diff --git a/lib/render.js b/lib/render.js index caec950..17d7f26 100755 --- a/lib/render.js +++ b/lib/render.js @@ -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') @@ -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 + const cell = wy + ',' + wx over.set(cell, line[sx]) heroCells.add(cell) } @@ -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 diff --git a/test/index.js b/test/index.js index 7a13856..0ed94d6 100644 --- a/test/index.js +++ b/test/index.js @@ -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