aboutsummaryrefslogtreecommitdiff
path: root/internal/object/store.go
diff options
context:
space:
mode:
authorworkhorse <workhorse@localhost.localdomain>2026-06-19 20:24:52 -0400
committerworkhorse <workhorse@localhost.localdomain>2026-06-19 20:24:52 -0400
commit8ee8982b8759bcae116647cc993867f4c8b0a6ce (patch)
treeee01f7b1d745cbc94d9981108a1209527487b3e5 /internal/object/store.go
parent2bec24859af8f03c80a0a58e3240519942450167 (diff)
downloadthehouseoficarus-8ee8982b8759bcae116647cc993867f4c8b0a6ce.tar.gz
reorganized items, objects, and rooms in directories. oranized module names. added startup checks.
Diffstat (limited to 'internal/object/store.go')
-rw-r--r--internal/object/store.go28
1 files changed, 23 insertions, 5 deletions
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
+}