LADX: Adding Slot Data For Magpie Tracker (#3582)
* wip: LADX slot_data * LADX: slot_data * Sending slot_data to magpie. * Moved sending slot_data from pushing to pull by Magpie request. * Adding EoF newline to tracker.py. * Update Tracker.py * Update __init__.py * Update LinksAwakeningClient.py --------- Co-authored-by: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									78c5489189
								
							
						
					
					
						commit
						dc218b7997
					
				| 
						 | 
					@ -467,6 +467,8 @@ class LinksAwakeningContext(CommonContext):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, server_address: typing.Optional[str], password: typing.Optional[str], magpie: typing.Optional[bool]) -> None:
 | 
					    def __init__(self, server_address: typing.Optional[str], password: typing.Optional[str], magpie: typing.Optional[bool]) -> None:
 | 
				
			||||||
        self.client = LinksAwakeningClient()
 | 
					        self.client = LinksAwakeningClient()
 | 
				
			||||||
 | 
					        self.slot_data = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if magpie:
 | 
					        if magpie:
 | 
				
			||||||
            self.magpie_enabled = True
 | 
					            self.magpie_enabled = True
 | 
				
			||||||
            self.magpie = MagpieBridge()
 | 
					            self.magpie = MagpieBridge()
 | 
				
			||||||
| 
						 | 
					@ -564,6 +566,8 @@ class LinksAwakeningContext(CommonContext):
 | 
				
			||||||
    def on_package(self, cmd: str, args: dict):
 | 
					    def on_package(self, cmd: str, args: dict):
 | 
				
			||||||
        if cmd == "Connected":
 | 
					        if cmd == "Connected":
 | 
				
			||||||
            self.game = self.slot_info[self.slot].game
 | 
					            self.game = self.slot_info[self.slot].game
 | 
				
			||||||
 | 
					            self.slot_data = args.get("slot_data", {})
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
        # TODO - use watcher_event
 | 
					        # TODO - use watcher_event
 | 
				
			||||||
        if cmd == "ReceivedItems":
 | 
					        if cmd == "ReceivedItems":
 | 
				
			||||||
            for index, item in enumerate(args["items"], start=args["index"]):
 | 
					            for index, item in enumerate(args["items"], start=args["index"]):
 | 
				
			||||||
| 
						 | 
					@ -628,6 +632,7 @@ class LinksAwakeningContext(CommonContext):
 | 
				
			||||||
                            self.magpie.set_checks(self.client.tracker.all_checks)
 | 
					                            self.magpie.set_checks(self.client.tracker.all_checks)
 | 
				
			||||||
                            await self.magpie.set_item_tracker(self.client.item_tracker)
 | 
					                            await self.magpie.set_item_tracker(self.client.item_tracker)
 | 
				
			||||||
                            await self.magpie.send_gps(self.client.gps_tracker)
 | 
					                            await self.magpie.send_gps(self.client.gps_tracker)
 | 
				
			||||||
 | 
					                            self.magpie.slot_data = self.slot_data
 | 
				
			||||||
                        except Exception:
 | 
					                        except Exception:
 | 
				
			||||||
                            # Don't let magpie errors take out the client
 | 
					                            # Don't let magpie errors take out the client
 | 
				
			||||||
                            pass
 | 
					                            pass
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -149,6 +149,8 @@ class MagpieBridge:
 | 
				
			||||||
    item_tracker = None
 | 
					    item_tracker = None
 | 
				
			||||||
    ws = None
 | 
					    ws = None
 | 
				
			||||||
    features = []
 | 
					    features = []
 | 
				
			||||||
 | 
					    slot_data = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def handler(self, websocket):
 | 
					    async def handler(self, websocket):
 | 
				
			||||||
        self.ws = websocket
 | 
					        self.ws = websocket
 | 
				
			||||||
        while True:
 | 
					        while True:
 | 
				
			||||||
