Extract animations

This commit is contained in:
octorock
2021-10-24 11:41:27 +02:00
parent a19a870382
commit fdfd43d0d3
255 changed files with 18385 additions and 15589 deletions
+4
View File
@@ -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')
+28
View File
@@ -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)