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 GameData struct {
|
|
|
|
ItemId int
|
|
|
|
|
|
|
|
GameStartTick int
|
|
|
|
// TODO: add struct to wrap these flags
|
|
|
|
// use network7.GameStateFlag bit operations to turn it into a bunch of booleans
|
|
|
|
|
|
|
|
// GameStateFlags GameStateFlagsStruct
|
|
|
|
FlagsRaw int
|
|
|
|
|
|
|
|
GameStateEndTick int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *GameData) Id() int {
|
|
|
|
return o.ItemId
|
|
|
|
}
|
|
|
|
|
2024-06-24 14:50:15 +00:00
|
|
|
func (o *GameData) TypeId() int {
|
2024-06-24 09:03:13 +00:00
|
|
|
return network7.ObjGameData
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *GameData) Size() int {
|
|
|
|
return reflect.TypeOf(GameData{}).NumField() - 1
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *GameData) Pack() []byte {
|
|
|
|
return slices.Concat(
|
2024-06-24 14:50:15 +00:00
|
|
|
packer.PackInt(o.TypeId()),
|
2024-06-24 09:03:13 +00:00
|
|
|
packer.PackInt(o.Id()),
|
|
|
|
|
|
|
|
packer.PackInt(o.GameStartTick),
|
|
|
|
packer.PackInt(o.FlagsRaw),
|
|
|
|
packer.PackInt(o.GameStateEndTick),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *GameData) Unpack(u *packer.Unpacker) error {
|
|
|
|
o.GameStartTick = u.GetInt()
|
|
|
|
o.FlagsRaw = u.GetInt()
|
|
|
|
o.GameStateEndTick = u.GetInt()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|