diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-12-04 14:23:42 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-12-04 14:23:42 +0100 |
commit | 688790b5dc0ea8f51a99e42a00c7510b9bd87aa6 (patch) | |
tree | 71c04c9f401c67caf5c1ea3f56c7360ac1d14b86 /extractor/action.gd | |
parent | 2bf6b303fc062a800afb784877d989686287a2a7 (diff) |
next commit
Diffstat (limited to 'extractor/action.gd')
-rw-r--r-- | extractor/action.gd | 222 |
1 files changed, 222 insertions, 0 deletions
diff --git a/extractor/action.gd b/extractor/action.gd new file mode 100644 index 0000000..1865786 --- /dev/null +++ b/extractor/action.gd @@ -0,0 +1,222 @@ +class_name ActionFormat + + +## Byte Length: 2 [br] +## SP +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[Action] + +## Byte Type: u16 [br] +## Byte Length: 2 +var event_count: int + +## Length: [member event_count] +var events: Array[Event] + +## Byte Type: f32 [br] +## Byte Length: 4 +var frame_times: float + + +func get_byte_length() -> int: + var length := 22 + + for action in actions: + length += action.get_byte_length() + + length += Event.BYTE_LENGTH * event_count + + return length + + +static func from_bytes(bytes: PackedByteArray): + var action = ActionFormat.new() + + @warning_ignore("shadowed_variable") + var version = Version.new() + version.minor = bytes.decode_u8(2) + version.major = bytes.decode_u8(3) + action.version = version + + print(version) + + action.action_count = bytes.decode_u16(4) + action.reserved = bytes.slice(6, 6 + 10) + + # TODO + action.actions = [] as Array[Action] + + action.event_count = 0 + + action.frame_times = 0.0 + + print(inst_to_dict(action)) + + return action + + +class Action: + ## 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 + + +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 + + +class SpriteLayer: + const BYTE_LENGTH := 48 + + ## 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 is_flipped_vertical: 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 sprite_type: int + + ## Byte Type: u32 [br] + ## Byte Length: 4 + var sprite_width: int + + ## Byte Type: u32 [br] + ## Byte Length: 4 + var sprite_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(sprite_width, sprite_height) + + +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) + + +class Event: + const BYTE_LENGTH := 40 + + ## Byte Type: u8 [br] + ## Byte Length: 40 + var name: String |