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/object/store.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'internal/object/store.go') diff --git a/internal/object/store.go b/internal/object/store.go index a884601..a11ff7a 100644 --- a/internal/object/store.go +++ b/internal/object/store.go @@ -5,18 +5,21 @@ import ( "os" "path/filepath" + "thehouseoficarus/internal/action" "gopkg.in/yaml.v3" ) type ObjectStore struct { - dataDir string - cache map[string]*ObjectDef + dataDir string + pathIndex map[string]string + cache map[string]*ObjectDef } func NewObjectStore(dataDir string) *ObjectStore { return &ObjectStore{ - dataDir: dataDir, - cache: make(map[string]*ObjectDef), + dataDir: dataDir, + pathIndex: action.BuildPathIndex(filepath.Join(dataDir, "objects")), + cache: make(map[string]*ObjectDef), } } @@ -24,7 +27,10 @@ func (s *ObjectStore) Load(id string) (*ObjectDef, error) { if def, ok := s.cache[id]; ok { return def, nil } - path := filepath.Join(s.dataDir, "objects", fmt.Sprintf("%s.yaml", id)) + path, ok := s.pathIndex[id] + if !ok { + return nil, fmt.Errorf("read object %s: no such object", id) + } data, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("read object %s: %w", id, err) @@ -36,3 +42,15 @@ func (s *ObjectStore) Load(id string) (*ObjectDef, error) { s.cache[id] = &def return &def, nil } + +func (s *ObjectStore) PathIndex() map[string]string { + return s.pathIndex +} + +func (s *ObjectStore) IDSet() map[string]bool { + ids := make(map[string]bool) + for id := range s.pathIndex { + ids[id] = true + } + return ids +} -- cgit v1.2.3