Skip to content

Commit

Permalink
Prevent duplicates in mod definitions (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsznsk authored Nov 22, 2023
1 parent 002e6be commit 5293b29
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def bool_str(text):
config["game"]["gameProperties"]["networkViewDistance"] = int(
os.environ["GAME_PROPS_NETWORK_VIEW_DISTANCE"]
)

if env_defined("GAME_MODS_IDS_LIST") or env_defined("GAME_MODS_JSON_FILE_PATH"):
# Since we want to keep ENVs as a single source of truth
# we will regenerate the mod list in case any manual changes were made
config["game"]["mods"] = []
config_mod_ids = []
if env_defined("GAME_MODS_IDS_LIST"):
reg = re.compile(r"^[A-Z\d,=.]+$")
assert reg.match(
Expand All @@ -124,12 +130,16 @@ def bool_str(text):
for mod in mods:
mod_details = mod.split("=")
assert 0 < len(mod_details) < 3, f"{mod} mod not defined properly"
mod_config = {"modId": mod_details[0]}
mod_id = mod_details[0]
if mod_id in config_mod_ids:
continue # modId already defined in config, skipping to avoid duplicates
mod_config = {"modId": mod_id}
if len(mod_details) == 2:
assert reg.match(
mod_details[1]
), f"{mod} mod version does not match the pattern"
mod_config["version"] = mod_details[1]
config_mod_ids.append(mod_id)
config["game"]["mods"].append(mod_config)
if env_defined("GAME_MODS_JSON_FILE_PATH"):
with open(os.environ["GAME_MODS_JSON_FILE_PATH"]) as f:
Expand All @@ -139,11 +149,14 @@ def bool_str(text):
assert (
"modId" in provided_mod
), f"Entry in GAME_MODS_JSON_FILE_PATH file does not contain modId: {provided_mod}"
if provided_mod["modId"] in config_mod_ids:
continue # modId already defined in config, skipping to avoid duplicates
valid_mod = {
key: provided_mod[key]
for key in allowed_keys
if key in provided_mod
} # Extract only valid config keys
config_mod_ids.append(provided_mod["modId"])
config["game"]["mods"].append(valid_mod)

f = open(CONFIG_GENERATED, "w")
Expand Down

0 comments on commit 5293b29

Please sign in to comment.