refactor: executors and routers
* refactor: executors and routers
This commit is contained in:
@@ -1,6 +1,24 @@
|
||||
package game
|
||||
|
||||
import "github.com/google/uuid"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Relation string
|
||||
|
||||
const (
|
||||
RelationWar Relation = "War"
|
||||
RelationPeace Relation = "Peace"
|
||||
)
|
||||
|
||||
var (
|
||||
relationSet = map[string]Relation{
|
||||
strings.ToLower(RelationWar.String()): RelationWar,
|
||||
strings.ToLower(RelationPeace.String()): RelationPeace,
|
||||
}
|
||||
)
|
||||
|
||||
type Race struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
@@ -15,17 +33,17 @@ type Race struct {
|
||||
ShipTypes []ShipType `json:"shipType,omitempty"`
|
||||
}
|
||||
|
||||
type Relation string
|
||||
func ParseRelation(v string) (Relation, bool) {
|
||||
if v, ok := relationSet[strings.ToLower(v)]; ok {
|
||||
return v, ok
|
||||
}
|
||||
return Relation(""), false
|
||||
}
|
||||
|
||||
func (r Relation) String() string {
|
||||
return string(r)
|
||||
}
|
||||
|
||||
const (
|
||||
RelationWar Relation = "War"
|
||||
RelationPeace Relation = "Peace"
|
||||
)
|
||||
|
||||
type RaceRelation struct {
|
||||
RaceID uuid.UUID `json:"raceId"`
|
||||
Relation Relation `json:"relation"`
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package game
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type State struct {
|
||||
ID uuid.UUID
|
||||
Turn uint
|
||||
Stage uint
|
||||
Players []PlayerState
|
||||
}
|
||||
|
||||
type PlayerState struct {
|
||||
ID uuid.UUID
|
||||
Name string
|
||||
Extinct bool
|
||||
}
|
||||
@@ -1,26 +1,30 @@
|
||||
package rest
|
||||
|
||||
/*
|
||||
Full list of requirements must be updated when adding new command:
|
||||
import "encoding/json"
|
||||
|
||||
required_without_all=Vote DeclarePeace DeclareWar
|
||||
| excluded_with=Vote DeclarePeace DeclareWar
|
||||
*/
|
||||
type Command struct {
|
||||
Race string `json:"race" binding:"required,notblank"`
|
||||
Vote *CommandVote `json:"vote" binding:"required_without_all=DeclarePeace DeclareWar,excluded_with=DeclarePeace DeclareWar"`
|
||||
DeclarePeace *CommandDeclarePeace `json:"declarePeace" binding:"required_without_all=Vote DeclareWar,excluded_with=Vote DeclareWar"`
|
||||
DeclareWar *CommandDeclareWar `json:"declareWar" binding:"required_without_all=Vote DeclarePeace,excluded_with=Vote DeclarePeace"`
|
||||
Actor string `json:"actor" binding:"required,notblank"`
|
||||
Commands []json.RawMessage `json:"cmd" binding:"min=1"`
|
||||
}
|
||||
|
||||
type CommandType string
|
||||
|
||||
const (
|
||||
CommandTypeVote CommandType = "vote"
|
||||
CommandTypeRelation CommandType = "declarePeace"
|
||||
)
|
||||
|
||||
type CommandMeta struct {
|
||||
Type CommandType `json:"@type"`
|
||||
}
|
||||
|
||||
type CommandVote struct {
|
||||
CommandMeta
|
||||
Recipient string `json:"recipient" binding:"required,notblank"`
|
||||
}
|
||||
|
||||
type CommandDeclarePeace struct {
|
||||
Opponent string `json:"recipient" binding:"required,notblank"`
|
||||
}
|
||||
|
||||
type CommandDeclareWar struct {
|
||||
type CommandUpdateRelation struct {
|
||||
CommandMeta
|
||||
Opponent string `json:"recipient" binding:"required,notblank"`
|
||||
Relation string `json:"relation" binding:"required,notblank"`
|
||||
}
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
package rest
|
||||
|
||||
type Status struct {
|
||||
Turn uint `json:"turn"`
|
||||
Players int `json:"players"`
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type StateResponse struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Turn uint `json:"turn"`
|
||||
Stage uint `json:"stage"`
|
||||
Players []PlayerState `json:"player"`
|
||||
}
|
||||
|
||||
type PlayerState struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Extinct bool `json:"extinct"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user