blob: a26633f2daf4d511bad44686c994b1e8a5dc9255 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
|