aboutsummaryrefslogtreecommitdiff
path: root/internal/game/map.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-14 21:07:26 -0400
committerhistoria <[not public]>2026-06-14 21:07:26 -0400
commit1aba2bdd23aebed4032333e74aa553c40a31fcbd (patch)
treec004f4c2a139df5c3cf4029b2611bdfa09b40f86 /internal/game/map.go
parenta19e6b6ab01670a5932308c7bd0e0e5eed8cbcad (diff)
downloadthehouseoficarus-1aba2bdd23aebed4032333e74aa553c40a31fcbd.tar.gz
refactor: added docs, split up some components in game package
Diffstat (limited to 'internal/game/map.go')
-rw-r--r--internal/game/map.go102
1 files changed, 102 insertions, 0 deletions
diff --git a/internal/game/map.go b/internal/game/map.go
index cd1012b..e7738bd 100644
--- a/internal/game/map.go
+++ b/internal/game/map.go
@@ -1,6 +1,8 @@
package game
import (
+ "strings"
+
"thirdcollapse/internal/world"
)
@@ -189,3 +191,103 @@ func roomMapSymbol(g *Game, roomID int) rune {
}
return 'o'
}
+
+func stripBlankRows(lines []string) []string {
+ var out []string
+ for _, line := range lines {
+ if strings.TrimSpace(line) != "" {
+ out = append(out, line)
+ }
+ }
+ return out
+}
+
+func leftTrimCommon(lines []string) []string {
+ min := -1
+ for _, line := range lines {
+ if strings.TrimSpace(line) == "" {
+ continue
+ }
+ n := 0
+ for _, r := range line {
+ if r == ' ' {
+ n++
+ } else {
+ break
+ }
+ }
+ if min < 0 || n < min {
+ min = n
+ }
+ }
+ if min <= 0 {
+ return lines
+ }
+ result := make([]string, len(lines))
+ for i, line := range lines {
+ if len(line) <= min {
+ result[i] = ""
+ } else {
+ result[i] = line[min:]
+ }
+ }
+ return result
+}
+
+func buildFullMap(g *Game, roomID, mapWidth, mapHeight int) []string {
+ mg := buildGraph(g, roomID)
+
+ grid := make([][]rune, mapHeight)
+ for i := range grid {
+ grid[i] = make([]rune, mapWidth)
+ for j := range grid[i] {
+ grid[i][j] = ' '
+ }
+ }
+
+ cx := mapWidth / 2
+ cy := mapHeight / 2
+
+ for pos, rid := range mg.posToRoom {
+ gr := cy + pos[1]*2
+ gc := cx + pos[0]*2
+ if gr < 0 || gr >= mapHeight || gc < 0 || gc >= mapWidth {
+ continue
+ }
+ if rid == roomID {
+ grid[gr][gc] = '@'
+ } else {
+ grid[gr][gc] = roomMapSymbol(g, rid)
+ }
+ }
+
+ for pos, rid := range mg.posToRoom {
+ x, y := pos[0], pos[1]
+
+ if rightID, ok := mg.posToRoom[[2]int{x + 1, y}]; ok {
+ if exitsConnect(g, rid, rightID, world.East, world.West) {
+ gr := cy + y*2
+ gc := cx + x*2 + 1
+ if gr >= 0 && gr < mapHeight && gc >= 0 && gc < mapWidth {
+ grid[gr][gc] = '─'
+ }
+ }
+ }
+
+ if bottomID, ok := mg.posToRoom[[2]int{x, y + 1}]; ok {
+ if exitsConnect(g, rid, bottomID, world.South, world.North) {
+ gr := cy + y*2 + 1
+ gc := cx + x*2
+ if gr >= 0 && gr < mapHeight && gc >= 0 && gc < mapWidth {
+ grid[gr][gc] = '│'
+ }
+ }
+ }
+ }
+
+ lines := make([]string, mapHeight)
+ for i := range grid {
+ lines[i] = string(grid[i])
+ }
+ return lines
+}