Skip to content

Commit

Permalink
add BMSBK support
Browse files Browse the repository at this point in the history
  • Loading branch information
duncathan committed Sep 22, 2023
1 parent 17c4bd3 commit 722d394
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mercury_engine_data_structures/formats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from mercury_engine_data_structures.formats.bmmdef import Bmmdef
from mercury_engine_data_structures.formats.bmsad import Bmsad
from mercury_engine_data_structures.formats.bmsas import Bmsas
from mercury_engine_data_structures.formats.bmsbk import Bmsbk
from mercury_engine_data_structures.formats.bmscc import Bmscc
from mercury_engine_data_structures.formats.bmscu import Bmscu
from mercury_engine_data_structures.formats.bmsld import Bmsld
Expand Down Expand Up @@ -36,6 +37,7 @@
"BMBLS": Bmbls,
"BMMAP": Bmmap,
"BMMDEF": Bmmdef,
"BMSBK": Bmsbk,
"BMSCP": Bmscp,
"BMSSD": Bmssd,
"BMSSK": Bmssk,
Expand Down
59 changes: 59 additions & 0 deletions src/mercury_engine_data_structures/formats/bmsbk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import functools

from construct import (
Array,
Const,
Construct,
Container,
Flag,
Float32l,
Hex,
Int32ul,
Rebuild,
Struct,
)

from mercury_engine_data_structures.common_types import CVector3D, StrId, make_vector
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

Block = Struct(
"pos" / CVector3D,
"unk2" / Int32ul,
"unk3" / Int32ul,
"unk4" / Float32l,
"name1" / StrId,
"name2" / StrId,
)

def _rebuild_blocks(ctx: Container) -> int:
return sum(len(group.blocks) for group in ctx.types)

def _rebuild_types(ctx: Container) -> int:
return len(ctx.types)

BlockGroup = Struct(
"_num_blocks" / Rebuild(Int32ul, _rebuild_blocks),
"_num_types" / Rebuild(Int32ul, _rebuild_types),
"unk_bool" / Flag, # always true?
"types" / Array(lambda this: this._num_types, Struct(
"block_type" / StrId,
"blocks" / make_vector(Block),
)),
)

BMSBK = Struct(
"magic" / Const(b"MSBK"),
"version" / Hex(Int32ul),
"block_groups" / make_vector(BlockGroup),
"collision_cameras" / make_vector(Struct(
"name" / StrId,
"entries" / make_vector(Int32ul),
)),
)

class Bmsbk(BaseResource):
@classmethod
@functools.lru_cache
def construct_class(cls, target_game: Game) -> Construct:
return BMSBK
13 changes: 13 additions & 0 deletions tests/formats/test_bmsbk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest
from tests.test_lib import parse_build_compare_editor

from mercury_engine_data_structures import samus_returns_data
from mercury_engine_data_structures.formats.bmsbk import Bmsbk

all_sr_bmsbk = [name for name in samus_returns_data.all_name_to_asset_id().keys()
if name.endswith(".bmsbk")]


@pytest.mark.parametrize("bmsbk_path", all_sr_bmsbk)
def test_bmsbk(samus_returns_tree, bmsbk_path):
parse_build_compare_editor(Bmsbk, samus_returns_tree, bmsbk_path)

0 comments on commit 722d394

Please sign in to comment.