From 640c760ca07e130c88c2ed5693b1d6b93adb6063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Wed, 9 Feb 2022 11:48:56 +0100 Subject: [PATCH] feat(emulator): now using match structure, cleaner --- src/emulator.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/emulator.py b/src/emulator.py index 60a97fa..eb4ff21 100644 --- a/src/emulator.py +++ b/src/emulator.py @@ -106,15 +106,13 @@ def state_manager(loop: asyncio.AbstractEventLoop): while True: for message in ps.listen(): if message["type"] == "message": - data = message["data"].decode("utf-8") - - # TODO: voir si plus clean possible ? - # TODO: dev dans un docker ? - - if data == "save": - asyncio.ensure_future(utils.save(core), loop=loop) - elif data.startswith("load:"): - asyncio.ensure_future(utils.load(core, data.removeprefix("load:")), loop=loop) + match message["data"].decode("utf-8").split(":"): + case ["save"]: + asyncio.ensure_future(utils.save(core), loop=loop) + case ["load", filename]: + asyncio.ensure_future(utils.load(core, filename), loop=loop) + case _: + print(f"Command not understood: {message}") async def emulator():