-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from steven11sjf/bnvib
Added bnvib
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
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,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 |
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,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) |