40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package types
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"io"
|
|
)
|
|
|
|
// EquipmentItem represents an equipment item with model and color information
|
|
type EquipmentItem struct {
|
|
Type uint16 // Model/item type ID
|
|
Color Color // RGB color for the item
|
|
}
|
|
|
|
// Serialize writes the equipment item to a writer
|
|
func (e *EquipmentItem) Serialize(w io.Writer) error {
|
|
if err := binary.Write(w, binary.LittleEndian, e.Type); err != nil {
|
|
return err
|
|
}
|
|
return e.Color.Serialize(w)
|
|
}
|
|
|
|
// SerializeToBytes writes the equipment item to a byte slice at the given offset
|
|
func (e *EquipmentItem) SerializeToBytes(dest []byte, offset *uint32) {
|
|
binary.LittleEndian.PutUint16(dest[*offset:], e.Type)
|
|
*offset += 2
|
|
e.Color.SerializeToBytes(dest, offset)
|
|
}
|
|
|
|
// Size returns the serialized size of the equipment item
|
|
func (e *EquipmentItem) Size() uint32 {
|
|
return 2 + e.Color.Size() // 2 bytes for type + color size
|
|
}
|
|
|
|
// Deserialize reads an equipment item from a reader
|
|
func (e *EquipmentItem) Deserialize(r io.Reader) error {
|
|
if err := binary.Read(r, binary.LittleEndian, &e.Type); err != nil {
|
|
return err
|
|
}
|
|
return e.Color.Deserialize(r)
|
|
} |