Skip to content

Commit

Permalink
Support for SR TXT files
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanatosGit committed Oct 1, 2023
1 parent e11f4e2 commit ad493e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/mercury_engine_data_structures/formats/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from typing import Dict

import construct
from construct import IfThenElse
from construct.core import Const, Construct, GreedyRange, Struct

from mercury_engine_data_structures import game_check
from mercury_engine_data_structures.common_types import DictAdapter, DictElement
from mercury_engine_data_structures.construct_extensions.strings import CStringRobust
from mercury_engine_data_structures.formats import BaseResource
Expand Down Expand Up @@ -38,7 +40,11 @@ def _parse_{n}(io, this):

TXT = Struct(
"magic" / Const(b'BTXT'),
"version" / Const(b'\x01\x00\x0a\x00'),
"version" / IfThenElse(
game_check.current_game_at_most(Game.SAMUS_RETURNS),
Const(b'\x01\x00\x08\x00'),
Const(b'\x01\x00\x0a\x00'),
),
"strings" / DictAdapter(_string_range),
"_end" / construct.Terminated,
)
Expand All @@ -48,7 +54,7 @@ class Txt(BaseResource):
@classmethod
@functools.lru_cache
def construct_class(cls, target_game: Game) -> Construct:
return TXT.compile()
return TXT

Check warning on line 57 in src/mercury_engine_data_structures/formats/txt.py

View check run for this annotation

Codecov / codecov/patch

src/mercury_engine_data_structures/formats/txt.py#L57

Added line #L57 was not covered by tests

@property
def strings(self) -> Dict[str, str]:
Expand Down
6 changes: 6 additions & 0 deletions tests/formats/test_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ def test_compare_dread(dread_path):
parse_and_build_compare(
TXT, Game.DREAD, file_path
)

def test_compare_sr(samus_returns_path):
file_path = samus_returns_path.joinpath("system/localization/us_english.txt")
parse_and_build_compare(
TXT, Game.SAMUS_RETURNS, file_path
)

0 comments on commit ad493e1

Please sign in to comment.