From 4ea84d89774c44c24b782468443923422a294ae7 Mon Sep 17 00:00:00 2001 From: qwint Date: Wed, 7 Aug 2024 20:13:47 -0500 Subject: [PATCH] Make UT possible to call ad hoc without using CommonClient to establish a connection (#13) * removes dependencies on UI elements when running updateTracker * override to not call CommonContext init because then we cannot create TrackerContext in a non-async context --- worlds/tracker/TrackerClient.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/worlds/tracker/TrackerClient.py b/worlds/tracker/TrackerClient.py index 691e52923f1..c718b14e61c 100644 --- a/worlds/tracker/TrackerClient.py +++ b/worlds/tracker/TrackerClient.py @@ -87,8 +87,14 @@ class TrackerGameContext(CommonContext): tracker_failed = False re_gen_passthrough = None - def __init__(self, server_address, password): - super().__init__(server_address, password) + def __init__(self, server_address, password, no_connection: bool = False): + if no_connection: + from worlds import network_data_package + self.item_names = self.NameLookupDict(self, "item") + self.location_names = self.NameLookupDict(self, "location") + self.update_data_package(network_data_package) + else: + super().__init__(server_address, password) self.items_handling = ITEMS_HANDLING self.locations_checked = [] self.locations_available = [] @@ -489,9 +495,10 @@ def updateTracker(ctx: TrackerGameContext): pass events = [location.item.name for location in state.events if location.player == ctx.player_id] - ctx.tracker_page.refresh_from_data() + if ctx.tracker_page: + ctx.tracker_page.refresh_from_data() ctx.locations_available = locations - if f"_read_hints_{ctx.team}_{ctx.slot}" in ctx.stored_data: + if ctx.ui and f"_read_hints_{ctx.team}_{ctx.slot}" in ctx.stored_data: ctx.ui.update_hints() if ctx.update_callback is not None: ctx.update_callback(callback_list)