aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_map.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-30 19:27:37 -0400
committerhistoria <[not public]>2026-06-30 19:27:37 -0400
commitfee376102192dc6f24297a7b11324636ace3a07d (patch)
tree6c777cc71208b429eebdbdc5864b353d4af34a09 /internal/admin/api_map.go
parent98bdef072c843fdd8ccdf85a9b54ab9d32d34187 (diff)
downloadthehouseoficarus-fee376102192dc6f24297a7b11324636ace3a07d.tar.gz
feat: admin gui object CRUD is much nicer
Diffstat (limited to 'internal/admin/api_map.go')
-rw-r--r--internal/admin/api_map.go31
1 files changed, 17 insertions, 14 deletions
diff --git a/internal/admin/api_map.go b/internal/admin/api_map.go
index 7298f1e..561c1e8 100644
--- a/internal/admin/api_map.go
+++ b/internal/admin/api_map.go
@@ -1,9 +1,11 @@
package admin
import (
+ "log"
"net/http"
"os"
"path/filepath"
+ "sort"
"strconv"
"thehouseoficarus/internal/world"
@@ -24,8 +26,7 @@ func (s *AdminServer) handleMap(w http.ResponseWriter, r *http.Request) {
dir := r.URL.Query().Get("dir")
seed := s.cfg.StartingRoom
if dir != "" {
- base := filepath.Join(s.dataDir, "rooms", dir)
- if low, ok := findLowestRoom(base); ok {
+ if low, ok := findLowestLoadableRoom(s, dir); ok {
seed = low
}
}
@@ -33,6 +34,7 @@ func (s *AdminServer) handleMap(w http.ResponseWriter, r *http.Request) {
g := world.BuildGrid(seed, func(id int) (*world.Room, bool) {
room, err := s.world.LoadRoom(id)
if err != nil {
+ log.Printf("map: BuildGrid failed to load room %d: %v", id, err)
return nil, false
}
return room, true
@@ -196,31 +198,32 @@ func linkKey(a, b int) string {
return strconv.Itoa(b) + "-" + strconv.Itoa(a)
}
-func findLowestRoom(dir string) (int, bool) {
- entries, err := os.ReadDir(dir)
+func findLowestLoadableRoom(s *AdminServer, dir string) (int, bool) {
+ base := filepath.Join(s.dataDir, "rooms", dir)
+ entries, err := os.ReadDir(base)
if err != nil {
return 0, false
}
- lowest := 0
- found := false
+ var ids []int
for _, e := range entries {
- if e.IsDir() {
+ if e.IsDir() || filepath.Ext(e.Name()) != ".yaml" {
continue
}
name := e.Name()
- if filepath.Ext(name) != ".yaml" {
- continue
- }
id, err := strconv.Atoi(name[:len(name)-5])
if err != nil || id <= 0 {
continue
}
- if !found || id < lowest {
- lowest = id
- found = true
+ ids = append(ids, id)
+ }
+ sort.Ints(ids)
+ for _, id := range ids {
+ if _, err := s.world.LoadRoom(id); err == nil {
+ return id, true
}
+ log.Printf("map: seed candidate room %d in dir %s is not loadable, skipping", id, dir)
}
- return lowest, found
+ return 0, false
}
func findDisconnectedRooms(s *AdminServer, dir string, seed int, g world.RoomGrid) []map[string]any {