summaryrefslogtreecommitdiff
path: root/packets/item_option.gd
diff options
context:
space:
mode:
Diffstat (limited to 'packets/item_option.gd')
-rw-r--r--packets/item_option.gd40
1 files changed, 40 insertions, 0 deletions
diff --git a/packets/item_option.gd b/packets/item_option.gd
new file mode 100644
index 0000000..8f59166
--- /dev/null
+++ b/packets/item_option.gd
@@ -0,0 +1,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