From e8149e7c3b04778bd829468dde7abc9a8bc32076 Mon Sep 17 00:00:00 2001 From: xeals Date: Tue, 4 Apr 2023 22:32:47 +1000 Subject: [PATCH] reorder match blocks by alphabetical --- main.py | 91 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/main.py b/main.py index 437aea6..990d7d8 100755 --- a/main.py +++ b/main.py @@ -209,13 +209,27 @@ class LogParser: LOG.trace(line) # type: ignore match chunks: - # t.Literal, PlayerTag, Player - case ["player", id, username, *rest]: - self.players[PlayerTag(id)] = Player(username) - # t.Literal, str - case ["turn", turn]: - self.turn = int(turn) + # t.Literal, TaggedPokemon, str, str + case ["drag", name_, specie, status, *rest]: + name = TaggedPokemon(name_) + + self.hp[name] = int(status.split("/")[0]) + self._log_appearance(name, specie) + + # t.Literal, TaggedPokemon + case ["faint", pokemon_]: + pokemon = TaggedPokemon(pokemon_) + + player, _ = self.split_pokemon(pokemon) + self.conn.execute( + """ + INSERT INTO knockouts(game, turn, player, pokemon) + VALUES(?, ?, ?, ?) + ON CONFLICT DO NOTHING + """, + (self.game, self.turn, team(player), self.specie(pokemon)), + ) # t.Literal, TaggedPokemon, str, TaggedPokemon case ["move", user_, move, target_]: @@ -240,12 +254,9 @@ class LogParser: ), ) - # t.Literal, TaggedPokemon, str, str - case ["drag", name_, specie, status, *rest]: - name = TaggedPokemon(name_) - - self.hp[name] = int(status.split("/")[0]) - self._log_appearance(name, specie) + # t.Literal, PlayerTag, Player + case ["player", id, username, *rest]: + self.players[PlayerTag(id)] = Player(username) # t.Literal, TaggedPokemon, str case ["replace", name, specie]: @@ -269,17 +280,9 @@ class LogParser: (self.game, self.turn, team(player), trimmed_specie), ) - # t.Literal, TaggedPokemon - case ["faint", pokemon_]: - pokemon = TaggedPokemon(pokemon_) - self.conn.execute( - """ - INSERT INTO knockouts(game, turn, player, pokemon) - VALUES(?, ?, ?, ?) - ON CONFLICT DO NOTHING - """, - (self.game, self.turn, team(player), self.specie(pokemon)), - ) + # t.Literal, str + case ["turn", turn]: + self.turn = int(turn) # t.Literal, Player case ["win", player]: @@ -292,25 +295,8 @@ class LogParser: (team(player), self.game), ) - # t.Literal, TaggedPlayer, str - case ["-sidestart", side, env]: - if not last_move: - LOG.warning(f"missing previous move for {line}") - continue - - LOG.debug(f"{line} <- {last_move}") - self.last_env_set[ - (side[0:1], env.replace("move: ", "")) - ] = last_move[0] - - # t.Literal, TaggedPokemon, str - case ["-status", mon, cond]: - if not last_move or last_move[1] != mon: - LOG.warning(f"missing previous move for {line}") - continue - - LOG.debug(f"{line} <- {last_move}") - self.last_status_set[(mon, cond)] = last_move[0] + case ["-heal", pokemon, status, *rest]: + self.hp[pokemon] = int(status.split("/")[0]) # t.Literal, TaggedPokemon, str case ["-damage", pokemon, status]: @@ -425,8 +411,25 @@ class LogParser: ), ) - case ["-heal", pokemon, status, *rest]: - self.hp[pokemon] = int(status.split("/")[0]) + # t.Literal, TaggedPlayer, str + case ["-sidestart", side, env]: + if not last_move: + LOG.warning(f"missing previous move for {line}") + continue + + LOG.debug(f"{line} <- {last_move}") + self.last_env_set[ + (side[0:1], env.replace("move: ", "")) + ] = last_move[0] + + # t.Literal, TaggedPokemon, str + case ["-status", mon, cond]: + if not last_move or last_move[1] != mon: + LOG.warning(f"missing previous move for {line}") + continue + + LOG.debug(f"{line} <- {last_move}") + self.last_status_set[(mon, cond)] = last_move[0] case _: # LOG.debug(f"unhandled message {chunks[0]}")