generate gamestate_enumerator

This commit is contained in:
stryan 2022-03-07 15:23:14 -05:00
parent b5fc903394
commit dd8dce8869
2 changed files with 55 additions and 0 deletions

View File

@ -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 (

54
gamestate_enumer.go Normal file
View File

@ -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
}