~nromdotcom/gemif

ref: 2a3f890ddab872d9b4e2ba4b1a2f413ad934ad3d gemif/pkg/gamemanager/room.go -rw-r--r-- 1.2 KiB
2a3f890dNorm MacLennan Drastically simplify .gemif story format 1 year, 1 month 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
31
32
33
34
35
36
37
package gamemanager

// Room contains information about a room and its Exits.
type Room struct {
	ID          string `yaml:"room_id" json:"room_id" binding:"uuid"`
	Name        string `yaml:"room_name" json:"room_name"`
	Description string `yaml:"room_description,omitempty" json:"room_description"`
	Exits       []Exit `yaml:"exits,omitempty" json:"exits"`
}

// Exit describes actions applied to GameState as part of leaving a Room.
type Exit struct {
	Description    string `yaml:"exit_description" json:"exit_description"`
	Destination    string `yaml:"destination_id" json:"destination_id" binding:"uuid"`
	SetCondition   string `yaml:"set_condition,omitempty" json:"set_condition"`
	IfCondition    string `yaml:"if_condition,omitempty" json:"if_condition"`
	NotCondition   string `yaml:"not_condition,omitempty" json:"not_condition"`
	UnsetCondition string `yaml:"unset_condition,omitempty" json:"unset_condition"`
}

func (r Room) filterExits(gameState GameState) []Exit {
	usableExits := []Exit{}

	for _, e := range r.Exits {
		if e.IfCondition != "" && !gameState.ConditionMet(e.IfCondition) {
			continue
		}

		if e.NotCondition != "" && gameState.ConditionMet(e.NotCondition) {
			continue
		}

		usableExits = append(usableExits, e)
	}

	return usableExits
}