From c14a1507951cf78ac82c92b39783425d0f2aa158 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sat, 3 Apr 2021 15:06:32 +0200 Subject: [PATCH] Output Factorio mod as zip --- Mystery.py | 2 ++ worlds/factorio/Mod.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Mystery.py b/Mystery.py index 534659d3..689d1904 100644 --- a/Mystery.py +++ b/Mystery.py @@ -343,6 +343,7 @@ legacy_boss_shuffle_options = { # legacy, will go away: 'simple': 'basic', 'random': 'full', + 'normal': 'full' } legacy_goals = { @@ -350,6 +351,7 @@ legacy_goals = { 'fast_ganon': 'crystals', } + def roll_percentage(percentage: typing.Union[int, float]) -> bool: """Roll a percentage chance. percentage is expected to be in range [0, 100]""" diff --git a/worlds/factorio/Mod.py b/worlds/factorio/Mod.py index f7afe219..ac396cdd 100644 --- a/worlds/factorio/Mod.py +++ b/worlds/factorio/Mod.py @@ -1,6 +1,7 @@ """Outputs a Factorio Mod to facilitate integration with Archipelago""" import os +import zipfile from typing import Optional import threading import json @@ -51,7 +52,7 @@ def generate_mod(world: MultiWorld, player: int): mod_code = template.render(**template_data) - mod_dir = Utils.output_path(mod_name) + mod_dir = Utils.output_path(mod_name)+"_"+Utils.__version__ en_locale_dir = os.path.join(mod_dir, "locale", "en") os.makedirs(en_locale_dir, exist_ok=True) shutil.copytree(Utils.local_path("data", "factorio", "mod"), mod_dir, dirs_exist_ok=True) @@ -64,3 +65,14 @@ def generate_mod(world: MultiWorld, player: int): info["name"] = mod_name with open(os.path.join(mod_dir, "info.json"), "wt") as f: json.dump(info, f, indent=4) + + # zip the result + zf_path = os.path.join(mod_dir+".zip") + with zipfile.ZipFile(zf_path, compression=zipfile.ZIP_DEFLATED, mode='w') as zf: + for root, dirs, files in os.walk(mod_dir): + for file in files: + zf.write(os.path.join(root, file), + os.path.relpath(os.path.join(root, file), + os.path.join(mod_dir, '..'))) + shutil.rmtree(mod_dir) +