aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_map.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-30 02:17:22 -0400
committerhistoria <[not public]>2026-06-30 02:17:22 -0400
commit7a4b91304061777e7b3365b505d1e74878043d35 (patch)
tree4440b95c6ed4425f19919a4e74890607d008feec /internal/admin/api_map.go
parent069d3c1c81d71042706372df153254487a765dfc (diff)
downloadthehouseoficarus-7a4b91304061777e7b3365b505d1e74878043d35.tar.gz
feat: web gui mapping and obj/item/mob placement improvements
Diffstat (limited to 'internal/admin/api_map.go')
-rw-r--r--internal/admin/api_map.go81
1 files changed, 76 insertions, 5 deletions
diff --git a/internal/admin/api_map.go b/internal/admin/api_map.go
index 1520279..5de41a7 100644
--- a/internal/admin/api_map.go
+++ b/internal/admin/api_map.go
@@ -162,11 +162,13 @@ func (s *AdminServer) handleMap(w http.ResponseWriter, r *http.Request) {
}
writeJSON(w, map[string]any{
- "rooms": rooms,
- "links": links,
- "upLinks": upLinks,
- "downLinks": downLinks,
- "dir": getRoomDir(s, seed),
+ "rooms": rooms,
+ "links": links,
+ "upLinks": upLinks,
+ "downLinks": downLinks,
+ "dir": getRoomDir(s, seed),
+ "seed": seed,
+ "disconnected": findDisconnectedRooms(s, dir, seed, g),
"bounds": map[string]int{
"minX": minX,
"maxX": maxX,
@@ -222,6 +224,75 @@ func findLowestRoom(dir string) (int, bool) {
return lowest, found
}
+func findDisconnectedRooms(s *AdminServer, dir string, seed int, g world.RoomGrid) []map[string]any {
+ var result []map[string]any
+ scanDir := dir
+ if scanDir == "" {
+ scanDir = getRoomDir(s, seed)
+ }
+ allIDs := listRoomIDsInDir(s, scanDir)
+ for _, id := range allIDs {
+ if _, inGrid := g.Coord[id]; inGrid {
+ continue
+ }
+ room, err := s.world.LoadRoom(id)
+ if err != nil {
+ continue
+ }
+ result = append(result, map[string]any{
+ "id": id,
+ "name": room.Name,
+ })
+ }
+ return result
+}
+
+func listRoomIDsInDir(s *AdminServer, dir string) []int {
+ base := filepath.Join(s.dataDir, "rooms")
+ var dirs []string
+ if dir == "" {
+ dirs = append(dirs, base)
+ entries, err := os.ReadDir(base)
+ if err != nil {
+ return nil
+ }
+ for _, e := range entries {
+ if e.IsDir() {
+ dirs = append(dirs, filepath.Join(base, e.Name()))
+ subE, err := os.ReadDir(filepath.Join(base, e.Name()))
+ if err != nil {
+ continue
+ }
+ for _, se := range subE {
+ if se.IsDir() {
+ dirs = append(dirs, filepath.Join(base, e.Name(), se.Name()))
+ }
+ }
+ }
+ }
+ } else {
+ dirs = append(dirs, filepath.Join(base, dir))
+ }
+ var ids []int
+ for _, d := range dirs {
+ entries, err := os.ReadDir(d)
+ if err != nil {
+ continue
+ }
+ for _, e := range entries {
+ if e.IsDir() || filepath.Ext(e.Name()) != ".yaml" {
+ continue
+ }
+ id, err := strconv.Atoi(e.Name()[:len(e.Name())-5])
+ if err != nil {
+ continue
+ }
+ ids = append(ids, id)
+ }
+ }
+ return ids
+}
+
func (s *AdminServer) handleNextRoomID(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, `{"error":"method not allowed"}`, http.StatusMethodNotAllowed)