summaryrefslogtreecommitdiff
path: root/extractor/action_format.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-12-12 02:12:52 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-12-12 02:12:52 +0100
commita22381eff3bf2286ee27f4d15ddf4c431ea063be (patch)
tree965bdcf12e5e0cf63c88cbba1bd5a52ba474f81f /extractor/action_format.gd
parente3c185e05823e30eccd7728ceda2ee57cc66fd4d (diff)
next commit
Diffstat (limited to 'extractor/action_format.gd')
-rw-r--r--extractor/action_format.gd58
1 files changed, 41 insertions, 17 deletions
diff --git a/extractor/action_format.gd b/extractor/action_format.gd
index ff2ba64..719bc2d 100644
--- a/extractor/action_format.gd
+++ b/extractor/action_format.gd
@@ -57,18 +57,22 @@ static func from_bytes(bytes: ByteStream) -> ActionFormat:
version.major = bytes.decode_u8()
action_format.version = version
+ if version.major < 2 and version.minor < 3:
+ print(version)
+ return action_format
+
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)
+ var action = ActionData.from_bytes(bytes, version)
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)
+ var event = Event.from_bytes(bytes, version)
action_format.events.append(event)
action_format.frame_times = [] as Array[float]
@@ -95,13 +99,13 @@ class ActionData:
return length
- static func from_bytes(bytes: ByteStream) -> ActionData:
+ static func from_bytes(bytes: ByteStream, version: Version) -> 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)
+ var motion = Motion.from_bytes(bytes, version)
action.motions.append(motion)
return action
@@ -135,7 +139,7 @@ class Motion:
return 44 + SpriteLayer.BYTE_LENGTH * sprite_layer_count + SpriteAnchor.BYTE_LENGTH * sprite_anchor_count
- static func from_bytes(bytes: ByteStream):
+ static func from_bytes(bytes: ByteStream, version: Version):
var motion = Motion.new()
motion.unused = bytes.get_buffer(32).bytes
@@ -143,7 +147,7 @@ class Motion:
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)
+ var sprite_layer = SpriteLayer.from_bytes(bytes, version)
motion.sprite_layers.append(sprite_layer)
motion.event_id = bytes.decode_s32()
@@ -151,8 +155,8 @@ class Motion:
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)
+ var sprite_anchor = SpriteAnchor.from_bytes(bytes, version)
+ motion.sprite_anchors.append(sprite_anchor)
return motion
@@ -194,10 +198,17 @@ class SpriteLayer:
## Byte Type: f32 [br]
## Byte Length: 4
+ ## Versions: [2.3, 2.4]
+ var scale: float
+
+ ## Byte Type: f32 [br]
+ ## Byte Length: 4
+ ## Versions: [2.5]
var scale_u: float
## Byte Type: f32 [br]
## Byte Length: 4
+ ## Versions: [2.5]
var scale_v: float
## Byte Type: i32 [br]
@@ -226,14 +237,20 @@ class SpriteLayer:
func get_scale() -> Vector2:
- return Vector2(scale_u, scale_v)
+ if scale:
+ return Vector2(scale, scale)
+ else:
+ return Vector2(scale_u, scale_v)
func get_size() -> Vector2:
- return Vector2(width, height)
+ if width and height:
+ return Vector2(width, height)
+ else:
+ return Vector2.ZERO
- static func from_bytes(bytes: ByteStream):
+ static func from_bytes(bytes: ByteStream, version: Version):
var sprite_layer = SpriteLayer.new()
sprite_layer.position_u = bytes.decode_s32()
@@ -244,12 +261,19 @@ class SpriteLayer:
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()
+
+ if version.major == 2 and version.minor >= 4:
+ sprite_layer.scale_u = bytes.decode_float()
+ sprite_layer.scale_v = bytes.decode_float()
+ else:
+ sprite_layer.scale = 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()
+
+ if version.to_string() == "2.5":
+ sprite_layer.width = bytes.decode_u32()
+ sprite_layer.height = bytes.decode_u32()
return sprite_layer
@@ -278,7 +302,7 @@ class SpriteAnchor:
return Vector2(position_u, position_v)
- static func from_bytes(bytes: ByteStream):
+ static func from_bytes(bytes: ByteStream, version: Version):
var sprite_anchor = SpriteAnchor.new()
sprite_anchor.unused = bytes.get_buffer(4).bytes
@@ -297,7 +321,7 @@ class Event:
var name: String
- static func from_bytes(bytes: ByteStream):
+ static func from_bytes(bytes: ByteStream, version: Version):
var event = Event.new()
event.name = bytes.get_string_from_utf8(BYTE_LENGTH)