aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_look.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-11 19:24:25 -0400
committerhistoria <[not public]>2026-06-11 19:24:25 -0400
commit6b2b4bf470b655f01c5a21c5f558a6102402c214 (patch)
tree10970b523999b87ea09c63486906f0c5314f3542 /internal/game/cmd_look.go
parent1b9e2da3b3c438d8dc53d3489725dd5ba0022777 (diff)
downloadthehouseoficarus-6b2b4bf470b655f01c5a21c5f558a6102402c214.tar.gz
feat: map implemented with BFS
Diffstat (limited to 'internal/game/cmd_look.go')
-rw-r--r--internal/game/cmd_look.go58
1 files changed, 57 insertions, 1 deletions
diff --git a/internal/game/cmd_look.go b/internal/game/cmd_look.go
index 48b7daf..0bec915 100644
--- a/internal/game/cmd_look.go
+++ b/internal/game/cmd_look.go
@@ -23,9 +23,20 @@ func (g *Game) doLook(sess *net.Session) {
sess.WriteLines(
"",
room.Name,
- room.Description,
)
+ if p.Toggles["tinymap"] && g.MapWidth > 0 {
+ descLines := wrapText(room.Description, g.MapWidth)
+ mapLines := buildTinyMap(g, p.RoomID)
+ if len(mapLines) == 7 {
+ g.writeLookSideBySide(sess, p, descLines, mapLines)
+ } else {
+ sess.WriteLine(room.Description)
+ }
+ } else {
+ sess.WriteLine(room.Description)
+ }
+
mobs := g.MobStore.MobsInRoom(p.RoomID)
if len(mobs) > 0 {
sort.Slice(mobs, func(i, j int) bool {
@@ -486,3 +497,48 @@ func mobInstanceIdx(mob *world.MobInstance, roomMobs []*world.MobInstance) int {
}
return 0
}
+
+func wrapText(text string, width int) []string {
+ if width <= 0 {
+ return []string{text}
+ }
+ words := strings.Fields(text)
+ if len(words) == 0 {
+ return nil
+ }
+ var lines []string
+ current := words[0]
+ for _, word := range words[1:] {
+ if len(current)+1+len(word) <= width {
+ current += " " + word
+ } else {
+ lines = append(lines, current)
+ current = word
+ }
+ }
+ lines = append(lines, current)
+ return lines
+}
+
+func (g *Game) writeLookSideBySide(sess *net.Session, p *player.Player, descLines []string, mapLines []string) {
+ total := len(descLines)
+ if len(mapLines) > total {
+ total = len(mapLines)
+ }
+ leftMap := p.Toggles["left-tinymap"]
+ for i := 0; i < total; i++ {
+ desc := ""
+ if i < len(descLines) {
+ desc = descLines[i]
+ }
+ mapLine := ""
+ if i < len(mapLines) {
+ mapLine = mapLines[i]
+ }
+ if leftMap {
+ sess.WriteLine(fmt.Sprintf("%s %s", mapLine, desc))
+ } else {
+ sess.WriteLine(fmt.Sprintf("%-*s %s", g.MapWidth, desc, mapLine))
+ }
+ }
+}