shotgun/serve/dto.go

71 lines
2.0 KiB
Go

package serve
import "github.com/google/uuid"
// Game is the JSON DTO for a game.
type Game struct {
// Players is the players in the game.
// The dealer is always the first player.
Players [2]Player `json:"players"`
// Action indicates the previous action taken in the game.
Action string `json:"action"`
// Winner indicates the winner of the match, if any.
Winner Winner `json:"winner,omitempty"`
// Round is the current round.
Round int8 `json:"round"`
// Dealer indicates whether the current player is the dealer.
Dealer bool `json:"dealer"`
// Damage is the damage a live shell will deal this turn.
Damage int8 `json:"damage"`
// Shell gives whether the current shell is live if it is revealed.
// Undefined if this game state is not for the current player or if the
// current player hasn't revealed it.
Shell *bool `json:"shell,omitempty"`
// Previous gives whether the previously discharged shell was live.
Previous *bool `json:"previous"`
// Live is the number of live shells this round, if it is the first turn
// of the round.
Live int `json:"live,omitempty"`
// Blank is the number of blank shells this round, if it is the first turn
// of the round.
Blank int `json:"blank,omitempty"`
}
// Player is the JSON DTO for a player.
type Player struct {
// HP is the player's current health.
HP int8 `json:"hp"`
// Items is the player's items.
Items [8]string `json:"items"`
// Cuffs is whether the player is currently wearing cuffs.
Cuffs bool `json:"cuffs,omitempty"`
}
type GameID = uuid.UUID
// GameStart is the JSON DTO given to each player when their game starts.
// Observers do not receive it.
type GameStart struct {
ID GameID `json:"id"`
Dealer bool `json:"dealer"`
}
// Winner is a round winner.
type Winner int8
const (
NoWinner Winner = iota
DealerWins
ChallengerWins
)
var winners = [...][]byte{
NoWinner: []byte("null"),
DealerWins: []byte("0"),
ChallengerWins: []byte("1"),
}
func (w *Winner) MarshalJSON() ([]byte, error) {
return winners[*w], nil
}