-
Notifications
You must be signed in to change notification settings - Fork 11
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 classes and functions to BMDEFS #266
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
from __future__ import annotations | ||
|
||
import construct | ||
from construct import ( | ||
from construct.core import ( | ||
Const, | ||
Construct, | ||
Container, | ||
Flag, | ||
Float32l, | ||
Int32ul, | ||
Struct, | ||
) | ||
|
||
from mercury_engine_data_structures.base_resource import BaseResource | ||
from mercury_engine_data_structures.common_types import StrId, VersionAdapter, make_vector | ||
from mercury_engine_data_structures.common_types import StrId, VersionAdapter, make_dict, make_vector | ||
from mercury_engine_data_structures.formats import standard_format | ||
from mercury_engine_data_structures.game_check import Game | ||
|
||
|
@@ -38,10 +39,7 @@ | |
"unk4" / Int32ul, | ||
"unk_bool" / Flag, | ||
"environment_sfx_volume" / Float32l, | ||
"inner_states" / make_vector(Struct( | ||
"type" / StrId, | ||
"unk1" / Float32l, | ||
)) | ||
"inner_states" / make_dict(Float32l) | ||
), | ||
'DEATH': Struct( | ||
"unk1" / Int32ul, | ||
|
@@ -55,10 +53,7 @@ | |
"unk4" / Int32ul, | ||
"unk_bool" / Flag, | ||
"environment_sfx_volume" / Float32l, | ||
"inner_states" / make_vector(Struct( | ||
"type" / StrId, | ||
"unk1" / Float32l, | ||
)) | ||
"inner_states" / make_dict(Float32l) | ||
), | ||
}, | ||
) | ||
|
@@ -68,10 +63,11 @@ | |
) # fmt: skip | ||
|
||
BMDEFS = Struct( | ||
_magic=Const(b"MDEF"), | ||
version=VersionAdapter("1.5.0"), | ||
unk1=Int32ul, | ||
sounds=make_vector( | ||
"_magic" / Const(b"MDEF"), | ||
"version" / VersionAdapter("1.5.0"), | ||
"number_of_sounds" / Int32ul, | ||
"sounds" | ||
/ make_vector( | ||
Struct( | ||
"sound_name" / StrId, | ||
"unk1" / Int32ul, | ||
|
@@ -87,16 +83,165 @@ | |
"environment_sfx_volume" / Float32l, | ||
) | ||
), # fmt: skip | ||
unk2=Int32ul, | ||
enemies_list=make_vector(EnemyStruct), | ||
rest=construct.GreedyBytes, | ||
"number_of_enemy_groups" / Int32ul, | ||
"enemies_list" / make_vector(EnemyStruct), | ||
construct.Terminated, | ||
) | ||
|
||
|
||
class EnemyStates: | ||
def __init__(self, raw: Container): | ||
self._raw = raw | ||
|
||
@property | ||
def state_type(self) -> str: | ||
return self._raw.type | ||
|
||
@state_type.setter | ||
def state_type(self, value: str) -> None: | ||
self._raw.type = value | ||
|
||
def get_sound_properties(self) -> Sounds: | ||
return Sounds(self._raw.properties) | ||
|
||
|
||
class EnemyLayers: | ||
def __init__(self, raw: Container): | ||
self._raw = raw | ||
|
||
@property | ||
def layer_name(self) -> str: | ||
return self._raw.layer_name | ||
|
||
@layer_name.setter | ||
def layer_name(self, value: str) -> None: | ||
self._raw.layer_name = value | ||
|
||
def get_state(self, state_idx: int) -> EnemyStates: | ||
return EnemyStates(self._raw.states[state_idx]) | ||
|
||
|
||
class Areas: | ||
def __init__(self, raw: Container): | ||
self._raw = raw | ||
|
||
@property | ||
def area_name(self) -> str: | ||
return self._raw.area_name | ||
|
||
@area_name.setter | ||
def area_name(self, value: str) -> None: | ||
self._raw.area_name = value | ||
|
||
def get_layer(self, layer_idx: int) -> EnemyLayers: | ||
return EnemyLayers(self._raw.layers[layer_idx]) | ||
|
||
|
||
class EnemiesList: | ||
def __init__(self, raw: Container): | ||
self._raw = raw | ||
|
||
@property | ||
def enemy_name(self) -> str: | ||
return self._raw.enemy_name | ||
|
||
@enemy_name.setter | ||
def enemy_name(self, value: str) -> None: | ||
self._raw.enemy_name = value | ||
|
||
def get_area(self, area_idx: int) -> Areas: | ||
return Areas(self._raw.areas[area_idx]) | ||
|
||
|
||
class Sounds: | ||
def __init__(self, raw: Container) -> None: | ||
self._raw = raw | ||
|
||
@property | ||
def sound_name(self) -> str: | ||
return self._raw.sound_name | ||
|
||
@sound_name.setter | ||
def sound_name(self, value: str) -> None: | ||
self._raw.sound_name = value | ||
|
||
@property | ||
def priority(self) -> int: | ||
return self._raw.priority | ||
|
||
@priority.setter | ||
def priority(self, value: str) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self._raw.priority = value | ||
|
||
@property | ||
def file_path(self) -> str: | ||
return self._raw.file_path | ||
|
||
@file_path.setter | ||
def file_path(self, value: str) -> None: | ||
self._raw.file_path = value | ||
|
||
@property | ||
def fade_in(self) -> float: | ||
return self._raw.fade_in | ||
|
||
@fade_in.setter | ||
def fade_in(self, value: float) -> None: | ||
self._raw.fade_in = value | ||
|
||
@property | ||
def fade_out(self) -> float: | ||
return self._raw.fade_out | ||
|
||
@fade_out.setter | ||
def fade_out(self, value: float) -> None: | ||
self._raw.fade_out = value | ||
|
||
@property | ||
def volume(self) -> float: | ||
return self._raw.volume | ||
|
||
@volume.setter | ||
def volume(self, value: float) -> None: | ||
self._raw.volume = value | ||
|
||
@property | ||
def environment_sfx_volume(self) -> float: | ||
return self._raw.environment_sfx_volume | ||
|
||
@environment_sfx_volume.setter | ||
def environment_sfx_volume(self, value: float) -> None: | ||
self._raw.environment_sfx_volume = value | ||
|
||
# inner_states and start_delay are only used for enemies | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then make a seperate child class (something something named like |
||
@property | ||
def start_delay(self) -> float: | ||
return self._raw.start_delay | ||
|
||
@start_delay.setter | ||
def start_delay(self, value: float) -> None: | ||
self._raw.start_delay = value | ||
|
||
@property | ||
def inner_states(self) -> dict[str, float]: | ||
return self._raw.inner_states | ||
|
||
@inner_states.setter | ||
def inner_states(self, value: dict[str, float]) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would just need to change the |
||
for name, value in value.items(): | ||
self._raw.inner_states[name] = value | ||
|
||
|
||
class Bmdefs(BaseResource): | ||
@classmethod | ||
def construct_class(cls, target_game: Game) -> Construct: | ||
if target_game == Game.SAMUS_RETURNS: | ||
return BMDEFS | ||
else: | ||
return standard_format.game_model("sound::CMusicManager", "4.0.2") | ||
|
||
def get_sound(self, sound_idx: int) -> Sounds: | ||
return Sounds(self.raw.sounds[sound_idx]) | ||
|
||
def get_enemy(self, enemy_idx: int) -> EnemiesList: | ||
return EnemiesList(self.raw.enemies_list[enemy_idx]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make the type an Enum instead of an arbitrary string, right? Because only
DEATH
orCOMBAT
should be accepted values.