aboutsummaryrefslogtreecommitdiff
path: root/internal/game/flagstore.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/flagstore.go')
-rw-r--r--internal/game/flagstore.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/game/flagstore.go b/internal/game/flagstore.go
new file mode 100644
index 0000000..2790d89
--- /dev/null
+++ b/internal/game/flagstore.go
@@ -0,0 +1,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)
+}