| 
						 | 
					@ -163,6 +165,9 @@ class MagpieBridge:
 | 
				
			||||||
                    await self.send_all_inventory()
 | 
					                    await self.send_all_inventory()
 | 
				
			||||||
                if "checks" in self.features:
 | 
					                if "checks" in self.features:
 | 
				
			||||||
                    await self.send_all_checks()
 | 
					                    await self.send_all_checks()
 | 
				
			||||||
 | 
					                if "slot_data" in self.features:
 | 
				
			||||||
 | 
					                    await self.send_slot_data(self.slot_data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Translate renamed IDs back to LADXR IDs
 | 
					    # Translate renamed IDs back to LADXR IDs
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def fixup_id(the_id):
 | 
					    def fixup_id(the_id):
 | 
				
			||||||
| 
						 | 
					@ -222,6 +227,18 @@ class MagpieBridge:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
        await gps.send_location(self.ws)
 | 
					        await gps.send_location(self.ws)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async def send_slot_data(self, slot_data):
 | 
				
			||||||
 | 
					        if not self.ws:
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        logger.debug("Sending slot_data to magpie.")
 | 
				
			||||||
 | 
					        message = {
 | 
				
			||||||
 | 
					            "type": "slot_data",
 | 
				
			||||||
 | 
					            "slot_data": slot_data
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await self.ws.send(json.dumps(message))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def serve(self):
 | 
					    async def serve(self):
 | 
				
			||||||
        async with websockets.serve(lambda w: self.handler(w), "", 17026, logger=logger):
 | 
					        async with websockets.serve(lambda w: self.handler(w), "", 17026, logger=logger):
 | 
				
			||||||
            await asyncio.Future()  # run forever
 | 
					            await asyncio.Future()  # run forever
 | 
				
			||||||
| 
						 | 
					@ -237,4 +254,3 @@ class MagpieBridge:
 | 
				
			||||||
                await self.send_all_inventory()
 | 
					                await self.send_all_inventory()
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            await self.send_inventory_diffs()
 | 
					            await self.send_inventory_diffs()
 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -512,3 +512,31 @@ class LinksAwakeningWorld(World):
 | 
				
			||||||
        if change and item.name in self.rupees:
 | 
					        if change and item.name in self.rupees:
 | 
				
			||||||
            state.prog_items[self.player]["RUPEES"] -= self.rupees[item.name]
 | 
					            state.prog_items[self.player]["RUPEES"] -= self.rupees[item.name]
 | 
				
			||||||
        return change
 | 
					        return change
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def fill_slot_data(self):
 | 
				
			||||||
 | 
					        slot_data = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if not self.multiworld.is_race:
 | 
				
			||||||
 | 
					            # all of these option are NOT used by the LADX- or Text-Client.
 | 
				
			||||||
 | 
					            # they are used by Magpie tracker (https://github.com/kbranch/Magpie/wiki/Autotracker-API)
 | 
				
			||||||
 | 
					            # for convenient auto-tracking of the generated settings and adjusting the tracker accordingly
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            slot_options = ["instrument_count"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            slot_options_display_name = [
 | 
				
			||||||
 | 
					                "goal", "logic", "tradequest", "rooster",
 | 
				
			||||||
 | 
					                "experimental_dungeon_shuffle", "experimental_entrance_shuffle", "trendy_game", "gfxmod",
 | 
				
			||||||
 | 
					                "shuffle_nightmare_keys", "shuffle_small_keys", "shuffle_maps",
 | 
				
			||||||
 | 
					                "shuffle_compasses", "shuffle_stone_beaks", "shuffle_instruments", "nag_messages"
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # use the default behaviour to grab options
 | 
				
			||||||
 | 
					            slot_data = self.options.as_dict(*slot_options)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # for options which should not get the internal int value but the display name use the extra handling
 | 
				
			||||||
 | 
					            slot_data.update({
 | 
				
			||||||
 | 
					                option: value.current_key
 | 
				
			||||||
 | 
					                for option, value in dataclasses.asdict(self.options).items() if option in slot_options_display_name
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return slot_data
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue