diff options
| author | historia <[not public]> | 2026-06-27 21:25:20 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-27 21:25:20 -0400 |
| commit | 87dacfbb3dd16e7f55a82361eace98f9a39d75c8 (patch) | |
| tree | d548f75a37b5b8e960c5e5d111237e172650bb59 /internal/game/object_def.go | |
| parent | 83f8f5447ec3baf85314ce7343f0e339d28bcc15 (diff) | |
| download | thehouseoficarus-87dacfbb3dd16e7f55a82361eace98f9a39d75c8.tar.gz | |
feat: room-specific objects can be defined inline in room yaml
Diffstat (limited to 'internal/game/object_def.go')
| -rw-r--r-- | internal/game/object_def.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/game/object_def.go b/internal/game/object_def.go new file mode 100644 index 0000000..e27aeb0 --- /dev/null +++ b/internal/game/object_def.go @@ -0,0 +1,33 @@ +package game + +import "thehouseoficarus/internal/object" + +// resolveObjectDef returns the ObjectDef for a room object instance. File +// objects (the common case) resolve through the cached object store with no +// disk I/O on a hit, and a store miss is just a map lookup; only inline objects +// — which never live in the store — fall through to a freshly-read room, so +// they keep live-edit semantics without slowing file-object lookups. defID is +// the ObjState DefID (a normalized name for inline objects, a file id +// otherwise). +// +// Use this from display or generic-handling sites. Sites that look up a +// specific interactable behavior (gather/use-station/safespot/steal/etc.) may +// call ObjectStore.Load directly: inline objects are guaranteed non-interactable +// and simply fall through those sites' existing error guards. +func (g *Game) resolveObjectDef(roomID int, defID string) (*object.ObjectDef, error) { + def, err := g.ObjectStore.Load(defID) + if err == nil { + return def, nil + } + if room, rerr := g.World.LoadRoom(roomID); rerr == nil { + for i := range room.Objects { + ro := &room.Objects[i] + if ro.Inline != nil && ro.ID == defID { + d := *ro.Inline + d.ID = defID + return &d, nil + } + } + } + return nil, err +} |
