Skip to content

Commit

Permalink
Merge pull request #62 from randovania/feature/bmsad
Browse files Browse the repository at this point in the history
update bmsad
  • Loading branch information
henriquegemignani authored Aug 23, 2023
2 parents edd33d0 + b91126b commit 916942e
Show file tree
Hide file tree
Showing 9 changed files with 891 additions and 197 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Construct type definitions for Mercury Engine
| Format | Samus Returns (Read) | Samus Returns (Write) | Dread (Read) | Dread (Write) |
| -------- |----------------------| --------------------- | ------------ | ------------- |
| PKG | ✓ | ✓ | ✓ | ✓ |
| BMSAD | ✗ | ✗ | ✓ | ✓ |
| BMSAD | ✓ | ✓ | ✓ | ✓ |
| BMSSD | ✓ | ✓ | ✓ | ✓ |
| BRFLD | Missing | Missing | ✓ | ✓ |
| BMSLD | ✓ | ✓ | Missing | Missing |
Expand All @@ -22,13 +22,13 @@ Construct type definitions for Mercury Engine

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

| Code | Color | |
| Code | Color | |
|------|-------------|--------------|
| {c0} | White | (Default) |
| {c1} | Yellow | |
| {c2} | Red | |
| {c3} | Pink | |
| {c4} | Green | |
| {c5} | Blue | |
| {c6} | UI Active | (Light blue) |
| {c1} | Yellow | |
| {c2} | Red | |
| {c3} | Pink | |
| {c4} | Green | |
| {c5} | Blue | |
| {c6} | UI Active | (Light blue) |
| {c7} | UI Inactive | (Dim blue) |
8 changes: 7 additions & 1 deletion src/mercury_engine_data_structures/file_tree_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,13 @@ def get_parsed_asset(self, name: str, *, in_pkg: Optional[str] = None,
elif type_hint != type_from_name:
raise ValueError(f"type_hint was {type_hint}, expected {type_from_name} from name")

return format_class.parse(data, target_game=self.target_game)
return format_class.parse(data, target_game=self.target_game, editor=self)

def get_file(self, path: str, type_hint: type[_T] = BaseResource) -> _T:
"""
Wrapper for `get_parsed_asset`. Override in children for additional functionality.
"""
return self.get_parsed_asset(path, type_hint=type_hint)

def add_new_asset(self, name: str, new_data: typing.Union[bytes, BaseResource],
in_pkgs: typing.Iterable[str]):
Expand Down
13 changes: 10 additions & 3 deletions src/mercury_engine_data_structures/formats/base_resource.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
from __future__ import annotations

import typing

from construct import Construct, Container

from mercury_engine_data_structures.game_check import Game

if typing.TYPE_CHECKING:
from mercury_engine_data_structures.file_tree_editor import FileTreeEditor


class BaseResource:
_raw: Container
target_game: Game
editor: FileTreeEditor | None

def __init__(self, raw: Container, target_game: Game):
def __init__(self, raw: Container, target_game: Game, editor: FileTreeEditor | None = None):
self._raw = raw
self.target_game = target_game
self.editor = editor

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

@classmethod
def parse(cls, data: bytes, target_game: Game) -> "BaseResource":
def parse(cls, data: bytes, target_game: Game, editor: FileTreeEditor | None = None) -> BaseResource:
return cls(cls.construct_class(target_game).parse(data, target_game=target_game),
target_game)
target_game, editor)

def build(self) -> bytes:
return self.construct_class(self.target_game).build(self._raw, target_game=self.target_game)
Expand Down
Loading

0 comments on commit 916942e

Please sign in to comment.