package system
import (
"github.com/argus-labs/monorepo/pkg/cardinal"
)
type MovePlayerCommand struct {
cardinal.BaseCommand
// The payload of the command.
X uint32 `json:"x"`
Y uint32 `json:"y"`
}
func (MovePlayerCommand) Name() string {
// The name of the command. Clients specify the name when sending the command.
return "move-player"
}
type MovePlayerSystemState struct {
cardinal.BaseSystemState
MovePlayerCommands cardinal.WithCommand[MovePlayerCommand]
Players PlayerSearch
}
func MovePlayerSystem(state *MovePlayerSystemState) error {
// Iterate over all move-player commands received in the tick.
for cmd := range state.MovePlayerCommands.Iter() {
payload := cmd.Payload()
state.Logger().Info().Msgf("Player moved to %d, %d", payload.X, payload.Y)
// You can also access the persona associated with the command.
persona := cmd.Persona()
state.Logger().Info().Msgf("Command sent by persona %s", persona)
}
return nil
}