Skip to content

Commit

Permalink
Improve CommonClient commands
Browse files Browse the repository at this point in the history
'/missing' now properly can take multi-word filter text, and is case-insensitive.
'/missing' now only shows missing locations, not checked locations.
New command '/checked' shows checked locations, opposite to '/missing'
'/received', '/items', and '/locations' now also take optional filter text.
  • Loading branch information
EmilyV99 committed Feb 21, 2024
1 parent ffdcb91 commit b207af8
Showing 1 changed file with 74 additions and 21 deletions.
95 changes: 74 additions & 21 deletions CommonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
if __name__ == "__main__":
Utils.init_logging("TextClient", exception_logger="Client")

from MultiServer import CommandProcessor
from MultiServer import CommandProcessor, mark_raw
from NetUtils import Endpoint, decode, NetworkItem, encode, JSONtoTextParser, \
ClientStatus, Permission, NetworkSlot, RawJSONtoTextParser
from Utils import Version, stream_input, async_start
Expand Down Expand Up @@ -70,59 +70,112 @@ def _cmd_disconnect(self) -> bool:
async_start(self.ctx.disconnect(), name="disconnecting")
return True

def _cmd_received(self) -> bool:
"""List all received items"""
self.output(f'{len(self.ctx.items_received)} received items:')
for index, item in enumerate(self.ctx.items_received, 1):
self.output(f"{self.ctx.item_names[item.item]} from {self.ctx.player_names[item.player]}")
@mark_raw
def _cmd_received(self, filter_text = "") -> bool:
"""List all received items
Can be given text, which will be used as filter."""
count = 0
if filter_text:
self.output(f"Received items matching '{filter_text}':")
else:
self.output("Received items:")
for item in self.ctx.items_received:
item_name = self.ctx.item_names[item.item]
if not filter_text or filter_text.lower() in item_name.lower():
count += 1
self.output(f"{item_name} from {self.ctx.player_names[item.player]}")
if count == 0:
self.output("No received items found")
else:
self.output(f"Found {count} {'matching ' if filter_text else ''}received items")
return True


@mark_raw
def _cmd_missing(self, filter_text = "") -> bool:
"""List all missing location checks, from your local game state.
"""List all missing location checks from your local game state.
Can be given text, which will be used as filter."""
if not self.ctx.game:
self.output("No game set, cannot determine missing checks.")
return False
if filter_text:
self.output(f"Missing checks matching '{filter_text}':")
else:
self.output("Missing checks:")
count = 0
checked_count = 0
total_count = 0
for location, location_id in AutoWorldRegister.world_types[self.ctx.game].location_name_to_id.items():
if filter_text and filter_text not in location:
if filter_text and filter_text.lower() not in location.lower():
continue
if location_id < 0:
continue
if location_id not in self.ctx.locations_checked:
if location_id in self.ctx.missing_locations:
self.output('Missing: ' + location)
count += 1
total_count += 1
elif location_id in self.ctx.checked_locations:
total_count += 1

if count:
self.output(f"Found {count}/{total_count} {'matching ' if filter_text else ''}missing checks")
else:
self.output("No missing checks found.")
return True
@mark_raw
def _cmd_checked(self, filter_text = "") -> bool:
"""List all checked location checks from your local game state.
Can be given text, which will be used as filter."""
if not self.ctx.game:
self.output("No game set, cannot determine checked checks.")
return False
if filter_text:
self.output(f"Checked locations matching '{filter_text}':")
else:
self.output("Checked locations:")
count = 0
total_count = 0
for location, location_id in AutoWorldRegister.world_types[self.ctx.game].location_name_to_id.items():
if filter_text and filter_text.lower() not in location.lower():
continue
if location_id < 0:
continue
if location_id not in self.ctx.locations_checked:
if location_id in self.ctx.missing_locations:
total_count += 1
elif location_id in self.ctx.checked_locations:
self.output('Checked: ' + location)
count += 1
checked_count += 1

total_count += 1
if count:
self.output(
f"Found {count} missing location checks{f'. {checked_count} location checks previously visited.' if checked_count else ''}")
self.output(f"Found {count}/{total_count} {'matching ' if filter_text else ''}checked locations")
else:
self.output("No missing location checks found.")
self.output("No checked locations found.")
return True

def _cmd_items(self):
"""List all item names for the currently running game."""
@mark_raw
def _cmd_items(self, filter_text = ""):
"""List all item names for the currently running game.
Can be given text, which will be used as filter."""
if not self.ctx.game:
self.output("No game set, cannot determine existing items.")
return False
self.output(f"Item Names for {self.ctx.game}")
for item_name in AutoWorldRegister.world_types[self.ctx.game].item_name_to_id:
self.output(item_name)
if not filter_text or filter_text.lower() in item_name.lower():
self.output(item_name)

def _cmd_locations(self):
"""List all location names for the currently running game."""
@mark_raw
def _cmd_locations(self, filter_text = ""):
"""List all location names for the currently running game.
Can be given text, which will be used as filter."""
if not self.ctx.game:
self.output("No game set, cannot determine existing locations.")
return False
self.output(f"Location Names for {self.ctx.game}")
for location_name in AutoWorldRegister.world_types[self.ctx.game].location_name_to_id:
self.output(location_name)
if not filter_text or filter_text.lower() in location_name.lower():
self.output(location_name)

def _cmd_ready(self):
"""Send ready status to server."""
Expand Down

0 comments on commit b207af8

Please sign in to comment.