-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/github_actions/codecov/codecov-ac…
…tion-4
- Loading branch information
Showing
7 changed files
with
155 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import functools | ||
|
||
from construct import ( | ||
Array, | ||
Const, | ||
Construct, | ||
Container, | ||
Flag, | ||
Float32l, | ||
Hex, | ||
Int32ul, | ||
Rebuild, | ||
Struct, | ||
Terminated, | ||
) | ||
|
||
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), | ||
)), | ||
Terminated, | ||
) | ||
|
||
class Bmsbk(BaseResource): | ||
@classmethod | ||
@functools.lru_cache | ||
def construct_class(cls, target_game: Game) -> Construct: | ||
return BMSBK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import functools | ||
|
||
import construct | ||
from construct.core import ( | ||
Array, | ||
Const, | ||
Construct, | ||
Flag, | ||
Float32l, | ||
Hex, | ||
Int32sl, | ||
Int32ul, | ||
Struct, | ||
Switch, | ||
) | ||
|
||
from mercury_engine_data_structures.common_types import Char, Float, StrId, make_dict | ||
from mercury_engine_data_structures.construct_extensions.misc import ErrorWithMessage | ||
from mercury_engine_data_structures.formats import BaseResource | ||
from mercury_engine_data_structures.game_check import Game | ||
|
||
# Functions | ||
TunableParam = Struct( | ||
type=Char, | ||
value=Switch( | ||
construct.this.type, | ||
{ | ||
's': StrId, | ||
'f': Float, | ||
'b': Flag, | ||
'i': Int32sl, | ||
'v': Array(3, Float32l) | ||
}, | ||
ErrorWithMessage(lambda ctx: f"Unknown argument type: {ctx.type}", construct.SwitchError) | ||
) | ||
) | ||
|
||
TunableClass = Struct( | ||
"tunables" / make_dict(TunableParam), | ||
) | ||
|
||
# BMTUN | ||
BMTUN = Struct( | ||
"_magic" / Const(b"MTUN"), | ||
"version" / Const(0x00050001, Hex(Int32ul)), | ||
"classes" / make_dict(TunableClass), | ||
construct.Terminated, | ||
) | ||
|
||
|
||
class Bmtun(BaseResource): | ||
@classmethod | ||
@functools.lru_cache | ||
def construct_class(cls, target_game: Game) -> Construct: | ||
return BMTUN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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): | ||
try: | ||
parse_build_compare_editor(Bmsbk, samus_returns_tree, bmsbk_path) | ||
except FileNotFoundError: | ||
pytest.skip(f"{bmsbk_path} does not exist") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.bmtun import Bmtun | ||
|
||
all_sr_bmtun = [name for name in samus_returns_data.all_name_to_asset_id().keys() | ||
if name.endswith(".bmtun")] | ||
|
||
|
||
@pytest.mark.parametrize("bmtun_path", all_sr_bmtun) | ||
def test_bmtun(samus_returns_tree, bmtun_path): | ||
parse_build_compare_editor(Bmtun, samus_returns_tree, bmtun_path) |