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
13 changes: 7 additions & 6 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,13 +1314,14 @@ function compose(opts) {
* @returns {string}
*/
function mapScreen(m) {
const tiles = (m.map && m.map.tiles) || []
const cellW = Math.max(1, m.cellW || CELL_W)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Quality: Unused cellW local variable left in mapScreen

The diff removed the mapW/tiles calculation that was the only consumer of the local const cellW = Math.max(1, m.cellW || CELL_W). The map pane is rendered with mapPane(m.map, w, h, { cellW: m.cellW }), which uses m.cellW directly and ignores the local clamped value, so cellW is now dead code. Remove the line to avoid confusion (and note the clamping/CELL_W fallback no longer applies here—if that fallback was intended for the pane, pass the local cellW to mapPane instead).

Was this helpful? React with 👍 / 👎

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 usefulMapW = Math.min(mapW, 60)
const sidebar = m.sidebar === undefined ? m.width - SIDE_W - 5 >= usefulMapW : m.sidebar
// Large maps scroll inside the pane, so the character sheet never has to
// compete with the world's full width (#7). Any terminal wide enough for the
// split layout keeps the sidebar: between 64 and 90 columns the previous
// estimate `width - SIDE_W - 5 >= min(mapW, 60)` silently dropped ficha and
// log, and actions that worked then left an unchanged screen on model state
// that had clearly moved.
const sidebar = m.sidebar === undefined ? m.width >= MIN_WIDTH : m.sidebar
const stats = m.stats || {}
const compactStats =
'nv ' +
Expand Down
4 changes: 3 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
const render = require('../lib/render.js')

require('./sage.test.js')
require('./sidebar-threshold.test.js')

function press(game, name) {
return game.onKey({ type: 'key', is: (...keys) => keys.includes(name) })
Expand Down Expand Up @@ -250,7 +251,8 @@ test('the larger city scrolls inside an 80-column console', (t) => {
MAPS.city.rows.some((row) => row.includes('~~~~~~~~~~~~~~~~~~')),
'the city keeps its detailed fountain'
)
t.ok(screen.includes('hp 20/20'), 'compact stats remain visible in the title bar')
t.ok(screen.includes('ficha'), 'the character sheet stays in its sidebar (#7)')
t.ok(screen.includes('log'), 'the log panel survives narrow city terminals too (#7)')
t.ok(!screen.includes('[#]'), 'a new hero does not display an unequipped shield')
t.ok(!screen.includes('@'), 'the city no longer represents the hero with an at sign')

Expand Down
46 changes: 46 additions & 0 deletions test/sidebar-threshold.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const { test } = require('brittle')
const { style } = require('bare-tui')
const render = require('../lib/render.js')

function cityFrame(width) {
return style.stripAnsi(
render.mapScreen({
width,
height: 20,
place: 'plaza',
stats: { hp: 9, maxhp: 12, gold: 7 },
log: ['primer mensaje'],
cellW: 1,
map: {
tiles: ['........', '........', '........'],
actors: [],
hero: { x: 4, y: 1 }
}
})
)
}

test('the city keeps ficha and log from MIN_WIDTH up to the old cutoff (#7)', (t) => {
for (const width of [64, 70, 80, 90]) {
const frame = cityFrame(width)
t.ok(frame.includes('ficha'), `${width} columns show the sheet`)
t.ok(frame.includes('log'), `${width} columns show the log panel`)
t.ok(frame.includes('primer mensaje'), `${width} columns surface new model state`)
}
})

test('below MIN_WIDTH nothing pretends to fit, and an explicit opt-out still works (#7)', (t) => {
t.ok(!cityFrame(63).includes('ficha'), '63 columns stay on the too-small screen')

const wide = render.mapScreen({
width: 100,
height: 20,
place: 'plaza',
stats: {},
log: [],
sidebar: false,
cellW: 1,
map: { tiles: ['....'], actors: [], hero: { x: 0, y: 0 } }
})
t.ok(!style.stripAnsi(wide).includes('ficha'), 'sidebar:false keeps its escape-hatch meaning')
})