aboutsummaryrefslogtreecommitdiff
path: root/internal/world/world.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-19 03:15:59 -0400
committerhistoria <[not public]>2026-09-19 03:15:59 -0400
commit0e60567a7a0addb9421769ee7be7853bfa8788cb (patch)
tree7645112db0e4eae95b8a83c1e4f9aab38bede655 /internal/world/world.go
parentcc33072eced3d5460512c09c42ec4531c807d7af (diff)
downloadthehouseoficarus-0e60567a7a0addb9421769ee7be7853bfa8788cb.tar.gz
refactor: simplifcation, change how rooms are stored in player yaml, remove legacy code
Diffstat (limited to 'internal/world/world.go')
-rw-r--r--internal/world/world.go38
1 files changed, 26 insertions, 12 deletions
diff --git a/internal/world/world.go b/internal/world/world.go
index 7a91894..10ceb08 100644
--- a/internal/world/world.go
+++ b/internal/world/world.go
@@ -18,10 +18,14 @@ type World struct {
dataDir string
mu sync.Mutex
roomPathIndex map[int]string
- groundItems map[int][]*groundEntry
- seeded map[int]bool
- objStates map[string]*ObjState
- objMoves []ObjMove
+ // roomIDMismatchLogged dedupes the "declared id ignored" warning, which
+ // would otherwise fire on every prompt/tick for a room file copied from a
+ // template with a stale id:. Guarded by mu.
+ roomIDMismatchLogged map[int]bool
+ groundItems map[int][]*groundEntry
+ seeded map[int]bool
+ objStates map[string]*ObjState
+ objMoves []ObjMove
hazardMu sync.Mutex
hazardPathIndex map[string]string
@@ -30,12 +34,13 @@ type World struct {
func New(dataDir string) *World {
return &World{
- dataDir: dataDir,
- roomPathIndex: behavior.BuildRoomIndex(filepath.Join(dataDir, "rooms")),
- groundItems: make(map[int][]*groundEntry),
- seeded: make(map[int]bool),
- objStates: make(map[string]*ObjState),
- hazardDefs: make(map[string]*HazardDef),
+ dataDir: dataDir,
+ roomPathIndex: behavior.BuildRoomIndex(filepath.Join(dataDir, "rooms")),
+ roomIDMismatchLogged: make(map[int]bool),
+ groundItems: make(map[int][]*groundEntry),
+ seeded: make(map[int]bool),
+ objStates: make(map[string]*ObjState),
+ hazardDefs: make(map[string]*HazardDef),
}
}
@@ -58,8 +63,17 @@ func (w *World) LoadRoom(id int) (*Room, error) {
// declared id: is silently ignored, so surface it rather than leave the
// author believing their written id is in use.
if room.ID != 0 && room.ID != id {
- log.Printf("room %d: file %s declares id %d but is loaded as room %d; the filename is authoritative and the declared id is ignored",
- id, path, room.ID, id)
+ w.mu.Lock()
+ if w.roomIDMismatchLogged == nil {
+ w.roomIDMismatchLogged = make(map[int]bool)
+ }
+ already := w.roomIDMismatchLogged[id]
+ w.roomIDMismatchLogged[id] = true
+ w.mu.Unlock()
+ if !already {
+ log.Printf("room %d: file %s declares id %d but is loaded as room %d; the filename is authoritative and the declared id is ignored",
+ id, path, room.ID, id)
+ }
}
room.ID = id
if room.Exits == nil {