aboutsummaryrefslogtreecommitdiff
path: root/internal/game/look_room.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-25 15:40:48 -0400
committerhistoria <[not public]>2026-06-25 15:40:48 -0400
commitabd612c15799f604e671e83dc7c410ed2b44185f (patch)
tree0597ca92350de73aac2a7cf26b2f2d6595dac0cc /internal/game/look_room.go
parent2725e2927a1595c7b100d942d1f14146252adeb7 (diff)
downloadthehouseoficarus-abd612c15799f604e671e83dc7c410ed2b44185f.tar.gz
slop refactor
Diffstat (limited to 'internal/game/look_room.go')
-rw-r--r--internal/game/look_room.go107
1 files changed, 107 insertions, 0 deletions
diff --git a/internal/game/look_room.go b/internal/game/look_room.go
new file mode 100644
index 0000000..8a1da04
--- /dev/null
+++ b/internal/game/look_room.go
@@ -0,0 +1,107 @@
+package game
+
+import (
+ "fmt"
+
+ "thehouseoficarus/internal/color"
+ "thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/object"
+ "thehouseoficarus/internal/player"
+ "thehouseoficarus/internal/world"
+)
+
+func (g *Game) showRoomName(sess *net.Session, p *player.Player, room *world.Room) {
+ sess.WriteLines(
+ "",
+ fmt.Sprintf("%s (%s)", g.colorize(sess, "room_name", room.Name), g.colorize(sess, "room_number", fmt.Sprintf("#%d", room.ID))),
+ )
+}
+
+func (g *Game) showRoomDescription(sess *net.Session, p *player.Player, room *world.Room) []string {
+ descWidth := p.OptionInt("room_desc_width")
+ if descWidth <= 0 {
+ descWidth = 70
+ }
+ rawLines := wrapText(g.roomDescription(sess, room), descWidth)
+ mode := g.colorMode(sess)
+ roomDescSpec := g.resolveColor(sess, "room_desc")
+ lines := make([]string, len(rawLines))
+ for i, l := range rawLines {
+ lines[i] = color.ExpandTagsDefault(mode, roomDescSpec, l)
+ }
+ return lines
+}
+
+// roomDescription resolves the room's effective description for this player,
+// picking the first conditional variant whose condition passes.
+func (g *Game) roomDescription(sess *net.Session, room *world.Room) string {
+ for _, d := range room.Description {
+ if d.Condition == nil || g.checkCondition(sess, d.Condition) {
+ return d.Text
+ }
+ }
+ return ""
+}
+
+// resolveObjDesc resolves the description an object shows to this player.
+// The first variant whose condition passes wins; if none pass the object is
+// reported as not present (false), so look falls through as if it were not there.
+func (g *Game) resolveObjDesc(sess *net.Session, def *object.ObjectDef) (string, bool) {
+ for _, d := range def.Description {
+ if d.Condition == nil || g.checkCondition(sess, d.Condition) {
+ return d.Text, true
+ }
+ }
+ return "", false
+}
+
+func (g *Game) showRoomExits(sess *net.Session, p *player.Player, room *world.Room) {
+ if len(room.Exits) > 0 {
+ sess.WriteLine("")
+ if p.OptionBool("exits") {
+ sess.WriteLine("Exits:")
+ type exitLine struct {
+ dir string
+ targetName string
+ }
+ var lines []exitLine
+ maxDirLen := 0
+ for _, dir := range world.ExitOrder {
+ exitDef, ok := room.Exits[dir]
+ if !ok {
+ continue
+ }
+ coloredDir := g.colorize(sess, "exit_direction", string(dir))
+ targetRoom, err := g.World.LoadRoom(exitDef.Room)
+ targetName := g.colorize(sess, "room_number", fmt.Sprintf("#%d", exitDef.Room))
+ if err == nil {
+ targetName = g.colorize(sess, "exit_name", targetRoom.Name)
+ }
+ if exitDef.Condition != nil && !g.checkCondition(sess, exitDef.Condition) {
+ targetName += " (blocked)"
+ }
+ lines = append(lines, exitLine{coloredDir, targetName})
+ if visibleLen(coloredDir) > maxDirLen {
+ maxDirLen = visibleLen(coloredDir)
+ }
+ }
+ for _, l := range lines {
+ pad := maxDirLen + (len(l.dir) - visibleLen(l.dir))
+ sess.WriteLine(fmt.Sprintf(" %-*s - %s", pad, l.dir, l.targetName))
+ }
+ } else {
+ sess.Write("Exits: ")
+ first := true
+ for _, dir := range world.ExitOrder {
+ if _, ok := room.Exits[dir]; ok {
+ if !first {
+ sess.Write(", ")
+ }
+ sess.Write(g.colorize(sess, "exit_direction", string(dir)))
+ first = false
+ }
+ }
+ sess.WriteLine("")
+ }
+ }
+}