From 8ee8982b8759bcae116647cc993867f4c8b0a6ce Mon Sep 17 00:00:00 2001 From: workhorse Date: Fri, 19 Jun 2026 20:24:52 -0400 Subject: reorganized items, objects, and rooms in directories. oranized module names. added startup checks. --- internal/world/mob.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'internal/world/mob.go') diff --git a/internal/world/mob.go b/internal/world/mob.go index f7988ce..9d07532 100644 --- a/internal/world/mob.go +++ b/internal/world/mob.go @@ -144,6 +144,7 @@ func (m *MobInstance) StartRegen() { type MobStore struct { dataDir string mu sync.Mutex + pathIndex map[string]string defs map[string]*MobDef instances map[string]*MobInstance } @@ -151,6 +152,7 @@ type MobStore struct { func NewMobStore(dataDir string) *MobStore { return &MobStore{ dataDir: dataDir, + pathIndex: action.BuildPathIndex(filepath.Join(dataDir, "mobs")), defs: make(map[string]*MobDef), instances: make(map[string]*MobInstance), } @@ -164,7 +166,10 @@ func (s *MobStore) LoadDef(id string) (*MobDef, error) { } s.mu.Unlock() - path := filepath.Join(s.dataDir, "mobs", id+".yaml") + path, ok := s.pathIndex[id] + if !ok { + return nil, fmt.Errorf("read mob %s: no such mob", id) + } data, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("read mob %s: %w", id, err) @@ -180,6 +185,14 @@ func (s *MobStore) LoadDef(id string) (*MobDef, error) { return &def, nil } +func (s *MobStore) AllDefIDs() map[string]bool { + ids := make(map[string]bool) + for id := range s.pathIndex { + ids[id] = true + } + return ids +} + func (s *MobStore) GetInstance(id string) *MobInstance { s.mu.Lock() defer s.mu.Unlock() -- cgit v1.2.3