diff --git a/game.go b/game.go index dbbe322..777b39e 100644 --- a/game.go +++ b/game.go @@ -7,6 +7,7 @@ import ( ) //GameState is an int representing the current state the game's in +//go:generate enumer -type=GameState type GameState int const ( diff --git a/gamestate_enumer.go b/gamestate_enumer.go new file mode 100644 index 0000000..94c1696 --- /dev/null +++ b/gamestate_enumer.go @@ -0,0 +1,54 @@ +// Code generated by "enumer -type=GameState"; DO NOT EDIT. + +// +package freego + +import ( + "fmt" +) + +const _GameStateName = "gameLobbygameSetupgameTurnRedgameTurnBluegameWinRedgameWinBlue" + +var _GameStateIndex = [...]uint8{0, 9, 18, 29, 41, 51, 62} + +func (i GameState) String() string { + if i < 0 || i >= GameState(len(_GameStateIndex)-1) { + return fmt.Sprintf("GameState(%d)", i) + } + return _GameStateName[_GameStateIndex[i]:_GameStateIndex[i+1]] +} + +var _GameStateValues = []GameState{0, 1, 2, 3, 4, 5} + +var _GameStateNameToValueMap = map[string]GameState{ + _GameStateName[0:9]: 0, + _GameStateName[9:18]: 1, + _GameStateName[18:29]: 2, + _GameStateName[29:41]: 3, + _GameStateName[41:51]: 4, + _GameStateName[51:62]: 5, +} + +// GameStateString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func GameStateString(s string) (GameState, error) { + if val, ok := _GameStateNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to GameState values", s) +} + +// GameStateValues returns all values of the enum +func GameStateValues() []GameState { + return _GameStateValues +} + +// IsAGameState returns "true" if the value is listed in the enum definition. "false" otherwise +func (i GameState) IsAGameState() bool { + for _, v := range _GameStateValues { + if i == v { + return true + } + } + return false +}