go-teeworlds-protocol/object7/flag.go

49 lines
760 B
Go
Raw Normal View History

2024-06-24 09:03:13 +00:00
package object7
import (
"reflect"
"slices"
"github.com/teeworlds-go/go-teeworlds-protocol/network7"
"github.com/teeworlds-go/go-teeworlds-protocol/packer"
)
type Flag struct {
ItemId int
X int
Y int
Team network7.GameTeam
}
func (o *Flag) Id() int {
return o.ItemId
}
func (o *Flag) TypeId() int {
2024-06-24 09:03:13 +00:00
return network7.ObjFlag
}
func (o *Flag) Size() int {
return reflect.TypeOf(Flag{}).NumField() - 1
}
func (o *Flag) Pack() []byte {
return slices.Concat(
packer.PackInt(o.TypeId()),
2024-06-24 09:03:13 +00:00
packer.PackInt(o.Id()),
packer.PackInt(o.X),
packer.PackInt(o.Y),
packer.PackInt(int(o.Team)),
)
}
func (o *Flag) Unpack(u *packer.Unpacker) error {
o.X = u.GetInt()
o.Y = u.GetInt()
o.Team = network7.GameTeam(u.GetInt())
return nil
}