Skip to content

Commit 916942e

Browse files
Merge pull request randovania#62 from randovania/feature/bmsad
update bmsad
2 parents edd33d0 + b91126b commit 916942e

File tree

9 files changed

+891
-197
lines changed

9 files changed

+891
-197
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Construct type definitions for Mercury Engine
44
| Format | Samus Returns (Read) | Samus Returns (Write) | Dread (Read) | Dread (Write) |
55
| -------- |----------------------| --------------------- | ------------ | ------------- |
66
| PKG | ✓ | ✓ | ✓ | ✓ |
7-
| BMSAD | ✗ | ✗ | ✓ | ✓ |
7+
| BMSAD | ✓ | ✓ | ✓ | ✓ |
88
| BMSSD | ✓ | ✓ | ✓ | ✓ |
99
| BRFLD | Missing | Missing | ✓ | ✓ |
1010
| BMSLD | ✓ | ✓ | Missing | Missing |
@@ -22,13 +22,13 @@ Construct type definitions for Mercury Engine
2222

2323
Metroid Dread uses the following annotations in text to change color:
2424

25-
| Code | Color | |
25+
| Code | Color | |
2626
|------|-------------|--------------|
2727
| {c0} | White | (Default) |
28-
| {c1} | Yellow | |
29-
| {c2} | Red | |
30-
| {c3} | Pink | |
31-
| {c4} | Green | |
32-
| {c5} | Blue | |
33-
| {c6} | UI Active | (Light blue) |
28+
| {c1} | Yellow | |
29+
| {c2} | Red | |
30+
| {c3} | Pink | |
31+
| {c4} | Green | |
32+
| {c5} | Blue | |
33+
| {c6} | UI Active | (Light blue) |
3434
| {c7} | UI Inactive | (Dim blue) |

src/mercury_engine_data_structures/file_tree_editor.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,13 @@ def get_parsed_asset(self, name: str, *, in_pkg: Optional[str] = None,
211211
elif type_hint != type_from_name:
212212
raise ValueError(f"type_hint was {type_hint}, expected {type_from_name} from name")
213213

214-
return format_class.parse(data, target_game=self.target_game)
214+
return format_class.parse(data, target_game=self.target_game, editor=self)
215+
216+
def get_file(self, path: str, type_hint: type[_T] = BaseResource) -> _T:
217+
"""
218+
Wrapper for `get_parsed_asset`. Override in children for additional functionality.
219+
"""
220+
return self.get_parsed_asset(path, type_hint=type_hint)
215221

216222
def add_new_asset(self, name: str, new_data: typing.Union[bytes, BaseResource],
217223
in_pkgs: typing.Iterable[str]):

src/mercury_engine_data_structures/formats/base_resource.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1+
from __future__ import annotations
2+
13
import typing
24

35
from construct import Construct, Container
46

57
from mercury_engine_data_structures.game_check import Game
68

9+
if typing.TYPE_CHECKING:
10+
from mercury_engine_data_structures.file_tree_editor import FileTreeEditor
11+
712

813
class BaseResource:
914
_raw: Container
1015
target_game: Game
16+
editor: FileTreeEditor | None
1117

12-
def __init__(self, raw: Container, target_game: Game):
18+
def __init__(self, raw: Container, target_game: Game, editor: FileTreeEditor | None = None):
1319
self._raw = raw
1420
self.target_game = target_game
21+
self.editor = editor
1522

1623
@classmethod
1724
def construct_class(cls, target_game: Game) -> Construct:
1825
raise NotImplementedError()
1926

2027
@classmethod
21-
def parse(cls, data: bytes, target_game: Game) -> "BaseResource":
28+
def parse(cls, data: bytes, target_game: Game, editor: FileTreeEditor | None = None) -> BaseResource:
2229
return cls(cls.construct_class(target_game).parse(data, target_game=target_game),
23-
target_game)
30+
target_game, editor)
2431

2532
def build(self) -> bytes:
2633
return self.construct_class(self.target_game).build(self._raw, target_game=self.target_game)

0 commit comments

Comments
 (0)