Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

const { style } = require('bare-tui')
const { makeMovingHeroSprite } = require('./sprites.js')
const { isSolid } = require('./map.js')
const { WORLD_BOSS } = require('./world-boss.js')
const { bossCamera } = require('./world-boss-event.js')

Expand Down Expand Up @@ -861,7 +862,10 @@ function mapPane(map, w, h, opts = {}) {
while (last > first && line[last] === ' ') last--
for (let sx = first; sx <= last; sx++) {
if (line[sx] === ' ') continue
const cell = top + sy + ',' + (left + sx)
const wx = left + sx
const wy = top + sy
if (isSolid({ rows: tiles, width: mapW, height: mapH }, wx, wy)) continue
Comment thread
gitar-bot[bot] marked this conversation as resolved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Edge Case: Displaced actors in mapPane are not wall-checked and may clip walls

The new displacement logic (lines 775-801) reassigns drawX for any actor within 2 tiles of the hero (Chebyshev distance), even when the sprites do not actually overlap, and the subsequent draw loop (lines 829-842) never calls isSolid the way the hero loop does at line 867. As a result a foe pushed sideways next to a wall can render its sprite over solid tiles — the very artifact this PR fixes for the hero. Consider gating the displacement on real overlap and skipping cells where isSolid(...) is true, mirroring the hero loop.

Was this helpful? React with 👍 / 👎

const cell = wy + ',' + wx
over.set(cell, line[sx])
heroCells.add(cell)
}
Expand Down Expand Up @@ -1396,7 +1400,6 @@ function compose(opts) {
function mapScreen(m) {
const tiles = (m.map && m.map.tiles) || []
const cellW = Math.max(1, m.cellW || CELL_W)
const mapW = tiles.reduce((widest, line) => Math.max(widest, String(line).length), 0) * cellW
// Large maps scroll inside the pane. Requiring the entire map to fit would
// hide the character sheet forever as soon as a world grew beyond one view.
const sidebar = m.sidebar === undefined ? m.width >= 64 : m.sidebar
Expand Down
22 changes: 22 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,28 @@ test('the shop lets the player equip and remove owned gear', (t) => {
t.is(game.player.snapshot().equipped.left, 'sword', 'enter equips an item already owned')
})

test('hero sprites do not overwrite solid wall tiles', (t) => {
const sprite = render.heroSprite({ frame: 0 })
const tiles = Array(5).fill(','.repeat(12))
tiles[1] = ',,,,#,,,,,,,'
const city = style
.stripAnsi(
render.mapPane(
{
tiles,
hero: { x: 4, y: 3, sprite },
actors: []
},
12,
5,
{ cellW: 1 }
)
)
.split('\n')

t.is(city[1][4], '#', 'the wall remains visible through the hero sprite')
})

test('spaces inside actor sprites are transparent over city and field terrain', (t) => {
const sprite = render.heroSprite({ frame: 0 })
const city = style
Expand Down