Output Factorio mod as zip

This commit is contained in:
Fabian Dill 2021-04-03 15:06:32 +02:00
parent 91bcd59940
commit c14a150795
2 changed files with 15 additions and 1 deletions

View File

@ -343,6 +343,7 @@ legacy_boss_shuffle_options = {
# legacy, will go away: # legacy, will go away:
'simple': 'basic', 'simple': 'basic',
'random': 'full', 'random': 'full',
'normal': 'full'
} }
legacy_goals = { legacy_goals = {
@ -350,6 +351,7 @@ legacy_goals = {
'fast_ganon': 'crystals', 'fast_ganon': 'crystals',
} }
def roll_percentage(percentage: typing.Union[int, float]) -> bool: def roll_percentage(percentage: typing.Union[int, float]) -> bool:
"""Roll a percentage chance. """Roll a percentage chance.
percentage is expected to be in range [0, 100]""" percentage is expected to be in range [0, 100]"""

View File

@ -1,6 +1,7 @@
"""Outputs a Factorio Mod to facilitate integration with Archipelago""" """Outputs a Factorio Mod to facilitate integration with Archipelago"""
import os import os
import zipfile
from typing import Optional from typing import Optional
import threading import threading
import json import json
@ -51,7 +52,7 @@ def generate_mod(world: MultiWorld, player: int):
mod_code = template.render(**template_data) 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") en_locale_dir = os.path.join(mod_dir, "locale", "en")
os.makedirs(en_locale_dir, exist_ok=True) os.makedirs(en_locale_dir, exist_ok=True)
shutil.copytree(Utils.local_path("data", "factorio", "mod"), mod_dir, dirs_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 info["name"] = mod_name
with open(os.path.join(mod_dir, "info.json"), "wt") as f: with open(os.path.join(mod_dir, "info.json"), "wt") as f:
json.dump(info, f, indent=4) 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)