diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-12-13 14:53:38 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-12-13 14:53:38 +0100 |
commit | ca4d1945598863d0ce297f4272317e5dd5797f88 (patch) | |
tree | c2675b394140a71c7eee04034f087c107dcd7c9c /packets/item_option.gd | |
parent | a22381eff3bf2286ee27f4d15ddf4c431ea063be (diff) |
next commit
Diffstat (limited to 'packets/item_option.gd')
-rw-r--r-- | packets/item_option.gd | 40 |
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 |