go-teeworlds-protocol/object7/snap_object.go

73 lines
2 KiB
Go
Raw Normal View History

2024-06-24 09:03:13 +00:00
package object7
import (
"log"
"github.com/teeworlds-go/go-teeworlds-protocol/network7"
"github.com/teeworlds-go/go-teeworlds-protocol/packer"
)
type SnapObject interface {
// id separating this snap item from other items with same type
// the ids are unique per type
// for players it matches their ClientId
2024-06-24 09:03:13 +00:00
Id() int
// type of the snap item
TypeId() int
2024-06-24 09:03:13 +00:00
// number of packed integers
// not the number of bytes
Size() int
Pack() []byte
Unpack(u *packer.Unpacker) error
}
// Comes without payload
// you have to call item.Unpack(u) manually after getting it
func NewObject(typeId int, itemId int) SnapObject {
if typeId == network7.ObjProjectile {
return &Projectile{ItemId: itemId}
} else if typeId == network7.ObjLaser {
return &Laser{ItemId: itemId}
} else if typeId == network7.ObjFlag {
2024-06-24 09:03:13 +00:00
return &Flag{ItemId: itemId}
} else if typeId == network7.ObjPickup {
2024-06-24 09:03:13 +00:00
return &Pickup{ItemId: itemId}
} else if typeId == network7.ObjGameData {
2024-06-24 09:03:13 +00:00
return &GameData{ItemId: itemId}
} else if typeId == network7.ObjGameDataTeam {
2024-06-24 09:03:13 +00:00
return &GameDataTeam{ItemId: itemId}
} else if typeId == network7.ObjGameDataFlag {
2024-06-24 09:03:13 +00:00
return &GameDataFlag{ItemId: itemId}
} else if typeId == network7.ObjCharacter {
2024-06-24 09:03:13 +00:00
return &Character{ItemId: itemId}
} else if typeId == network7.ObjPlayerInfo {
2024-06-24 09:03:13 +00:00
return &PlayerInfo{ItemId: itemId}
} else if typeId == network7.ObjSpectatorInfo {
return &SpectatorInfo{ItemId: itemId}
} else if typeId == network7.ObjExplosion {
return &Explosion{ItemId: itemId}
} else if typeId == network7.ObjSpawn {
return &Spawn{ItemId: itemId}
} else if typeId == network7.ObjHammerHit {
return &HammerHit{ItemId: itemId}
} else if typeId == network7.ObjDeath {
return &Death{ItemId: itemId}
} else if typeId == network7.ObjSoundWorld {
return &SoundWorld{ItemId: itemId}
} else if typeId == network7.ObjDamage {
return &Damage{ItemId: itemId}
2024-06-24 09:03:13 +00:00
}
// TODO: remove this is just for debugging
log.Fatalf("unknown item type %d\n", typeId)
2024-06-24 09:03:13 +00:00
unknown := &Unknown{
ItemId: itemId,
ItemType: typeId,
2024-06-24 09:03:13 +00:00
}
return unknown
}