Skip to content

Commit

Permalink
Merge pull request #7 from duncathan/fixes-for-patcher
Browse files Browse the repository at this point in the history
couple things for patcher needs
  • Loading branch information
duncathan authored Jan 28, 2022
2 parents 9a603b4 + 9345f09 commit af61eb0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
26 changes: 26 additions & 0 deletions mercury_engine_data_structures/formats/txt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from construct.core import Struct, Construct, Const

from mercury_engine_data_structures.common_types import make_dict
from mercury_engine_data_structures.construct_extensions.strings import CStringRobust
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.game_check import Game

TXT = Struct(
"magic" / Const(b'BTXT'),
"version" / Const(b'\x01\x00\x0a\x00'),
"strings" / make_dict(CStringRobust("utf16"))
)


class Txt(BaseResource):
@classmethod
def construct_class(cls, target_game: Game) -> Construct:
return TXT

@property
def strings(self) -> dict[str, str]:
return self._raw.strings

@strings.setter
def strings(self, value):
self._raw.strings = value
10 changes: 10 additions & 0 deletions test/formats/text_txt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest
from mercury_engine_data_structures.formats.txt import TXT
from mercury_engine_data_structures.game_check import Game
from test.test_lib import parse_and_build_compare

def test_compare_dread(dread_path):
file_path = dread_path.joinpath("system/localization/us_english.txt")
parse_and_build_compare(
TXT, Game.DREAD, file_path
)
3 changes: 2 additions & 1 deletion tools/create_class_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def _export_type(self, type_name: str):

elif isinstance(type_data, type_lib.FlagsetType):
reference = self.ensure_exported_type(type_data.enum)
self._type_definition_code += f'\n\n{type_variable} = {reference}'
flags = f'construct.FlagsEnum(construct.Int32ul, {reference}.enum_class)'
self._type_definition_code += f'\n\n{type_variable} = {flags}'

elif isinstance(type_data, type_lib.TypedefType):
reference = self.ensure_exported_type(type_data.alias)
Expand Down

0 comments on commit af61eb0

Please sign in to comment.