aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-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
-rw-r--r--internal/game/cmd_dig.go2
-rw-r--r--internal/game/cmd_room_insert.go14
6 files changed, 23 insertions, 19 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;
diff --git a/internal/game/cmd_dig.go b/internal/game/cmd_dig.go
index 807f424..e3bc2b5 100644
--- a/internal/game/cmd_dig.go
+++ b/internal/game/cmd_dig.go
@@ -138,7 +138,7 @@ func (g *Game) executeDig(sess *net.Session, args []string, rawInput string) {
if len(args) > 1 {
name = strings.Join(args[1:], " ")
} else {
- name = "New Room"
+ name = fmt.Sprintf("Room #%d", newID)
}
oppositeDir := world.OppositeExit[dir]
diff --git a/internal/game/cmd_room_insert.go b/internal/game/cmd_room_insert.go
index 713c5ee..b248e49 100644
--- a/internal/game/cmd_room_insert.go
+++ b/internal/game/cmd_room_insert.go
@@ -30,13 +30,6 @@ func (g *Game) roomInsert(sess *net.Session, args []string) {
return
}
- var name string
- if len(args) > 1 {
- name = strings.Join(args[1:], " ")
- } else {
- name = "New Room"
- }
-
curPath, ok := g.World.GetRoomPath(p.RoomID)
if !ok {
sess.WriteLine("Error: can't find current room file.")
@@ -71,6 +64,13 @@ func (g *Game) roomInsert(sess *net.Session, args []string) {
return
}
+ var name string
+ if len(args) > 1 {
+ name = strings.Join(args[1:], " ")
+ } else {
+ name = fmt.Sprintf("Room #%d", newID)
+ }
+
conflicts := world.InsertGridConflicts(p.RoomID, dir, targetID, newID, func(id int) (*world.Room, bool) {
r, err := g.World.LoadRoom(id)
if err != nil {