From 432ae5865ddace2b7df7dd61b5e81fb3c59720ed Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Wed, 14 Apr 2021 17:51:11 +0200 Subject: [PATCH] Factorio: Filter bridged technologies correctly Turns out, lua does not use regex, nor simple string matching, but its own invention. --- FactorioClient.py | 3 ++- Options.py | 4 ++-- data/factorio/mod_template/control.lua | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/FactorioClient.py b/FactorioClient.py index 118aaf5f..a0eb3621 100644 --- a/FactorioClient.py +++ b/FactorioClient.py @@ -108,7 +108,8 @@ async def game_watcher(ctx: FactorioContext): with open(bridge_file) as f: data = json.load(f) research_data = data["research_done"] - research_data = {int(tech_name.split("-")[1]) for tech_name in research_data if tech_name.startswith("ap-")} + + research_data = {int(tech_name.split("-")[1]) for tech_name in research_data} if ctx.locations_checked != research_data: bridge_logger.info(f"New researches done: " f"{[lookup_id_to_name[rid] for rid in research_data - ctx.locations_checked]}") diff --git a/Options.py b/Options.py index d3eacc0e..70a438d7 100644 --- a/Options.py +++ b/Options.py @@ -3,7 +3,7 @@ import typing class AssembleOptions(type): - def __new__(cls, name, bases, attrs): + def __new__(mcs, name, bases, attrs): options = attrs["options"] = {} name_lookup = attrs["name_lookup"] = {} for base in bases: @@ -17,7 +17,7 @@ class AssembleOptions(type): # apply aliases, without name_lookup options.update({name[6:].lower(): option_id for name, option_id in attrs.items() if name.startswith("alias_")}) - return super(AssembleOptions, cls).__new__(cls, name, bases, attrs) + return super(AssembleOptions, mcs).__new__(mcs, name, bases, attrs) class Option(metaclass=AssembleOptions): diff --git a/data/factorio/mod_template/control.lua b/data/factorio/mod_template/control.lua index 391a17fc..02f2502b 100644 --- a/data/factorio/mod_template/control.lua +++ b/data/factorio/mod_template/control.lua @@ -51,11 +51,11 @@ function dumpTech(force) local data_collection = {["research_done"] = research_done} for tech_name, tech in pairs(force.technologies) do - if tech.researched and string.find(tech_name, "ap-") == 1 then + if tech.researched and string.find(tech_name, "ap%-") == 1 then research_done[tech_name] = tech.researched end end - game.write_file("ap_bridge.json", game.table_to_json(data_collection), false) + game.write_file("ap_bridge.json", game.table_to_json(data_collection), false, 0) -- game.write_file("research_done.json", game.table_to_json(data_collection), false, 0) -- game.print("Sent progress to Archipelago.") end