Skip to content

Commit

Permalink
Clients: allow use of console input if stdin is available.
Browse files Browse the repository at this point in the history
Such as unfrozen + gui
  • Loading branch information
Berserker66 committed Nov 26, 2021
1 parent b0bf66b commit 82de3c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 4 additions & 3 deletions CommonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,15 @@ def on_package(self, cmd: str, args: dict):
async def main(args):
ctx = TextContext(args.connect, args.password)
ctx.server_task = asyncio.create_task(server_loop(ctx), name="server loop")
input_task = None
if gui_enabled:
input_task = None
from kvui import TextManager
ctx.ui = TextManager(ctx)
ui_task = asyncio.create_task(ctx.ui.async_run(), name="UI")
else:
input_task = asyncio.create_task(console_loop(ctx), name="Input")
ui_task = None
if sys.stdin:
input_task = asyncio.create_task(console_loop(ctx), name="Input")
await ctx.exit_event.wait()

await ctx.shutdown()
Expand All @@ -614,7 +615,7 @@ async def main(args):

import colorama

parser = get_base_parser(description="Gameless Archipelago Client, for text interfaction.")
parser = get_base_parser(description="Gameless Archipelago Client, for text interfacing.")

args, rest = parser.parse_known_args()
colorama.init()
Expand Down
6 changes: 4 additions & 2 deletions FactorioClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import string
import copy
import subprocess
import sys
import time
import random

Expand Down Expand Up @@ -294,14 +295,15 @@ async def factorio_spinup_server(ctx: FactorioContext) -> bool:
async def main(args):
ctx = FactorioContext(args.connect, args.password)
ctx.server_task = asyncio.create_task(server_loop(ctx), name="ServerLoop")
input_task = None
if gui_enabled:
input_task = None
from kvui import FactorioManager
ctx.ui = FactorioManager(ctx)
ui_task = asyncio.create_task(ctx.ui.async_run(), name="UI")
else:
input_task = asyncio.create_task(console_loop(ctx), name="Input")
ui_task = None
if sys.stdin:
input_task = asyncio.create_task(console_loop(ctx), name="Input")
factorio_server_task = asyncio.create_task(factorio_spinup_server(ctx), name="FactorioSpinupServer")
succesful_launch = await factorio_server_task
if succesful_launch:
Expand Down
6 changes: 3 additions & 3 deletions SNIClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,15 +1091,15 @@ async def main():
ctx = Context(args.snes, args.connect, args.password)
if ctx.server_task is None:
ctx.server_task = asyncio.create_task(server_loop(ctx), name="ServerLoop")

input_task = None
if gui_enabled:
input_task = None
from kvui import SNIManager
ctx.ui = SNIManager(ctx)
ui_task = asyncio.create_task(ctx.ui.async_run(), name="UI")
else:
input_task = asyncio.create_task(console_loop(ctx), name="Input")
ui_task = None
if sys.stdin:
input_task = asyncio.create_task(console_loop(ctx), name="Input")

snes_connect_task = asyncio.create_task(snes_connect(ctx, ctx.snes_address), name="SNES Connect")
watcher_task = asyncio.create_task(game_watcher(ctx), name="GameWatcher")
Expand Down

0 comments on commit 82de3c9

Please sign in to comment.