diff --git a/pokete_classes/multiplayer/communication.py b/pokete_classes/multiplayer/communication.py index ac70de27..c324ae3c 100644 --- a/pokete_classes/multiplayer/communication.py +++ b/pokete_classes/multiplayer/communication.py @@ -2,6 +2,7 @@ import socket import bs_rpc +from pokete_classes.context import Context from pokete_classes.generate import gen_maps, gen_obs from pokete_classes.multiplayer import msg from pokete_classes.multiplayer.exceptions import ConnectionException, \ @@ -15,6 +16,7 @@ class CommunicationService: def __init__(self): self.client: bs_rpc.Client | None = None + self.saved_pos = () def __subscribe_position_updates(self): gen = self.client.call_for_responses( @@ -60,13 +62,16 @@ def listener(): daemon=True ).start() - def handshake(self, context, user_name, version): + def handshake( + self, ctx: Context, user_name, + version + ): # Here COmntext usage outside of the UI context """Sends and handles the handshake with the server""" resp = self.client.call_for_response( msg.Handshake({ "user_name": user_name, "version": version, - "pokes": [p.dict() for p in context.figure.pokes] + "pokes": [p.dict() for p in ctx.figure.pokes] })) match resp.get_type(): case error.VERSION_MISMATCH_TYPE: @@ -83,22 +88,22 @@ def handshake(self, context, user_name, version): data["obmaps"], data["npcs"], data["trainers"], - context.figure, + ctx.figure, ) roadmap.roadmap = roadmap.RoadMap( data["map_stations"], data["map_decorations"] ) pos = data["position"] - context.saved_pos = ( - context.figure.map.name, - context.figure.oldmap.name, - context.figure.last_center_map.name, - context.figure.x, - context.figure.y, + self.saved_pos = ( + ctx.figure.map.name, + ctx.figure.oldmap.name, + ctx.figure.last_center_map.name, + ctx.figure.x, + ctx.figure.y, ) - context.figure.remove() - context.figure.add(obmp.ob_maps[pos["map"]], pos["x"], pos["y"]) + ctx.figure.remove() + ctx.figure.add(obmp.ob_maps[pos["map"]], pos["x"], pos["y"]) for user in data["users"]: pc_manager.set( user["name"], diff --git a/pokete_classes/multiplayer/connector.py b/pokete_classes/multiplayer/connector.py index 2d6d975e..78ee7819 100644 --- a/pokete_classes/multiplayer/connector.py +++ b/pokete_classes/multiplayer/connector.py @@ -30,7 +30,7 @@ def __call__(self, ctx: Context): def handshake(self, ctx: Context): try: - greeting_text = com_service.handshake(self, self.user_name, + greeting_text = com_service.handshake(ctx, self.user_name, release.VERSION) ask_ok(ctx, liner(greeting_text, ctx.map.width - 4)) except UserPresentException: @@ -65,12 +65,13 @@ def ask_user_name(self, ctx: Context, reask=False): """Asks the user for username ARGS: reask: Boolean whether or not this is asked again""" + self.user_name = ctx.figure.name self.user_name = ask_text( ctx, ("That username isn't awailable right now\n" if reask else "") + "Please enter the username you want to use on the server", "Username:", - self.user_name if self.user_name else "lxgr", + self.user_name, "Username", 20, ) diff --git a/pokete_classes/save.py b/pokete_classes/save.py index 54b75027..9eebe266 100644 --- a/pokete_classes/save.py +++ b/pokete_classes/save.py @@ -7,7 +7,7 @@ from . import timer from .achievements import achievements from .input import hotkeys_save -from .multiplayer.connector import connector +from .multiplayer.connector import com_service from .multiplayer.modeprovider import modeProvider, Mode from .pokete_care import pokete_care from .settings import settings @@ -22,7 +22,7 @@ def save(figure): y = figure.y last_center_map = figure.last_center_map.name if modeProvider.mode == Mode.MULTI: - _map, old_map, last_center_map, x, y = connector.saved_pos + _map, old_map, last_center_map, x, y = com_service.saved_pos """Saves all relevant data to savefile""" _si = {