Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new function to BMSMSD to get a tile by index #249

Merged
merged 6 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/mercury_engine_data_structures/formats/bmsmsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@
from typing import TYPE_CHECKING

import construct
from construct.core import Const, Construct, Enum, FlagsEnum, Float32l, Int32sl, Int32ul, Struct
from construct.core import (
Const,
Construct,
Container,
Enum,
FlagsEnum,
Float32l,
Int32sl,
Int32ul,
Struct,
)

from mercury_engine_data_structures.base_resource import BaseResource
from mercury_engine_data_structures.common_types import CVector2D, CVector3D, StrId, VersionAdapter, make_vector
from mercury_engine_data_structures.common_types import (
CVector2D,
CVector3D,
StrId,
VersionAdapter,
make_vector,
)

if TYPE_CHECKING:
from mercury_engine_data_structures.game_check import Game
Expand Down Expand Up @@ -85,3 +101,6 @@ class Bmsmsd(BaseResource):
@functools.lru_cache
def construct_class(cls, target_game: Game) -> Construct:
return BMSMSD

def get_tile(self, tile_idx: int) -> Container:
return self.raw.tiles[tile_idx]
18 changes: 17 additions & 1 deletion tests/formats/test_bmsmsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@
from tests.test_lib import parse_build_compare_editor

from mercury_engine_data_structures import samus_returns_data
from mercury_engine_data_structures.formats.bmsmsd import Bmsmsd
from mercury_engine_data_structures.formats.bmsmsd import Bmsmsd, TileType


@pytest.mark.parametrize("bmsmsd_path", samus_returns_data.all_files_ending_with(".bmsmsd"))
def test_bmsmsd(samus_returns_tree, bmsmsd_path):
parse_build_compare_editor(Bmsmsd, samus_returns_tree, bmsmsd_path)


@pytest.fixture()
def surface_bmsmsd(samus_returns_tree) -> Bmsmsd:
return samus_returns_tree.get_parsed_asset("gui/minimaps/c10_samus/s000_surface.bmsmsd", type_hint=Bmsmsd)


def test_get_tile(surface_bmsmsd: Bmsmsd):
tile = surface_bmsmsd.get_tile(4)
assert tile.tile_coordinates == [48, 5]

tile = surface_bmsmsd.get_tile(12)
assert len(tile.icons) == 2

tile = surface_bmsmsd.get_tile(25)
assert tile.tile_type == TileType.NORMAL
Loading