From a22381eff3bf2286ee27f4d15ddf4c431ea063be Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 12 Dec 2024 02:12:52 +0100 Subject: next commit --- packets/achievement_data.gd | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 packets/achievement_data.gd (limited to 'packets/achievement_data.gd') diff --git a/packets/achievement_data.gd b/packets/achievement_data.gd new file mode 100644 index 0000000..a26633f --- /dev/null +++ b/packets/achievement_data.gd @@ -0,0 +1,50 @@ +class_name AchievementData +extends PacketChunk + + +const BYTE_LENGTH := 50 + + +## Byte Type: u32 +## Byte Length: 4 +var achievement_id: int + +## Byte Type: u8 +## Byte Length: 1 +var is_completed: bool + +## Byte Type: u32 +## Byte Length: 4 * 10 +var objectives: PackedByteArray + +## Byte Type: u32 +## Byte Length: 4 +var completion_timestamp: int + +## Byte Type: u8 +## Byte Length: 1 +var got_rewarded: bool + + +static func from_bytes(bytes: PackedByteArray) -> AchievementData: + var achievement_data = AchievementData.new() + + achievement_data.achievement_id = bytes.decode_u32(0) + achievement_data.is_completed = bytes.decode_u8(4) + achievement_data.objectives = bytes.slice(5, 5 + 40) + achievement_data.completion_timestamp = bytes.decode_u32(45) + achievement_data.got_rewarded = bytes.decode_u8(49) + + return achievement_data + + +static func array_from_bytes(bytes: PackedByteArray) -> Array[AchievementData]: + var array: Array[AchievementData] = [] + + var offset = 0 + while offset < bytes.size(): + var chunk = from_bytes(bytes.slice(offset)) + array.append(chunk) + offset += chunk.byte_length + + return array -- cgit v1.2.3