custom deck support

This commit is contained in:
stryan 2021-11-08 15:01:23 -05:00
parent 469c6606a3
commit 785936fada
4 changed files with 45 additions and 24 deletions

View File

@ -67,7 +67,15 @@ func (c *Coordinator) Coordinate(cmd *SessionCommand) *SessionCommandResult {
resp := m.Join(cmd.ID)
if m.p1 != uuid.Nil && m.p2 != uuid.Nil {
log.Printf("Starting game for %v and %v\n", m.p1, m.p2)
m.Game = tome_game.NewGame()
d1 := []int{}
d2 := []int{}
if m.p1Deck != nil {
d1 = m.p1Deck
}
if m.p2Deck != nil {
d2 = m.p2Deck
}
m.Game = tome_game.NewGame(d1, d2)
m.Active = true
}
return &SessionCommandResult{

4
go.mod
View File

@ -7,3 +7,7 @@ require (
git.saintnet.tech/tomecraft/tome_lib v0.1.3
github.com/google/uuid v1.3.0
)
replace git.saintnet.tech/tomecraft/tome_game => ../tome_game
replace git.saintnet.tech/tomecraft/tome_lib => ../tome_lib

9
go.sum
View File

@ -20,5 +20,14 @@ git.saintnet.tech/tomecraft/tome_lib v0.1.2 h1:S2BHgsWBGFv9fy+qBHuKXv0kcjT7VP/7g
git.saintnet.tech/tomecraft/tome_lib v0.1.2/go.mod h1:Jekqa9ojNDOrcO1aL0IWKuhCQSE5+MNHVcYtTWA6uko=
git.saintnet.tech/tomecraft/tome_lib v0.1.3 h1:JHW5ozFDfikLcRakAUSX+xxXlwNb4nmlcl8/ja7dKAo=
git.saintnet.tech/tomecraft/tome_lib v0.1.3/go.mod h1:Jekqa9ojNDOrcO1aL0IWKuhCQSE5+MNHVcYtTWA6uko=
github.com/alvaroloes/enumer v1.1.2 h1:5khqHB33TZy1GWCO/lZwcroBFh7u+0j40T83VUbfAMY=
github.com/alvaroloes/enumer v1.1.2/go.mod h1:FxrjvuXoDAx9isTJrv4c+T410zFi0DtXIT0m65DJ+Wo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190524210228-3d17549cdc6b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=

View File

@ -1,7 +1,7 @@
package coordinator
import (
"fmt"
"encoding/json"
"time"
. "git.saintnet.tech/tomecraft/tome_game"
@ -14,6 +14,8 @@ type Session struct {
p1 uuid.UUID
p2 uuid.UUID
pMap map[uuid.UUID]int
p1Deck []int
p2Deck []int
Active bool
Game *Game
Watcher chan bool
@ -80,29 +82,27 @@ func (s *Session) Play(id uuid.UUID, cmd *Command) *CommandResult {
return res
}
func (s *Session) LoadDeck(id uuid.UUID, data string) SessionResp {
var deck []int
err := json.Unmarshal([]byte(data), &data)
if err != nil {
return SessionRespLoadDeckError
}
valid := ValidateDeck(deck)
if !valid {
return SessionRespLoadDeckError
}
if id == s.p1 {
s.p1Deck = deck
} else if id == s.p2 {
s.p2Deck = deck
} else {
return SessionRespError
}
return SessionRespDeckLoaded
}
func (s *Session) PlayerIn(id uuid.UUID) bool {
_, exists := s.pMap[id]
return exists
}
type SessionCommand struct {
ID uuid.UUID `json:"player_id"`
MatchID uuid.UUID `json:"match_id"`
Command SessionCmd `json:"command"`
GameCommand *Command `json:"game_command,omitempty"`
}
func (s *SessionCommand) String() string {
return fmt.Sprintf("%v %v %v\n", s.ID, s.Command, s.GameCommand)
}
type SessionCommandResult struct {
ID uuid.UUID `json:"player_id"`
MatchID uuid.UUID `json:"match_id"`
Result SessionResp `json:"result"`
GameResult *CommandResult `json:"game_result,omitempty"`
}
func (s *SessionCommandResult) String() string {
return fmt.Sprintf("%v %v %v\n", s.ID, s.Result, s.GameResult)
}