summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authoroctorock <79596758+octorock@users.noreply.github.com>2021-10-24 11:41:27 +0200
committeroctorock <79596758+octorock@users.noreply.github.com>2021-10-24 11:41:27 +0200
commitfdfd43d0d31feeda3082227bcfae7d32abc663f6 (patch)
tree0d853b60ad7a72d6076410f676b3aeb897ad4b06 /tools
parenta19a870382befa354caa24148733ea335fcc692c (diff)
Extract animations
Diffstat (limited to 'tools')
-rw-r--r--tools/asset_extractor/asset_extractor.py4
-rw-r--r--tools/asset_extractor/assets/animation.py28
2 files changed, 32 insertions, 0 deletions
diff --git a/tools/asset_extractor/asset_extractor.py b/tools/asset_extractor/asset_extractor.py
index a335d75e..35e4404a 100644
--- a/tools/asset_extractor/asset_extractor.py
+++ b/tools/asset_extractor/asset_extractor.py
@@ -10,6 +10,7 @@ from assets.gfx_group import GfxGroup
from assets.fixed_type_gfx import FixedTypeGfx
from assets.frame_obj_lists import FrameObjLists
from assets.extra_frame_offsets import ExtraFrameOffsets
+from assets.animation import Animation
verbose = False
@@ -126,6 +127,9 @@ def extract_assets(variant, assets_folder):
elif mode == 'extra_frame_offsets':
extra_frame_offsets = ExtraFrameOffsets(path, start, size, options)
extra_frame_offsets.extract_binary(baserom)
+ elif mode == 'animation':
+ animation = Animation(path, start, size, options)
+ animation.extract_binary(baserom)
elif mode != '':
print(f'Asset type {mode} not yet implemented')
diff --git a/tools/asset_extractor/assets/animation.py b/tools/asset_extractor/assets/animation.py
new file mode 100644
index 00000000..c5f19683
--- /dev/null
+++ b/tools/asset_extractor/assets/animation.py
@@ -0,0 +1,28 @@
+from assets.base import BaseAsset, Reader
+
+class Animation(BaseAsset):
+ def __init__(self, path: str, addr: int, size: int, options: any) -> None:
+ super().__init__(path, addr, size, options)
+
+ def extract_binary(self, rom: bytearray) -> None:
+ reader = Reader(rom[self.addr:self.addr+self.size])
+ lines = []
+ end_of_animation = False
+ while not end_of_animation and reader.cursor+3 < self.size:
+ frame_index = reader.read_u8()
+ keyframe_duration = reader.read_u8()
+ bitfield = reader.read_u8()
+ bitfield2 = reader.read_u8()
+
+ end_of_animation = bitfield2 & 0x80 != 0
+ lines.append(f'\t.byte {frame_index}, {keyframe_duration}, {hex(bitfield)}, {hex(bitfield2)}\n')
+ if not end_of_animation:
+ lines.append('@ TODO why no terminator?\n')
+ while reader.cursor < self.size:
+ keyframe_count = reader.read_u8()
+ lines.append(f'\t.byte {keyframe_count} @ keyframe count\n')
+
+ assert(self.path.endswith('.bin'))
+ path = self.path[0:-4] + '.s'
+ with open(path, 'w') as file:
+ file.writelines(lines) \ No newline at end of file