custom deck support, card type generation

This commit is contained in:
stryan 2021-11-08 15:01:07 -05:00
parent 3a38ef2252
commit c588dab2ae
5 changed files with 104 additions and 14 deletions

View File

@ -19,6 +19,7 @@ type Card struct {
Effects []*Effect `json:"effects"` Effects []*Effect `json:"effects"`
} }
//go:generate enumer -type=CardType -json
type CardType int type CardType int
const ( const (
@ -50,12 +51,6 @@ func NewEmpty(p int) *Card {
Effects: []*Effect{}, Effects: []*Effect{},
} }
} }
func (c CardType) String() string {
if c == -1 {
return " "
}
return []string{"V", "A", "2", "3", "4", "5", "6", "7", "8"}[c]
}
func (c *Card) Empty() bool { func (c *Card) Empty() bool {
return c.Type == EmptyValue return c.Type == EmptyValue

77
cardtype_enumer.go Normal file
View File

@ -0,0 +1,77 @@
// Code generated by "enumer -type=CardType -json"; DO NOT EDIT.
//
package tome_lib
import (
"encoding/json"
"fmt"
)
const _CardTypeName = "EmptyValueValkAceTwoThreeFourFiveSixSevenEight"
var _CardTypeIndex = [...]uint8{0, 10, 14, 17, 20, 25, 29, 33, 36, 41, 46}
func (i CardType) String() string {
i -= -1
if i < 0 || i >= CardType(len(_CardTypeIndex)-1) {
return fmt.Sprintf("CardType(%d)", i+-1)
}
return _CardTypeName[_CardTypeIndex[i]:_CardTypeIndex[i+1]]
}
var _CardTypeValues = []CardType{-1, 0, 1, 2, 3, 4, 5, 6, 7, 8}
var _CardTypeNameToValueMap = map[string]CardType{
_CardTypeName[0:10]: -1,
_CardTypeName[10:14]: 0,
_CardTypeName[14:17]: 1,
_CardTypeName[17:20]: 2,
_CardTypeName[20:25]: 3,
_CardTypeName[25:29]: 4,
_CardTypeName[29:33]: 5,
_CardTypeName[33:36]: 6,
_CardTypeName[36:41]: 7,
_CardTypeName[41:46]: 8,
}
// CardTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func CardTypeString(s string) (CardType, error) {
if val, ok := _CardTypeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to CardType values", s)
}
// CardTypeValues returns all values of the enum
func CardTypeValues() []CardType {
return _CardTypeValues
}
// IsACardType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i CardType) IsACardType() bool {
for _, v := range _CardTypeValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for CardType
func (i CardType) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for CardType
func (i *CardType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("CardType should be a string, got %s", data)
}
var err error
*i, err = CardTypeString(s)
return err
}

5
go.mod
View File

@ -2,4 +2,7 @@ module git.saintnet.tech/tomecraft/tome_lib
go 1.16 go 1.16
require github.com/google/uuid v1.3.0 require (
github.com/alvaroloes/enumer v1.1.2 // indirect
github.com/google/uuid v1.3.0
)

11
go.sum
View File

@ -1,2 +1,13 @@
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 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1 h1:/I3lTljEEDNYLho3/FUB7iD/oc2cEFgVmbHzV+O0PtU=
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 h1:iEAPfYPbYbxG/2lNN4cMOHkmgKNsCuUwkxlDCK46UlU=
golang.org/x/tools v0.0.0-20190524210228-3d17549cdc6b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=

View File

@ -16,6 +16,7 @@ const (
SessionCmdPlay = "play" SessionCmdPlay = "play"
SessionCmdPoll = "poll" SessionCmdPoll = "poll"
SessionCmdReady = "ready" SessionCmdReady = "ready"
SessionCmdLoadDeck = "load_deck"
) )
const ( const (
@ -26,7 +27,9 @@ const (
SessionRespJoinError = "join error" SessionRespJoinError = "join error"
SessionRespLeft = "left" SessionRespLeft = "left"
SessionRespPlayed = "played" SessionRespPlayed = "played"
SessionRespDeckLoaded = "deck loaded"
SessionRespError = "generic error" SessionRespError = "generic error"
SessionRespLoadDeckError = "load deck error"
SessionRespBroadcastSenTurn = "Sentinal turn" SessionRespBroadcastSenTurn = "Sentinal turn"
SessionRespBroadcastScoTrun = "Scourge turn" SessionRespBroadcastScoTrun = "Scourge turn"
SessionRespBroadcastSenWin = "Sentinal wins" SessionRespBroadcastSenWin = "Sentinal wins"
@ -46,10 +49,11 @@ type SessionCommand struct {
MatchID uuid.UUID `json:"match_id"` MatchID uuid.UUID `json:"match_id"`
Command SessionCmd `json:"command"` Command SessionCmd `json:"command"`
GameCommand *Command `json:"game_command,omitempty"` GameCommand *Command `json:"game_command,omitempty"`
Data string `json:"data,omitempty"`
} }
func (s *SessionCommand) String() string { func (s *SessionCommand) String() string {
return fmt.Sprintf("%v %v %v\n", s.ID, s.Command, s.GameCommand) return fmt.Sprintf("%v %v %v %v\n", s.ID, s.Command, s.GameCommand, s.Data)
} }
type SessionCommandResult struct { type SessionCommandResult struct {