aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-24 18:46:18 -0400
committerhistoria <[not public]>2026-09-24 18:46:18 -0400
commitf606db40c3290fd9ce40b53ef9bbe135b1e6f6e2 (patch)
treec2d70d17d748ecb9da1123d229006498ae050dae
parent91b466b6923d3eb1df1658199960fe7aa6db36dc (diff)
downloadthehouseoficarus-f606db40c3290fd9ce40b53ef9bbe135b1e6f6e2.tar.gz
fix: tiny map alignment broke with certain characters
-rw-r--r--internal/game/cmd_look.go4
-rw-r--r--internal/game/look_alignment_test.go48
2 files changed, 50 insertions, 2 deletions
diff --git a/internal/game/cmd_look.go b/internal/game/cmd_look.go
index 3e0bbc4..f01b83c 100644
--- a/internal/game/cmd_look.go
+++ b/internal/game/cmd_look.go
@@ -152,11 +152,11 @@ func (g *Game) writeLookSideBySide(sess *net.Session, p *player.Player, contentL
if leftMap {
sess.WriteLine(fmt.Sprintf("%s %s", mapLine, content))
} else {
- pad := mapWidth + (len(content) - visibleLen(content))
+ pad := mapWidth - visibleLen(content)
if pad < 0 {
pad = 0
}
- sess.WriteLine(fmt.Sprintf("%-*s %s", pad, content, mapLine))
+ sess.WriteLine(content + strings.Repeat(" ", pad) + " " + mapLine)
}
} else {
sess.WriteLine(content)
diff --git a/internal/game/look_alignment_test.go b/internal/game/look_alignment_test.go
new file mode 100644
index 0000000..42af09a
--- /dev/null
+++ b/internal/game/look_alignment_test.go
@@ -0,0 +1,48 @@
+package game
+
+import (
+ "strings"
+ "testing"
+
+ "thehouseoficarus/internal/color"
+ "thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/player"
+)
+
+func TestLookMiniMapAlignment(t *testing.T) {
+ for _, side := range []string{"right", "left"} {
+ for _, colored := range []bool{false, true} {
+ t.Run(side+map[bool]string{false: "/plain", true: "/colored"}[colored], func(t *testing.T) {
+ p := player.New("alice")
+ p.Options = map[string]any{"tiny_map": side, "wrap_width": 80}
+ conn := &casinoTestConn{}
+ sess := &net.Session{Player: p, Conn: conn}
+ content := wrapText("A ceiling of tiny brass suns hangs over polished stone. Icarus Leisure’s emblem repeats on every column. Stairs and galleries are open to all visitors.", 71)
+ if colored {
+ for i := range content {
+ content[i] = color.Render("xterm256", color.ColorSpec{Fg: 42, Bg: -1}, content[i])
+ }
+ }
+ mapLines := []string{"╔═════╗", "║□-□-□║", "║ ↑ ║", "║ @ ║", "║ │ ║", "║ ■ ║", "╚═════╝"}
+ (&Game{}).writeLookSideBySide(sess, p, content, mapLines, 71)
+ lines := strings.Split(strings.TrimSuffix(string(conn.data), "\r\n"), "\r\n")
+ if len(lines) != len(mapLines) {
+ t.Fatalf("got %d lines, want %d: %q", len(lines), len(mapLines), conn.data)
+ }
+ for i, line := range lines {
+ index := strings.Index(line, mapLines[i])
+ if index < 0 {
+ t.Fatalf("line %d missing map row: %q", i, line)
+ }
+ want := 73
+ if side == "left" {
+ want = 0
+ }
+ if got := visibleLen(line[:index]); got != want {
+ t.Errorf("line %d: map column = %d, want %d", i, got, want)
+ }
+ }
+ })
+ }
+ }
+}