aboutsummaryrefslogtreecommitdiff
path: root/internal/world/mob.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/world/mob.go')
-rw-r--r--internal/world/mob.go15
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()