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

Added bnvib #196

Merged
merged 3 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Construct type definitions for Mercury Engine
| BMSSTOC | Missing | Missing | ✗ | ✗ |
| BMTRE | ✗ | ✗ | ✓ | ✓ |
| BMTUN | ✓ | ✓ | Missing | Missing |
| BNVIB | Missing | Missing | ✗ | ✗ |
| BNVIB | Missing | Missing | ✓ | ✓ |
| BPSI | ✗ | ✗ | ✗ | ✗ |
| BPTDAT | Missing | Missing | ✗ | ✗ |
| BPTDEF | Missing | Missing | ✗ | ✗ |
Expand Down
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 @@ -30,6 +30,7 @@
from mercury_engine_data_structures.formats.bmssd import Bmssd
from mercury_engine_data_structures.formats.bmtre import Bmtre
from mercury_engine_data_structures.formats.bmtun import Bmtun
from mercury_engine_data_structures.formats.bnvib import Bnvib
from mercury_engine_data_structures.formats.brem import Brem
from mercury_engine_data_structures.formats.bres import Bres
from mercury_engine_data_structures.formats.brev import Brev
Expand Down Expand Up @@ -80,6 +81,7 @@
"BMSLINK": Bmslink,
"BMSMD": Bmsmd,
"BMTRE": Bmtre,
"BNVIB": Bnvib,
"BRSA": Brsa,
"BREM": Brem,
"BRES": Bres,
Expand Down
39 changes: 39 additions & 0 deletions src/mercury_engine_data_structures/formats/bnvib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from enum import Enum

import construct
from construct.core import (
Byte,
Const,
Construct,
If,
Int16ul,
Int32ul,
PrefixedArray,
Struct,
)

from mercury_engine_data_structures.adapters.enum_adapter import EnumAdapter
from mercury_engine_data_structures.formats.base_resource import BaseResource
from mercury_engine_data_structures.game_check import Game

# standard switch format. https://switchbrew.org/wiki/BNVIB#Normal_Vibration
Miepee marked this conversation as resolved.
Show resolved Hide resolved

class VibrationType(Enum):
NORMAL = 4
LOOP = 12
LOOPWAIT = 16

BNVIB = Struct(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to have a link to the switchbrew wiki page here.

"vibration_type" / EnumAdapter(VibrationType, Int32ul),
"_magic" / Const(3, Int16ul),
"sample_rate" / Int16ul,
"loop_start" / If(construct.this.vibration_type != VibrationType.NORMAL, Int32ul),
"loop_end" / If(construct.this.vibration_type != VibrationType.NORMAL, Int32ul),
"loop_wait" / If(construct.this.vibration_type == VibrationType.LOOPWAIT, Int32ul),
"data" / PrefixedArray(Int32ul, Byte)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefixed(Int32ul, GreedyBytes)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually looking at the documentation more closely: "The size of a sample is 4 bytes."
this should be Prefixed(Int32ul, GreedyRange(Int32ul))

)

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

from mercury_engine_data_structures import dread_data
from mercury_engine_data_structures.formats.bnvib import Bnvib


@pytest.mark.parametrize("bnvib_path", dread_data.all_files_ending_with(".bnvib"))
def test_bgsnds(dread_file_tree, bnvib_path):
parse_build_compare_editor(Bnvib, dread_file_tree, bnvib_path)