diff options
Diffstat (limited to 'packets/achievement_data.gd')
-rw-r--r-- | packets/achievement_data.gd | 50 |
1 files changed, 50 insertions, 0 deletions
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 |