Skip to content

Commit d1fea3e

Browse files
authored
Free yamls for those who want them, take 2 (ArchipelagoMW#10)
1 parent 1764195 commit d1fea3e

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

worlds/tracker/TrackerClient.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import logging
3+
import tempfile
34
import traceback
45
import typing
56
from collections.abc import Callable
@@ -481,9 +482,20 @@ def on_package(self, cmd: str, args: dict):
481482
logger.error(tb)
482483
return
483484
else:
484-
# TODO consider allowing worlds that self-attest to not need an options file for UT
485-
self.log_to_tab(f"Player's Yaml not in tracker's list. Known players: {list(self.launch_multiworld.world_name_lookup.keys())}", False)
486-
return
485+
if getattr(AutoWorld.AutoWorldRegister.world_types[self.game], "ut_can_gen_without_yaml", False):
486+
with tempfile.TemporaryDirectory() as tempdir:
487+
self.write_empty_yaml(self.game, slot_name, tempdir)
488+
self.run_generator(None, tempdir)
489+
self.player_id = 1
490+
if callable(getattr(self.multiworld.worlds[self.player_id], "interpret_slot_data", None)):
491+
temp = self.multiworld.worlds[self.player_id].interpret_slot_data(args["slot_data"])
492+
if temp:
493+
self.re_gen_passthrough = {self.game: temp}
494+
495+
self.run_generator(args["slot_data"], tempdir)
496+
else:
497+
self.log_to_tab(f"Player's Yaml not in tracker's list. Known players: {list(self.launch_multiworld.world_name_lookup.keys())}", False)
498+
return
487499

488500
if self.ui is not None and getattr(self.multiworld.worlds[self.player_id], "tracker_world", None):
489501
self.tracker_world = UTMapTabData(**self.multiworld.worlds[self.player_id].tracker_world)
@@ -499,6 +511,13 @@ def on_package(self, cmd: str, args: dict):
499511
elif cmd == 'RoomUpdate':
500512
updateTracker(self)
501513

514+
def write_empty_yaml(self, game, player_name, tempdir):
515+
path = os.path.join(tempdir, f'{game}_{player_name}.yaml')
516+
with open(path, 'w') as f:
517+
f.write('name: ' + player_name + '\n')
518+
f.write('game: ' + game + '\n')
519+
f.write(game + ': {}\n')
520+
502521
async def disconnect(self, allow_autoreconnect: bool = False):
503522
if "Tracker" in self.tags:
504523
self.game = ""
@@ -528,7 +547,7 @@ def _set_host_settings(self):
528547
return tracker_settings['player_files_path'], report_type, tracker_settings[
529548
'hide_excluded_locations']
530549

531-
def run_generator(self, slot_data: Optional[Dict] = None):
550+
def run_generator(self, slot_data: Optional[Dict] = None, override_yaml_path: Optional[str] = None):
532551
def move_slots(args: "Namespace", slot_name: str):
533552
"""
534553
helper function to copy all the proper option values into slot 1,
@@ -547,7 +566,9 @@ def move_slots(args: "Namespace", slot_name: str):
547566
# strip command line args, they won't be useful from the client anyway
548567
sys.argv = sys.argv[:1]
549568
args = mystery_argparse()
550-
if yaml_path:
569+
if override_yaml_path:
570+
args.player_files_path = override_yaml_path
571+
elif yaml_path:
551572
args.player_files_path = yaml_path
552573
args.skip_output = True
553574

0 commit comments

Comments
 (0)