// ── A backpack as a grid (PLAN_REDESIGNS §11.3.2) ───────────────────────── // // The grid is drawn from these, so each test is a backpack that could be drawn // wrong: a two-page one, one with overflow past its capacity, one that never // existed, and the labels a slot can carry (D340, D341). import test from 'node:test' import assert from 'node:assert/strict' import { backpackPages, overflowCount, stackLabel } from '../src/lib/backpack.js' test('a backpack that does not exist is no pages', () => { assert.deepEqual(backpackPages(null), []) assert.deepEqual(backpackPages({ exists: false }), []) }) test('slots run across pages of the page size', () => { const pages = backpackPages({ exists: true, capacity: 96, pageSize: 48, items: [{ slot: 0, shortname: 'wood', amount: 1000 }, { slot: 50, shortname: 'note', amount: 1 }], }) assert.equal(pages.length, 2) assert.equal(pages[0].cells.length, 48) assert.equal(pages[1].cells.length, 48) assert.equal(pages[0].cells[0].stack.shortname, 'wood') assert.equal(pages[1].cells[2].slot, 50) assert.equal(pages[1].cells[2].stack.shortname, 'note') assert.ok(pages.every((p) => p.cells.every((c) => !c.overflow))) }) test('stacks past the capacity are drawn after it, marked overflow', () => { // A size revoked at the end of a run: capacity 6, five notes still on what was page two. const backpack = { exists: true, capacity: 6, pageSize: 48, items: [{ slot: 0, shortname: 'wood', amount: 1 }, ...[48, 49, 50, 51, 52].map((slot) => ({ slot, shortname: 'note', amount: 1, overflow: true }))], } const pages = backpackPages(backpack) assert.equal(pages.length, 2) assert.equal(pages[0].cells.slice(0, 6).filter((c) => c.overflow).length, 0) assert.ok(pages[0].cells.slice(6).every((c) => c.overflow)) assert.equal(pages[1].cells.length, 5) assert.equal(overflowCount(backpack), 5) }) test('an empty backpack still draws its capacity', () => { const pages = backpackPages({ exists: true, capacity: 12, pageSize: 48, items: [] }) assert.equal(pages.length, 1) assert.equal(pages[0].cells.length, 12) assert.ok(pages[0].cells.every((c) => c.stack === null)) }) test('a slot is named by the game, a blueprint by what it makes', () => { assert.equal(stackLabel({ shortname: 'rifle.ak', display: 'Assault Rifle' }), 'Assault Rifle') assert.equal(stackLabel({ shortname: 'blueprintbase', display: 'Assault Rifle', blueprint: 'rifle.ak' }), 'Assault Rifle blueprint') assert.equal(stackLabel({ shortname: 'wood' }), 'wood') assert.equal(stackLabel({ shortname: null, itemId: 999 }), 'item 999') assert.equal(stackLabel(null), '') })