From e3c185e05823e30eccd7728ceda2ee57cc66fd4d Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 11 Dec 2024 12:55:08 +0100 Subject: next commit --- extractor/action_format.gd | 305 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 extractor/action_format.gd (limited to 'extractor/action_format.gd') diff --git a/extractor/action_format.gd b/extractor/action_format.gd new file mode 100644 index 0000000..ff2ba64 --- /dev/null +++ b/extractor/action_format.gd @@ -0,0 +1,305 @@ +class_name ActionFormat + + +## Byte Length: 2 [br] +## AC +var signature: String = "AC" + +## Byte Type: u8 [br] +## Byte Length: 2 +var version: Version + +## Byte Type: u16 [br] +## Byte Length: 2 +var action_count: int + +## Byte Type: u8 [br] +## Byte Length: 10 +var reserved: PackedByteArray + +## Length: [member action_count] +var actions: Array[ActionData] + +## Byte Type: u32 [br] +## Byte Length: 4 +var event_count: int + +## Length: [member event_count] +var events: Array[Event] + +## Byte Type: f32 [br] +## Byte Length: [member action_count] [br] +## The times are given in the unit of "ticks per displayed frame". [br] +## Multiply by 24 to get the time in milliseconds. +var frame_times: Array[float] + + +func get_byte_length() -> int: + var length := 20 + + for action in actions: + length += action.get_byte_length() + + length += Event.BYTE_LENGTH * event_count + length += 4 * action_count + + return length + + +static func from_bytes(bytes: ByteStream) -> ActionFormat: + var action_format = ActionFormat.new() + + bytes.seek(2) + + @warning_ignore("shadowed_variable") + var version = Version.new() + version.minor = bytes.decode_u8() + version.major = bytes.decode_u8() + action_format.version = version + + action_format.action_count = bytes.decode_u16() + action_format.reserved = bytes.get_buffer(10).bytes + + action_format.actions = [] as Array[ActionData] + for idx in action_format.action_count: + var action = ActionData.from_bytes(bytes) + action_format.actions.append(action) + + action_format.event_count = bytes.decode_u32() + action_format.events = [] as Array[Event] + for idx in action_format.event_count: + var event = Event.from_bytes(bytes) + action_format.events.append(event) + + action_format.frame_times = [] as Array[float] + for idx in action_format.action_count: + action_format.frame_times.append(bytes.decode_float()) + + return action_format + + +class ActionData: + ## Byte Type: u32 [br] + ## Byte Length: 4 + var motion_count: int + + ## Length: [member motion_count] + var motions: Array[Motion] + + + func get_byte_length() -> int: + var length := 4 + for motion in motions: + length += motion.get_byte_length() + + return length + + + static func from_bytes(bytes: ByteStream) -> ActionData: + var action = ActionData.new() + + action.motion_count = bytes.decode_u32() + action.motions = [] as Array[Motion] + for idx in action.motion_count: + var motion = Motion.from_bytes(bytes) + action.motions.append(motion) + + return action + + +class Motion: + ## Byte Type: u8 [br] + ## Byte Length: 32 + var unused: PackedByteArray + + ## Byte Type: u32 [br] + ## Byte Length: 4 + var sprite_layer_count: int + + ## Length: [member sprite_layer_count] + var sprite_layers: Array[SpriteLayer] + + ## Byte Type: i32 [br] + ## Byte Length: 4 + var event_id: int + + ## Byte Type: u32 [br] + ## Byte Length: 4 + var sprite_anchor_count: int + + ## Length: [member sprite_anchor_count] + var sprite_anchors: Array[SpriteAnchor] + + + func get_byte_length() -> int: + return 44 + SpriteLayer.BYTE_LENGTH * sprite_layer_count + SpriteAnchor.BYTE_LENGTH * sprite_anchor_count + + + static func from_bytes(bytes: ByteStream): + var motion = Motion.new() + + motion.unused = bytes.get_buffer(32).bytes + + motion.sprite_layer_count = bytes.decode_u32() + motion.sprite_layers = [] as Array[SpriteLayer] + for idx in motion.sprite_layer_count: + var sprite_layer = SpriteLayer.from_bytes(bytes) + motion.sprite_layers.append(sprite_layer) + + motion.event_id = bytes.decode_s32() + + motion.sprite_anchor_count = bytes.decode_u32() + motion.sprite_anchors = [] as Array[SpriteAnchor] + for idx in motion.sprite_anchor_count: + var sprite_anchor = SpriteAnchor.from_bytes(bytes) + motion.sprite_anchor_count.append(sprite_anchor) + + return motion + + +class SpriteLayer: + const BYTE_LENGTH := 44 + + ## Byte Type: i32 [br] + ## Byte Length: 4 + var position_u: int + + ## Byte Type: i32 [br] + ## Byte Length: 4 + var position_v: int + + ## Byte Type: i32 [br] + ## Byte Length: 4 + var sprite_index: int + + ## Byte Type: u32 [br] + ## Byte Length: 4 + var flip_h: int + + ## Byte Type: u8 [br] + ## Byte Length: 1 + var color_r: int + + ## Byte Type: u8 [br] + ## Byte Length: 1 + var color_g: int + + ## Byte Type: u8 [br] + ## Byte Length: 1 + var color_b: int + + ## Byte Type: u8 [br] + ## Byte Length: 1 + var color_a: int + + ## Byte Type: f32 [br] + ## Byte Length: 4 + var scale_u: float + + ## Byte Type: f32 [br] + ## Byte Length: 4 + var scale_v: float + + ## Byte Type: i32 [br] + ## Byte Length: 4 + var rotation_degrees: int + + ## Byte Type: u32 [br] + ## Byte Length: 4 + var type: int + + ## Byte Type: u32 [br] + ## Byte Length: 4 + var width: int + + ## Byte Type: u32 [br] + ## Byte Length: 4 + var height: int + + + func get_position() -> Vector2: + return Vector2(position_u, position_v) + + + func get_color() -> Color: + return Color8(color_r, color_g, color_b, color_a) + + + func get_scale() -> Vector2: + return Vector2(scale_u, scale_v) + + + func get_size() -> Vector2: + return Vector2(width, height) + + + static func from_bytes(bytes: ByteStream): + var sprite_layer = SpriteLayer.new() + + sprite_layer.position_u = bytes.decode_s32() + sprite_layer.position_v = bytes.decode_s32() + sprite_layer.sprite_index = bytes.decode_s32() + sprite_layer.flip_h = bytes.decode_u32() + sprite_layer.color_r = bytes.decode_u8() + sprite_layer.color_g = bytes.decode_u8() + sprite_layer.color_b = bytes.decode_u8() + sprite_layer.color_a = bytes.decode_u8() + sprite_layer.scale_u = bytes.decode_float() + sprite_layer.scale_v = bytes.decode_float() + sprite_layer.rotation_degrees = bytes.decode_s32() + sprite_layer.type = bytes.decode_u32() + sprite_layer.width = bytes.decode_u32() + sprite_layer.height = bytes.decode_u32() + + return sprite_layer + + +class SpriteAnchor: + const BYTE_LENGTH := 16 + + ## Byte Type: u8 [br] + ## Byte Length: 4 + var unused: PackedByteArray + + ## Byte Type: i32 [br] + ## Byte Length: 4 + var position_u: int + + ## Byte Type: i32 [br] + ## Byte Length: 4 + var position_v: int + + ## Byte Type: u32 [br] + ## Byte Length: 4 + var flag: int + + + func get_position() -> Vector2: + return Vector2(position_u, position_v) + + + static func from_bytes(bytes: ByteStream): + var sprite_anchor = SpriteAnchor.new() + + sprite_anchor.unused = bytes.get_buffer(4).bytes + sprite_anchor.position_u = bytes.decode_s32() + sprite_anchor.position_v = bytes.decode_s32() + sprite_anchor.flag = bytes.decode_u32() + + return sprite_anchor + + +class Event: + const BYTE_LENGTH := 40 + + ## Byte Type: u8 [br] + ## Byte Length: 40 + var name: String + + + static func from_bytes(bytes: ByteStream): + var event = Event.new() + + event.name = bytes.get_string_from_utf8(BYTE_LENGTH) + + return event -- cgit v1.2.3