From ca4d1945598863d0ce297f4272317e5dd5797f88 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 13 Dec 2024 14:53:38 +0100 Subject: next commit --- packets/item_option.gd | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 packets/item_option.gd (limited to 'packets/item_option.gd') 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 -- cgit v1.2.3