aboutsummaryrefslogtreecommitdiff
path: root/internal/admin
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-07-07 17:04:00 -0400
committerhistoria <[not public]>2026-07-07 17:04:00 -0400
commitbae42946d24bd533cdbc1b271ce14acd752689d0 (patch)
treefee984aead607deb7ba14e8736ff2cda942b9642 /internal/admin
parent726997d799edc388cd448e978d5bb0755aaa551c (diff)
downloadthehouseoficarus-bae42946d24bd533cdbc1b271ce14acd752689d0.tar.gz
feat: standardize new room names to Room #<id>
Diffstat (limited to 'internal/admin')
-rw-r--r--internal/admin/api_room_insert_remove.go10
-rw-r--r--internal/admin/api_room_insert_remove_test.go9
-rw-r--r--internal/admin/api_rooms.go5
-rw-r--r--internal/admin/static/map.js2
4 files changed, 15 insertions, 11 deletions
diff --git a/internal/admin/api_room_insert_remove.go b/internal/admin/api_room_insert_remove.go
index c5ed54a..8549d76 100644
--- a/internal/admin/api_room_insert_remove.go
+++ b/internal/admin/api_room_insert_remove.go
@@ -66,11 +66,6 @@ func (s *AdminServer) handleRoomInsert(w http.ResponseWriter, r *http.Request) {
return
}
- name := strings.TrimSpace(body.Name)
- if name == "" {
- name = "New Room"
- }
-
aPath, aPathOK := s.world.GetRoomPath(aID)
if !aPathOK {
writeJSONError(w, fmt.Sprintf("could not find the file for room #%d", aID), http.StatusInternalServerError)
@@ -83,6 +78,11 @@ func (s *AdminServer) handleRoomInsert(w http.ResponseWriter, r *http.Request) {
return
}
+ name := strings.TrimSpace(body.Name)
+ if name == "" {
+ name = fmt.Sprintf("Room #%d", newID)
+ }
+
// Grid-conflict check on a hypothetical post-insert world.
conflicts := world.InsertGridConflicts(aID, dir, bID, newID, func(id int) (*world.Room, bool) {
r, err := s.world.LoadRoom(id)
diff --git a/internal/admin/api_room_insert_remove_test.go b/internal/admin/api_room_insert_remove_test.go
index 4f04a99..5a3b28e 100644
--- a/internal/admin/api_room_insert_remove_test.go
+++ b/internal/admin/api_room_insert_remove_test.go
@@ -2,6 +2,7 @@ package admin
import (
"encoding/json"
+ "fmt"
"net/http"
"net/http/httptest"
"os"
@@ -153,7 +154,7 @@ func TestInsertSuccess(t *testing.T) {
}
}
-// TestInsertDefaultName confirms an empty name falls back to "New Room".
+// TestInsertDefaultName confirms an empty name falls back to "Room #<id>".
func TestInsertDefaultName(t *testing.T) {
s := newTestAdminServer(t, map[int]string{
1: "name: A\nexits:\n east: 2\n",
@@ -163,8 +164,10 @@ func TestInsertDefaultName(t *testing.T) {
if code != http.StatusOK {
t.Fatalf("insert: expected 200, got %d: %v", code, resp)
}
- if resp["room"].(map[string]any)["name"] != "New Room" {
- t.Errorf("insert: expected default name 'New Room', got %v", resp["room"].(map[string]any)["name"])
+ newID := int(resp["room"].(map[string]any)["id"].(float64))
+ expectedName := fmt.Sprintf("Room #%d", newID)
+ if resp["room"].(map[string]any)["name"] != expectedName {
+ t.Errorf("insert: expected default name %q, got %v", expectedName, resp["room"].(map[string]any)["name"])
}
}
diff --git a/internal/admin/api_rooms.go b/internal/admin/api_rooms.go
index 8b4a28f..49a6601 100644
--- a/internal/admin/api_rooms.go
+++ b/internal/admin/api_rooms.go
@@ -1016,8 +1016,9 @@ func (s *AdminServer) handleCreateEmptyRoom(w http.ResponseWriter, r *http.Reque
}
path := filepath.Join(targetDir, strconv.Itoa(id)+".yaml")
+ roomName := fmt.Sprintf("Room #%d", id)
m := map[string]any{
- "name": "New Room",
+ "name": roomName,
"description": "An empty room.",
}
newContent, writeErr := writeMapAsYAML(path, m)
@@ -1032,5 +1033,5 @@ func (s *AdminServer) handleCreateEmptyRoom(w http.ResponseWriter, r *http.Reque
NewContent: newContent,
IsCreate: true,
})
- writeJSON(w, map[string]any{"room": map[string]any{"id": id, "name": "New Room"}})
+ writeJSON(w, map[string]any{"room": map[string]any{"id": id, "name": roomName}})
}
diff --git a/internal/admin/static/map.js b/internal/admin/static/map.js
index 9044286..9974b2c 100644
--- a/internal/admin/static/map.js
+++ b/internal/admin/static/map.js
@@ -2169,7 +2169,7 @@ function dirLabel(d) {
// insertRoom calls the admin insert endpoint to push a new room into id's dir
// exit, then refreshes the map and selects the new room. The backend fills in
-// the default name ("New Room") when none is supplied.
+// the default name ("Room #<id>") when none is supplied.
function insertRoom(fromID, dir) {
API.post('/api/rooms/insert', { from: fromID, dir: dir, name: '' }).then(function(r) {
var nid = r && r.room && r.room.id;