Skip to content

Commit

Permalink
Merge pull request #196 from steven11sjf/bnvib
Browse files Browse the repository at this point in the history
Added bnvib
  • Loading branch information
Miepee authored Jul 27, 2024
2 parents ad546f7 + 3ea6bf3 commit d41dbd1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
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

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

BNVIB = Struct(
"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)
)

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)

0 comments on commit d41dbd1

Please sign in to comment.