Client UI: allow auto filling !getitem
This commit is contained in:
parent
f478b65815
commit
c46abd7e65
|
@ -102,7 +102,9 @@ class ClientCommandProcessor(CommandProcessor):
|
||||||
asyncio.create_task(self.ctx.send_msgs([{"cmd": "StatusUpdate", "status": state}]), name="send StatusUpdate")
|
asyncio.create_task(self.ctx.send_msgs([{"cmd": "StatusUpdate", "status": state}]), name="send StatusUpdate")
|
||||||
|
|
||||||
def default(self, raw: str):
|
def default(self, raw: str):
|
||||||
asyncio.create_task(self.ctx.send_msgs([{"cmd": "Say", "text": raw}]), name="send Say")
|
raw = self.ctx.on_user_say(raw)
|
||||||
|
if raw:
|
||||||
|
asyncio.create_task(self.ctx.send_msgs([{"cmd": "Say", "text": raw}]), name="send Say")
|
||||||
|
|
||||||
|
|
||||||
class CommonContext():
|
class CommonContext():
|
||||||
|
@ -273,6 +275,11 @@ class CommonContext():
|
||||||
"""For custom package handling in subclasses."""
|
"""For custom package handling in subclasses."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def on_user_say(self, text: str) -> typing.Optional[str]:
|
||||||
|
"""Gets called before sending a Say to the server from the user.
|
||||||
|
Returned text is sent, or sending is aborted if None is returned."""
|
||||||
|
return text
|
||||||
|
|
||||||
def update_permissions(self, permissions: typing.Dict[str, int]):
|
def update_permissions(self, permissions: typing.Dict[str, int]):
|
||||||
for permission_name, permission_flag in permissions.items():
|
for permission_name, permission_flag in permissions.items():
|
||||||
try:
|
try:
|
||||||
|
@ -282,6 +289,20 @@ class CommonContext():
|
||||||
except Exception as e: # safeguard against permissions that may be implemented in the future
|
except Exception as e: # safeguard against permissions that may be implemented in the future
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
|
||||||
|
async def shutdown(self):
|
||||||
|
self.server_address = None
|
||||||
|
if self.server and not self.server.socket.closed:
|
||||||
|
await self.server.socket.close()
|
||||||
|
if self.server_task:
|
||||||
|
await self.server_task
|
||||||
|
|
||||||
|
while self.input_requests > 0:
|
||||||
|
self.input_queue.put_nowait(None)
|
||||||
|
self.input_requests -= 1
|
||||||
|
self.keep_alive_task.cancel()
|
||||||
|
|
||||||
|
# DeathLink hooks
|
||||||
|
|
||||||
def on_deathlink(self, data: dict):
|
def on_deathlink(self, data: dict):
|
||||||
"""Gets dispatched when a new DeathLink is triggered by another linked player."""
|
"""Gets dispatched when a new DeathLink is triggered by another linked player."""
|
||||||
self.last_death_link = max(data["time"], self.last_death_link)
|
self.last_death_link = max(data["time"], self.last_death_link)
|
||||||
|
@ -303,18 +324,6 @@ class CommonContext():
|
||||||
}
|
}
|
||||||
}])
|
}])
|
||||||
|
|
||||||
async def shutdown(self):
|
|
||||||
self.server_address = None
|
|
||||||
if self.server and not self.server.socket.closed:
|
|
||||||
await self.server.socket.close()
|
|
||||||
if self.server_task:
|
|
||||||
await self.server_task
|
|
||||||
|
|
||||||
while self.input_requests > 0:
|
|
||||||
self.input_queue.put_nowait(None)
|
|
||||||
self.input_requests -= 1
|
|
||||||
self.keep_alive_task.cancel()
|
|
||||||
|
|
||||||
async def update_death_link(self, death_link):
|
async def update_death_link(self, death_link):
|
||||||
old_tags = self.tags.copy()
|
old_tags = self.tags.copy()
|
||||||
if death_link:
|
if death_link:
|
||||||
|
|
|
@ -134,7 +134,7 @@ async def game_watcher(ctx: FactorioContext):
|
||||||
ctx.finished_game = True
|
ctx.finished_game = True
|
||||||
|
|
||||||
if ctx.locations_checked != research_data:
|
if ctx.locations_checked != research_data:
|
||||||
bridge_logger.info(
|
bridge_logger.debug(
|
||||||
f"New researches done: "
|
f"New researches done: "
|
||||||
f"{[lookup_id_to_name[rid] for rid in research_data - ctx.locations_checked]}")
|
f"{[lookup_id_to_name[rid] for rid in research_data - ctx.locations_checked]}")
|
||||||
ctx.locations_checked = research_data
|
ctx.locations_checked = research_data
|
||||||
|
@ -192,7 +192,7 @@ async def factorio_server_watcher(ctx: FactorioContext):
|
||||||
while not factorio_queue.empty():
|
while not factorio_queue.empty():
|
||||||
msg = factorio_queue.get()
|
msg = factorio_queue.get()
|
||||||
factorio_queue.task_done()
|
factorio_queue.task_done()
|
||||||
factorio_server_logger.info(msg)
|
|
||||||
if not ctx.rcon_client and "Starting RCON interface at IP ADDR:" in msg:
|
if not ctx.rcon_client and "Starting RCON interface at IP ADDR:" in msg:
|
||||||
ctx.rcon_client = factorio_rcon.RCONClient("localhost", rcon_port, rcon_password)
|
ctx.rcon_client = factorio_rcon.RCONClient("localhost", rcon_port, rcon_password)
|
||||||
if not ctx.server:
|
if not ctx.server:
|
||||||
|
@ -201,7 +201,9 @@ async def factorio_server_watcher(ctx: FactorioContext):
|
||||||
|
|
||||||
if not ctx.awaiting_bridge and "Archipelago Bridge Data available for game tick " in msg:
|
if not ctx.awaiting_bridge and "Archipelago Bridge Data available for game tick " in msg:
|
||||||
ctx.awaiting_bridge = True
|
ctx.awaiting_bridge = True
|
||||||
|
factorio_server_logger.debug(msg)
|
||||||
|
else:
|
||||||
|
factorio_server_logger.info(msg)
|
||||||
if ctx.rcon_client:
|
if ctx.rcon_client:
|
||||||
commands = {}
|
commands = {}
|
||||||
while ctx.send_index < len(ctx.items_received):
|
while ctx.send_index < len(ctx.items_received):
|
||||||
|
|
21
kvui.py
21
kvui.py
|
@ -179,7 +179,7 @@ class SelectableLabel(RecycleDataViewBehavior, Label):
|
||||||
if text.startswith(question):
|
if text.startswith(question):
|
||||||
name = Utils.get_text_between(text, question,
|
name = Utils.get_text_between(text, question,
|
||||||
"? (")
|
"? (")
|
||||||
cmdinput.text = f"!hint {name}"
|
cmdinput.text = f"!{App.get_running_app().last_autofillable_command} {name}"
|
||||||
break
|
break
|
||||||
|
|
||||||
Clipboard.copy(text)
|
Clipboard.copy(text)
|
||||||
|
@ -194,7 +194,8 @@ class GameManager(App):
|
||||||
logging_pairs = [
|
logging_pairs = [
|
||||||
("Client", "Archipelago"),
|
("Client", "Archipelago"),
|
||||||
]
|
]
|
||||||
base_title = "Archipelago Client"
|
base_title: str = "Archipelago Client"
|
||||||
|
last_autofillable_command: str
|
||||||
|
|
||||||
def __init__(self, ctx: context_type):
|
def __init__(self, ctx: context_type):
|
||||||
self.title = self.base_title
|
self.title = self.base_title
|
||||||
|
@ -203,6 +204,22 @@ class GameManager(App):
|
||||||
self.icon = r"data/icon.png"
|
self.icon = r"data/icon.png"
|
||||||
self.json_to_kivy_parser = KivyJSONtoTextParser(ctx)
|
self.json_to_kivy_parser = KivyJSONtoTextParser(ctx)
|
||||||
self.log_panels = {}
|
self.log_panels = {}
|
||||||
|
|
||||||
|
# keep track of last used command to autofill on click
|
||||||
|
self.last_autofillable_command = "hint"
|
||||||
|
autofillable_commands = ("hint", "getitem")
|
||||||
|
original_say = ctx.on_user_say
|
||||||
|
|
||||||
|
def intercept_say(text):
|
||||||
|
text = original_say(text)
|
||||||
|
if text:
|
||||||
|
for command in autofillable_commands:
|
||||||
|
if text.startswith("!"+command):
|
||||||
|
self.last_autofillable_command = command
|
||||||
|
break
|
||||||
|
return text
|
||||||
|
ctx.on_user_say = intercept_say
|
||||||
|
|
||||||
super(GameManager, self).__init__()
|
super(GameManager, self).__init__()
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
|
|
Loading…
Reference in New Issue