blob: 2790d8912f48eb5ffaa4e621cf6257025f0ac8fc (
plain)
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
38
39
40
41
42
|
package game
import "sync"
// FlagStore holds world flags — shared mutable state visible to all players
// (e.g. opened doors, quest state). Player-specific flags live on
// *player.Player.Flags instead. FlagStore is safe for concurrent use.
type FlagStore struct {
mu sync.Mutex
flags map[string]any
}
func NewFlagStore() *FlagStore {
return &FlagStore{flags: make(map[string]any)}
}
func (f *FlagStore) Get(name string) (any, bool) {
f.mu.Lock()
defer f.mu.Unlock()
v, ok := f.flags[name]
return v, ok
}
func (f *FlagStore) Set(name string, value any) {
f.mu.Lock()
defer f.mu.Unlock()
f.flags[name] = value
}
func (f *FlagStore) SetAll(m map[string]any) {
f.mu.Lock()
defer f.mu.Unlock()
for k, v := range m {
f.flags[k] = v
}
}
func (f *FlagStore) Delete(name string) {
f.mu.Lock()
defer f.mu.Unlock()
delete(f.flags, name)
}
|