~nromdotcom/gemif

ref: 9b7a8a567d14485941e0fa82d75b91b02d15b5e6 gemif/pkg/gamemanager/gamestate.go -rw-r--r-- 741 bytes
9b7a8a56Norm MacLennan try switching to protobuf for state tokens 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package gamemanager

// GameState contains state information about an active game in progress.
type GameState struct {
	StoryID     string   `json:"si"`
	CurrentRoom string   `json:"cr"`
	Conditions  []string `json:"cn"`
}

// MeetCondition adds a condtition to the list of met conditions if not already met.
func (gs *GameState) MeetCondition(cond string) {
	if !isInSlice(gs.Conditions, cond) {
		gs.Conditions = append(gs.Conditions, cond)
	}
}

// ConditionMet checks to see if a condition has been met.
func (gs GameState) ConditionMet(cond string) bool {
	return isInSlice(gs.Conditions, cond)
}

func isInSlice(slice []string, val string) bool {
	for _, item := range slice {
		if item == val {
			return true
		}
	}

	return false
}