From 165a38dd583ddf588a8d377450aafe83122d5819 Mon Sep 17 00:00:00 2001 From: recklesscoder <57289227+recklesscoder@users.noreply.github.com> Date: Mon, 31 Oct 2022 03:55:18 +0100 Subject: [PATCH] Factorio: Added commands for checking energy link from CLI and in game. --- CommonClient.py | 2 +- FactorioClient.py | 18 +++++++++++++++++- worlds/factorio/data/mod_template/control.lua | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CommonClient.py b/CommonClient.py index e157b31c..c4934628 100644 --- a/CommonClient.py +++ b/CommonClient.py @@ -153,7 +153,7 @@ class CommonContext: disconnected_intentionally: bool = False server: typing.Optional[Endpoint] = None server_version: Version = Version(0, 0, 0) - current_energy_link_value: int = 0 # to display in UI, gets set by server + current_energy_link_value: typing.Optional[int] = None # to display in UI, gets set by server last_death_link: float = time.time() # last send/received death link on AP layer diff --git a/FactorioClient.py b/FactorioClient.py index 19150ca2..cd3ad1bb 100644 --- a/FactorioClient.py +++ b/FactorioClient.py @@ -33,6 +33,10 @@ from worlds.factorio import Factorio class FactorioCommandProcessor(ClientCommandProcessor): ctx: FactorioContext + def _cmd_energy_link(self): + """Print the status of the energy link.""" + self.output(f"Energy Link: {self.ctx.energy_link_status}") + @mark_raw def _cmd_factorio(self, text: str) -> bool: """Send the following command to the bound Factorio Server.""" @@ -113,6 +117,15 @@ class FactorioContext(CommonContext): self.rcon_client.send_command(f"/ap-print [font=default-large-bold]Archipelago:[/font] " f"{text}") + @property + def energy_link_status(self) -> str: + if not self.energy_link_increment: + return "Disabled" + elif self.current_energy_link_value is None: + return "Standby" + else: + return f"{Utils.format_SI_prefix(self.current_energy_link_value)}J" + def on_deathlink(self, data: dict): if self.rcon_client: self.rcon_client.send_command(f"/ap-deathlink {data['source']}") @@ -317,7 +330,10 @@ async def factorio_server_watcher(ctx: FactorioContext): if not ctx.awaiting_bridge and "Archipelago Bridge Data available for game tick " in msg: ctx.awaiting_bridge = True factorio_server_logger.debug(msg) - elif re.match(r"^[0-9.]+ Script @[^ ]+\.lua:\d+: Player command toggle-ap-send-filter", msg): + elif re.match(r"^[0-9.]+ Script @[^ ]+\.lua:\d+: Player command energy-link$", msg): + factorio_server_logger.debug(msg) + ctx.print_to_game(f"Energy Link: {ctx.energy_link_status}") + elif re.match(r"^[0-9.]+ Script @[^ ]+\.lua:\d+: Player command toggle-ap-send-filter$", msg): factorio_server_logger.debug(msg) ctx.toggle_filter_item_sends() elif re.match(r"^[0-9.]+ Script @[^ ]+\.lua:\d+: Player command toggle-ap-chat$", msg): diff --git a/worlds/factorio/data/mod_template/control.lua b/worlds/factorio/data/mod_template/control.lua index 98c9ca62..35425991 100644 --- a/worlds/factorio/data/mod_template/control.lua +++ b/worlds/factorio/data/mod_template/control.lua @@ -598,6 +598,10 @@ commands.add_command("ap-energylink", "Used by the Archipelago client to manage global.forcedata[force].energy = global.forcedata[force].energy + change end) +commands.add_command("energy-link", "Print the status of the Archipelago energy link.", function(call) + log("Player command energy-link") -- notifies client +end) + commands.add_command("toggle-ap-send-filter", "Toggle filtering of item sends that get displayed in-game to only those that involve you.", function(call) log("Player command toggle-ap-send-filter") -- notifies client end)