diff --git a/CommonClient.py b/CommonClient.py index 0415df1ac371..1d13a3926179 100644 --- a/CommonClient.py +++ b/CommonClient.py @@ -17,7 +17,8 @@ logger = logging.getLogger("Client") -gui_enabled = Utils.is_frozen() or "--nogui" not in sys.argv +# without terminal we have to use gui mode +gui_enabled = not sys.stdout or "--nogui" not in sys.argv log_folder = Utils.local_path("logs") os.makedirs(log_folder, exist_ok=True) @@ -57,7 +58,7 @@ def _cmd_missing(self) -> bool: """List all missing location checks, from your local game state""" if not self.ctx.game: self.output("No game set, cannot determine missing checks.") - return + return False count = 0 checked_count = 0 for location, location_id in AutoWorldRegister.world_types[self.ctx.game].location_name_to_id.items(): @@ -531,11 +532,20 @@ def init_logging(name: str): ) +def get_base_parser(description=None): + import argparse + parser = argparse.ArgumentParser(description=description) + parser.add_argument('--connect', default=None, help='Address of the multiworld host.') + parser.add_argument('--password', default=None, help='Password of the multiworld host.') + if sys.stdout: # If terminal output exists, offer gui-less mode + parser.add_argument('--nogui', default=False, action='store_true', help="Turns off Client GUI.") + return parser + + if __name__ == '__main__': # Text Mode to use !hint and such with games that have no text entry init_logging("TextClient") - class TextContext(CommonContext): tags = {"AP", "IgnoreGame"} @@ -586,15 +596,9 @@ async def main(args): if input_task: input_task.cancel() - - import argparse import colorama - parser = argparse.ArgumentParser(description="Gameless Archipelago Client, for text interfaction.") - parser.add_argument('--connect', default=None, help='Address of the multiworld host.') - parser.add_argument('--password', default=None, help='Password of the multiworld host.') - if not Utils.is_frozen(): # Frozen state has no cmd window in the first place - parser.add_argument('--nogui', default=False, action='store_true', help="Turns off Client GUI.") + parser = get_base_parser(description="Gameless Archipelago Client, for text interfaction.") args, rest = parser.parse_known_args() colorama.init() diff --git a/FactorioClient.py b/FactorioClient.py index fefb4cb2457c..f1a1f47dbaf8 100644 --- a/FactorioClient.py +++ b/FactorioClient.py @@ -13,7 +13,7 @@ import asyncio from queue import Queue from CommonClient import CommonContext, server_loop, console_loop, ClientCommandProcessor, logger, gui_enabled, \ - init_logging + init_logging, get_base_parser from MultiServer import mark_raw import Utils @@ -353,17 +353,11 @@ def _handle_color(self, node: JSONMessagePart): if __name__ == '__main__': - import argparse - - parser = argparse.ArgumentParser(description="Optional arguments to FactorioClient follow. " - "Remaining arguments get passed into bound Factorio instance." - "Refer to Factorio --help for those.") + parser = get_base_parser(description="Optional arguments to FactorioClient follow. " + "Remaining arguments get passed into bound Factorio instance." + "Refer to Factorio --help for those.") parser.add_argument('--rcon-port', default='24242', type=int, help='Port to use to communicate with Factorio') parser.add_argument('--rcon-password', help='Password to authenticate with RCON.') - parser.add_argument('--connect', default=None, help='Address of the multiworld host.') - parser.add_argument('--password', default=None, help='Password of the multiworld host.') - if not Utils.is_frozen(): # Frozen state has no cmd window in the first place - parser.add_argument('--nogui', default=False, action='store_true', help="Turns off Client GUI.") args, rest = parser.parse_known_args() colorama.init() diff --git a/LttPClient.py b/LttPClient.py index a0ba1d9d5e2d..276f3cb28668 100644 --- a/LttPClient.py +++ b/LttPClient.py @@ -1,5 +1,4 @@ from __future__ import annotations -import argparse import atexit exit_func = atexit.register(input, "Press enter to close.") @@ -27,7 +26,8 @@ from worlds.alttp import Items from worlds.alttp.Rom import ROM_PLAYER_LIMIT import Utils -from CommonClient import CommonContext, server_loop, console_loop, ClientCommandProcessor, gui_enabled, init_logging +from CommonClient import CommonContext, server_loop, console_loop, ClientCommandProcessor, gui_enabled, init_logging, \ + get_base_parser init_logging("LttPClient") @@ -473,8 +473,8 @@ def launch_sni(ctx: Context): if os.path.isfile(sni_path): snes_logger.info(f"Attempting to start {sni_path}") - import subprocess - if Utils.is_frozen(): # if it spawns a visible console, may as well populate it + import sys + if not sys.stdout: # if it spawns a visible console, may as well populate it subprocess.Popen(sni_path, cwd=os.path.dirname(sni_path)) else: subprocess.Popen(sni_path, cwd=os.path.dirname(sni_path), stdout=subprocess.DEVNULL, @@ -951,17 +951,13 @@ async def run_game(romfile): async def main(): multiprocessing.freeze_support() - parser = argparse.ArgumentParser() + parser = get_base_parser() parser.add_argument('diff_file', default="", type=str, nargs="?", help='Path to a Archipelago Binary Patch file') parser.add_argument('--snes', default='localhost:8080', help='Address of the SNI server.') - parser.add_argument('--connect', default=None, help='Address of the multiworld host.') - parser.add_argument('--password', default=None, help='Password of the multiworld host.') parser.add_argument('--loglevel', default='info', choices=['debug', 'info', 'warning', 'error', 'critical']) - if not Utils.is_frozen(): # Frozen state has no cmd window in the first place - parser.add_argument('--nogui', default=False, action='store_true', help="Turns off Client GUI.") args = parser.parse_args() - logging.basicConfig(format='%(message)s', level=getattr(logging, args.loglevel.upper(), logging.INFO)) + if args.diff_file: import Patch logging.info("Patch file was supplied. Creating sfc rom..")