Documentation ¶
Index ¶
- type BlankSmartObjectAdditional
- type Chat
- type ChatAuthor
- type ChatMessage
- type GameObject
- type Player
- type Resource
- type SmartObject
- type SmartObjectAdditional
- type SmartObjectAdditionalParser
- type State
- func (s *State) HandleMessage(packet srvpkts.Packet)
- func (s *State) OnControllableSmartObjectLoaded(listener func(*SmartObject))
- func (s *State) OnControllableSmartObjectLost(listener func(*SmartObject))
- func (s *State) OnSelfLoaded(listener func(*Player))
- func (s *State) OnSelfLost(listener func(*Player))
- type TeamRoleUIDLookup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlankSmartObjectAdditional ¶
type BlankSmartObjectAdditional struct{}
BlankSmartObjectAdditional is for objects with no additional information
func (*BlankSmartObjectAdditional) Update ¶
func (a *BlankSmartObjectAdditional) Update(update *srvpkts.SmartObjectUpdatePacket) error
Update is no-op
type Chat ¶
type Chat struct { // LocalChatAuthorsByUID contains all of the chat authors that would hear // any messages we send locally right now. LocalChatAuthorsByUID map[string]*ChatAuthor // RecentChatAuthorsByUID contains all of the chat authors that are in the // message history RecentChatAuthorsByUID map[string]*ChatAuthor // RecentChatAuthorUIDsToCount maps from the keys in RecentChatAuthorsByUID // to the number of messages by that chat author in the message history. Each // value is positive - when it reaches 0 the key is deleted from the map // and the chat author is removed from RecentChatAuthorsByUID. RecentChatAuthorUIDsToCount map[string]int // MessageHistory is the ring of recent messages MessageHistory *rbuf.PointerRingBuf // contains filtered or unexported fields }
Chat maintains the chat history and current set of chat authors
func NewChat ¶
NewChat initializes a blank chat event that will need a game sync event to fully initialize
func (*Chat) HandleMessage ¶
HandleMessage should be called on any packet received from the server to update the state of the chat.
type ChatAuthor ¶
type ChatAuthor struct { // UID is the identifier for the chat author UID string // Name is the display name of the chat author Name string // Color is the CSS class that represents the color that the chat author // should be rendered with. Any CSS class loaded on the play page of the // website is valid. Color string // BonusClasses contains all of the additional CSS classes for the text of // this author. Any CSS class loaded on the play page of the website is // valid. BonusClasses []string }
ChatAuthor describes a chat author from the perspective of the client
func (*ChatAuthor) Update ¶
func (a *ChatAuthor) Update(sync *srvpkts.ChatAuthorSync) *ChatAuthor
Update this chat author to match the given sync information, then return this chat author
type ChatMessage ¶
type ChatMessage struct { // GameTime when this message was received by the server GameTime float64 // Time is the real time when the message was received by the server Time time.Time // ChatAuthor is a pointer to the chat author for this chat message; // this pointer is only valid while the message is in the Chat buffer, // otherwise it may be stale. ChatAuthor *ChatAuthor // Text of the message Text string }
ChatMessage describes a chat message
type GameObject ¶
type GameObject struct { // UID of the object UID string // SheetURL describes where the PixiJS spritesheet file containing // the animations for this object can be found SheetURL string // SpriteScale describes the x/y scaling for this game object compared // to the underlying sprite. SpriteScale cp.Vector // SpriteRotation is the default rotation in radians for this game object // compared to how it is on the spritesheet, which can be used for object // packing SpriteRotation float64 // RenderOffset is the visual offset of the sprite on the screen in pixels // at standard zoom. RenderOffset cp.Vector // Animation is the name of the animation within the sheet that // should currently be used to render this object. Animation string // AnimationSpeed is the speed of the animation, where 1 is 60 // frames per second, 0.5 is 30 frames per second, and 2 is // 120 frames per second. AnimationSpeed float64 // AnimationPlaying is true if the animation should actually play // and false if it should be frozen on an arbitrary frame. AnimationPlaying bool // AnimationLooping is true if the animation should loop when // finished and false if it should not. AnimationLooping bool // Body is the physics body for this game object, with the appropriate // shapes, position, velocity, angle, and angular velocity, but not // attached to any space and hence not simulated. Body *cp.Body }
GameObject describes some object that's within the game. This is often wrapped.
func (*GameObject) Sync ¶
func (o *GameObject) Sync(packet *srvpkts.GameObjectSync) *GameObject
Sync this game object using the given information. This overwrites everything
func (*GameObject) Update ¶
func (o *GameObject) Update(packet *srvpkts.GameObjectUpdatePacket) *GameObject
Update this game object with the given information, which only affects the relatively frequently changing fields
type Player ¶
type Player struct { // GameObject for this player GameObject *GameObject // Role this player is fulfilling Role utils.Role // Team this player is on Team int }
Player describes a player in the world from the perspective of the client
type Resource ¶
type Resource struct { // UID of this resource UID string // SheetURL where the PixiJS spritesheet containing this resource // can be found SheetURL string // Animation within the sheet for this resource Animation string // How much of this resource we have Amount int }
Resource describes a resource from the perspective of the client.
type SmartObject ¶
type SmartObject struct { // GameObject for this smart object GameObject *GameObject // UnitType that this smart object is acting as UnitType string // CurrentHealth of this unit, may be a rounded representation of the // units true health CurrentHealth int // MaxHealth of this unit MaxHealth int // ControllingTeam is the team which controls this object. ControllingTeam int // ControllingRole is the role required to control this object. See utils.Role ControllingRole utils.Role // Additional contains the SyncInfo on the Unit controlling this smart object, // and depends on the type of unit. Additional SmartObjectAdditional }
SmartObject describes a "fancy" non-player unit in the world. These are often controllable by someone and have special orders. The UnitType of the smart object acts as the enum for the special behavior of the object.
func (*SmartObject) Sync ¶
func (o *SmartObject) Sync(sync *srvpkts.SmartObjectSync) *SmartObject
Sync this smart object with the given sync information
func (*SmartObject) Update ¶
func (o *SmartObject) Update(update *srvpkts.SmartObjectUpdatePacket) *SmartObject
Update this smart object with the given update packet
type SmartObjectAdditional ¶
type SmartObjectAdditional interface { // Update the additional information using the given packet Update(update *srvpkts.SmartObjectUpdatePacket) error }
SmartObjectAdditional describes additional information on a SmartObject
func ParseSmartObjectAdditional ¶
func ParseSmartObjectAdditional(sync *srvpkts.SmartObjectSync) (SmartObjectAdditional, error)
ParseSmartObjectAdditional parses a SmartObjectAdditional from the given SmartObjectSync based on its UnitType
type SmartObjectAdditionalParser ¶
type SmartObjectAdditionalParser func(*srvpkts.SmartObjectSync) (SmartObjectAdditional, error)
SmartObjectAdditionalParser parses a SmartObjectAdditional from a SmartObjectSync
type State ¶
type State struct { // MyUID is the uid of the game object of the player for this client MyUID string // MyTeam is the team that the player for this client is on MyTeam int // MyRole is the role of the player for this client MyRole utils.Role // GameTime is the current game time GameTime float64 // PlayersByUID contains all the currently visible players mapped from // their uid. PlayersByUID map[string]*Player // PlayerUIDsByTeamAndRole allows quickly looking up the set of players // which have a given team or a given team and role. PlayerUIDsByTeamAndRole TeamRoleUIDLookup // StaticObjects contains all of the static objects in the game. These // do not move or change and you can see them regardless of vision. StaticObjects []GameObject // SmartObjectsByUID contains all of the currently visible smart objects // mapped from their uid. SmartObjectsByUID map[string]*SmartObject // GameObjectsByUID contains any generic game objects within vision. // Besides handling them for the purpose of collision these are largely // irrelevant to gameplay. GenericObjectsByUID map[string]*GameObject // ResourcesByUID contains all the resources on the clients team, mapped // from their uid. ResourcesByUID map[string]*Resource // contains filtered or unexported fields }
State describes the general state of the world from the perspective of the client right now. This is generally used to take over the generic packet management for AIs so they can focus on unit / player controls rather than just synchronizing the client state.
func NewState ¶
func NewState() *State
NewState initializes a blank state that will need the game sync packet in order to fill into normal representation. Typically the state can be considered invalid if the GameTime is 0.
func (*State) HandleMessage ¶
HandleMessage should be called whenever a new server packet is received. If the packet is relevant to the client state, this updates the client state appropriately.
func (*State) OnControllableSmartObjectLoaded ¶ added in v0.1.0
func (s *State) OnControllableSmartObjectLoaded(listener func(*SmartObject))
OnControllableSmartObjectLoaded is called when a new smart object that the player can control is loaded from a packet, such as via a game sync or because it just came into vision or it was just created.
func (*State) OnControllableSmartObjectLost ¶ added in v0.1.0
func (s *State) OnControllableSmartObjectLost(listener func(*SmartObject))
OnControllableSmartObjectLost is called whenever a smart object which is controlled by the player is lost, such as at the beginning of a game sync, because it died, or because we lost vision of it.
func (*State) OnSelfLoaded ¶ added in v0.1.0
OnSelfLoaded will register the given listener to be called whenever the Player with uid s.MyUID is loaded from a packet. Typically this is on game sync.
func (*State) OnSelfLost ¶ added in v0.1.0
OnSelfLost will register the given listener to be called whenever the Player with uid s.MyUID is removed from the game. Typically is the first stage of a game sync packet.
type TeamRoleUIDLookup ¶ added in v0.2.2
TeamRoleUIDLookup provides a lookup of the set of UIDs for players which are within a particular team and role.
func (TeamRoleUIDLookup) EachOnTeam ¶ added in v0.2.2
func (l TeamRoleUIDLookup) EachOnTeam(team int, fnc func(string))
EachOnTeam calls the given function on each player in the given team.