reorder match blocks by alphabetical

This commit is contained in:
xeals 2023-04-04 22:32:47 +10:00
parent 37a2df3039
commit e8149e7c3b
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C

91
main.py
View File

@ -209,13 +209,27 @@ class LogParser:
LOG.trace(line) # type: ignore LOG.trace(line) # type: ignore
match chunks: match chunks:
# t.Literal, PlayerTag, Player
case ["player", id, username, *rest]:
self.players[PlayerTag(id)] = Player(username)
# t.Literal, str # t.Literal, TaggedPokemon, str, str
case ["turn", turn]: case ["drag", name_, specie, status, *rest]:
self.turn = int(turn) 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 # t.Literal, TaggedPokemon, str, TaggedPokemon
case ["move", user_, move, target_]: case ["move", user_, move, target_]:
@ -240,12 +254,9 @@ class LogParser:
), ),
) )
# t.Literal, TaggedPokemon, str, str # t.Literal, PlayerTag, Player
case ["drag", name_, specie, status, *rest]: case ["player", id, username, *rest]:
name = TaggedPokemon(name_) self.players[PlayerTag(id)] = Player(username)
self.hp[name] = int(status.split("/")[0])
self._log_appearance(name, specie)
# t.Literal, TaggedPokemon, str # t.Literal, TaggedPokemon, str
case ["replace", name, specie]: case ["replace", name, specie]:
@ -269,17 +280,9 @@ class LogParser:
(self.game, self.turn, team(player), trimmed_specie), (self.game, self.turn, team(player), trimmed_specie),
) )
# t.Literal, TaggedPokemon # t.Literal, str
case ["faint", pokemon_]: case ["turn", turn]:
pokemon = TaggedPokemon(pokemon_) self.turn = int(turn)
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, Player # t.Literal, Player
case ["win", player]: case ["win", player]:
@ -292,25 +295,8 @@ class LogParser:
(team(player), self.game), (team(player), self.game),
) )
# t.Literal, TaggedPlayer, str case ["-heal", pokemon, status, *rest]:
case ["-sidestart", side, env]: self.hp[pokemon] = int(status.split("/")[0])
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]
# t.Literal, TaggedPokemon, str # t.Literal, TaggedPokemon, str
case ["-damage", pokemon, status]: case ["-damage", pokemon, status]:
@ -425,8 +411,25 @@ class LogParser:
), ),
) )
case ["-heal", pokemon, status, *rest]: # t.Literal, TaggedPlayer, str
self.hp[pokemon] = int(status.split("/")[0]) 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 _: case _:
# LOG.debug(f"unhandled message {chunks[0]}") # LOG.debug(f"unhandled message {chunks[0]}")