blob: 8f591668b9220a7f95a6496d9109833644fb3670 (
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
|
class_name ItemOption
extends PacketChunk
const BYTE_LENGTH := 5
## Byte Type: u16
## Byte Length: 2
var index: int
## Byte Type: u16
## Byte Length: 2
var value: int
## Byte Type: u8
## Byte Length: 1
var parameter: int
static func from_bytes(bytes: PackedByteArray):
var option = ItemOption.new()
option.index = bytes.decode_u16(0)
option.value = bytes.decode_u16(2)
option.parameter = bytes.decode_u8(3)
return option
static func array_from_bytes(bytes: PackedByteArray) -> Array[ItemOption]:
var array: Array[ItemOption] = []
var offset = 0
while offset < bytes.size():
var chunk = from_bytes(bytes.slice(offset))
array.append(chunk)
offset += chunk.byte_length
return array
|