aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_room_remove.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-10-05 17:49:48 -0400
committerhistoria <[not public]>2026-10-05 17:49:48 -0400
commit7a15a5d70004b28bf2a710fa0f536af2446e5b17 (patch)
tree920705853f79bb13a65fcb2f89cee38e6f2efab8 /internal/game/cmd_room_remove.go
parentec703a39738fefb60817f5659f76f8e683f8d301 (diff)
downloadthehouseoficarus-7a15a5d70004b28bf2a710fa0f536af2446e5b17.tar.gz
fix: production multi-step recipes, drop-weight validation, journal versioning
Diffstat (limited to 'internal/game/cmd_room_remove.go')
-rw-r--r--internal/game/cmd_room_remove.go59
1 files changed, 3 insertions, 56 deletions
diff --git a/internal/game/cmd_room_remove.go b/internal/game/cmd_room_remove.go
index 79b84d8..c84e747 100644
--- a/internal/game/cmd_room_remove.go
+++ b/internal/game/cmd_room_remove.go
@@ -2,11 +2,6 @@ package game
import (
"fmt"
- "os"
- "path/filepath"
- "regexp"
- "strconv"
- "strings"
"gopkg.in/yaml.v3"
"thehouseoficarus/internal/net"
@@ -125,7 +120,7 @@ func (g *Game) roomRemove(sess *net.Session, args []string) {
// Guard 5: no other room points into B. The only allowed inbound edges are
// A→dir→B and C→oppositeDir→B.
- if extra := g.countExtraInbound(bID, aID, cID, dir, oppositeDir); extra > 0 {
+ if extra := world.CountExtraInbound(g.DataDir, bID, aID, cID, dir, oppositeDir); extra > 0 {
sess.WriteLine(fmt.Sprintf(
"Cannot remove: %d other exit(s) point into %s (it was modified since insertion).",
extra, bName))
@@ -244,53 +239,5 @@ func (g *Game) roomRemove(sess *net.Session, args []string) {
g.doLook(sess)
}
-// countExtraInbound returns the number of exits in rooms OTHER than A and C
-// that point into B, plus any A/C exits to B other than the expected
-// (A→dir→B, C→oppositeDir→B). A nonzero result means B has been modified since
-// it was inserted and the remove would silently orphan edges. It walks
-// data/rooms/ and matches \b<id>\b against raw file contents to skip rooms
-// that don't mention bID at all, then unmarshals the matching files.
-func (g *Game) countExtraInbound(bID, aID, cID int, dir, oppositeDir world.ExitDir) int {
- roomsDir := filepath.Join(g.DataDir, "rooms")
- re := regexp.MustCompile(fmt.Sprintf(`\b%d\b`, bID))
- var extra int
- _ = filepath.WalkDir(roomsDir, func(path string, d os.DirEntry, err error) error {
- if err != nil || d.IsDir() || filepath.Ext(path) != ".yaml" {
- return nil
- }
- data, rerr := os.ReadFile(path)
- if rerr != nil {
- return nil
- }
- if !re.MatchString(string(data)) {
- return nil
- }
- idStr := strings.TrimSuffix(filepath.Base(path), ".yaml")
- rid, serr := strconv.Atoi(idStr)
- if serr != nil || rid == bID {
- return nil
- }
- var room world.Room
- if yerr := yaml.Unmarshal(data, &room); yerr != nil {
- return nil
- }
- if room.Exits == nil {
- return nil
- }
- for ed, exitDef := range room.Exits {
- if exitDef.Room != bID {
- continue
- }
- // Allowed: A→dir→B and C→oppositeDir→B.
- if rid == aID && ed == dir {
- continue
- }
- if rid == cID && ed == oppositeDir {
- continue
- }
- extra++
- }
- return nil
- })
- return extra
-}
+// countExtraInbound was moved to world.CountExtraInbound so the in-game and
+// admin removal paths share one implementation.