Skip to content

Commit

Permalink
Get rid of the gimmicky fake spell card ID and add real fields instead.
Browse files Browse the repository at this point in the history
Not sure exactly what the right way to do this is, but this should be fine for now.
  • Loading branch information
n-rook committed Sep 10, 2024
1 parent 6e91174 commit 8c09218
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions project/thscoreboard/replays/replay_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ class ReplayInfo:
name: str
replay_type: int
route: Optional[str] = None

spell_card_id: Optional[int] = None
scene_game_level: Optional[int] = None
scene_game_scene: Optional[int] = None

stages: List[ReplayStage] = dataclasses.field(default_factory=list)
slowdown: Optional[float] = None

Expand Down Expand Up @@ -450,10 +454,8 @@ def _Parse09(rep_raw):
def _Parse095(rep_raw):
encrypted_replay = th095_encrypted.Th095Encrypted.from_bytes(rep_raw)

# This is goofy and probably not a good idea
spell_level = int(encrypted_replay.userdata.level.value)
spell_scene = int(encrypted_replay.userdata.scene.value)
spell_card_id = (spell_level << 8) + spell_scene

return ReplayInfo(
game=game_ids.GameIDs.TH095,
Expand All @@ -463,7 +465,8 @@ def _Parse095(rep_raw):
timestamp=time.strptime(encrypted_replay.userdata.date.value, "%y/%m/%d %H:%M"),
name=encrypted_replay.userdata.username.value,
replay_type=game_ids.ReplayTypes.SPELL_PRACTICE,
spell_card_id=spell_card_id,
scene_game_level=spell_level,
scene_game_scene=spell_scene,
slowdown=float(encrypted_replay.userdata.slowdown.value),
)

Expand Down
8 changes: 4 additions & 4 deletions project/thscoreboard/replays/test_replay_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ def testOne(self):
r.timestamp,
datetime.datetime(2024, 4, 27, 16, 42, tzinfo=datetime.timezone.utc),
)
self.assertEqual(r.spell_card_id >> 8, 3)
self.assertEqual(r.spell_card_id & 0xFF, 1)
self.assertEqual(r.scene_game_level, 3)
self.assertEqual(r.scene_game_scene, 1)
self.assertEqual(r.name, "nrook3.1")
self.assertEqual(r.slowdown, 0.00)

Expand All @@ -231,8 +231,8 @@ def testTwo(self):
r.timestamp,
datetime.datetime(2024, 4, 27, 19, 54, tzinfo=datetime.timezone.utc),
)
self.assertEqual(r.spell_card_id >> 8, 2)
self.assertEqual(r.spell_card_id & 0xFF, 5)
self.assertEqual(r.scene_game_level, 2)
self.assertEqual(r.scene_game_scene, 5)
self.assertEqual(r.name, "nrook ")
self.assertEqual(r.slowdown, 0.00)

Expand Down

0 comments on commit 8c09218

Please sign in to comment.