From ab2597b22ccdb71116992aec78080d9858358d04 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 7 Jul 2026 16:24:27 -0400 Subject: rename flags to global_flags (differentiate from player_flags) --- internal/game/core_flagstore.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'internal/game/core_flagstore.go') diff --git a/internal/game/core_flagstore.go b/internal/game/core_flagstore.go index ecefccf..18578b7 100644 --- a/internal/game/core_flagstore.go +++ b/internal/game/core_flagstore.go @@ -2,37 +2,37 @@ package game import "sync" -// FlagChangeCallback is invoked when a world flag value actually changes +// GlobalFlagChangeCallback is invoked when a global flag value actually changes // (old value differs from new, or new flag is created with a truthy value). -type FlagChangeCallback func(name string, value any) +type GlobalFlagChangeCallback func(name string, value any) -// 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 { +// GlobalFlagStore holds global flags — shared mutable state visible to all +// players (e.g. opened doors, quest state). Player-specific flags live on +// *player.Player.Flags instead. GlobalFlagStore is safe for concurrent use. +type GlobalFlagStore struct { mu sync.Mutex flags map[string]any - callbacks []FlagChangeCallback + callbacks []GlobalFlagChangeCallback } -func NewFlagStore() *FlagStore { - return &FlagStore{flags: make(map[string]any)} +func NewGlobalFlagStore() *GlobalFlagStore { + return &GlobalFlagStore{flags: make(map[string]any)} } -func (f *FlagStore) OnChange(cb FlagChangeCallback) { +func (f *GlobalFlagStore) OnChange(cb GlobalFlagChangeCallback) { f.mu.Lock() defer f.mu.Unlock() f.callbacks = append(f.callbacks, cb) } -func (f *FlagStore) Get(name string) (any, bool) { +func (f *GlobalFlagStore) 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) { +func (f *GlobalFlagStore) Set(name string, value any) { f.mu.Lock() old, existed := f.flags[name] f.flags[name] = value @@ -46,7 +46,7 @@ func (f *FlagStore) Set(name string, value any) { } } -func (f *FlagStore) SetAll(m map[string]any) { +func (f *GlobalFlagStore) SetAll(m map[string]any) { f.mu.Lock() changed := make(map[string]any) for k, v := range m { @@ -66,13 +66,13 @@ func (f *FlagStore) SetAll(m map[string]any) { } } -func (f *FlagStore) Delete(name string) { +func (f *GlobalFlagStore) Delete(name string) { f.mu.Lock() defer f.mu.Unlock() delete(f.flags, name) } -func (f *FlagStore) All() map[string]any { +func (f *GlobalFlagStore) All() map[string]any { f.mu.Lock() defer f.mu.Unlock() out := make(map[string]any, len(f.flags)) -- cgit v1.2.3