diff options
| author | workhorse <workhorse@localhost.localdomain> | 2026-06-19 20:24:52 -0400 |
|---|---|---|
| committer | workhorse <workhorse@localhost.localdomain> | 2026-06-19 20:24:52 -0400 |
| commit | 8ee8982b8759bcae116647cc993867f4c8b0a6ce (patch) | |
| tree | ee01f7b1d745cbc94d9981108a1209527487b3e5 /internal/world/mob.go | |
| parent | 2bec24859af8f03c80a0a58e3240519942450167 (diff) | |
| download | thehouseoficarus-8ee8982b8759bcae116647cc993867f4c8b0a6ce.tar.gz | |
reorganized items, objects, and rooms in directories. oranized module names. added startup checks.
Diffstat (limited to 'internal/world/mob.go')
| -rw-r--r-- | internal/world/mob.go | 15 |
1 files changed, 14 insertions, 1 deletions
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() |
