'use strict'; // t1203: on narrow / portrait screens the opponent minis shrink so they all // fit above the player's field; only if even the minimum size does not fit, // defeated opponents are sorted to the back (stable). const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const L = require('../src/miniLayout.js'); const hudFor = (vh) => Math.max(56, Math.round(vh * 0.09)); const plan = (vw, vh, n) => L.plan(vw, vh, n, hudFor(vh), Math.max(6, Math.round(Math.min(vw, vh) * 0.015))); function noOverlap (ps) { for (let i = 0; i < ps.length; i++) for (let j = i + 1; j < ps.length; j++) { const a = ps[i], b = ps[j]; const sep = a.x + a.w <= b.x || b.x + b.w <= a.x || a.y + a.h <= b.y || b.y + b.h <= a.y; if (!sep) return false; } return true; } describe('Top-row mini scaling (t1203)', () => { it('constants: 80 px max, 32 px min canvas width, 9 px min label font', () => { assert.equal(L.TOP_MAX_W, 80); assert.equal(L.TOP_MIN_W, 32); assert.equal(L.TOP_FONT_MIN, 9); const m = L.topMiniForWidth(10); assert.equal(m.w, 32); assert.equal(m.h, Math.round(32 * 1.3)); assert.ok(m.font >= 9); }); for (const [vw, vh] of [[412, 915], [360, 800], [460, 900], [390, 844]]) { for (const n of [6, 7, 8, 10, 12, 16]) { it(`${vw}x${vh}, ${n} opponents: all fit above the field, inside the screen, no overlap`, () => { const p = plan(vw, vh, n); assert.equal(p.mode, 'top'); assert.equal(p.mini.fits, true); assert.equal(p.positions.length, n); for (const q of p.positions) { assert.ok(q.aboveField, `slot ${q.slot} bottom ${q.y + q.h} <= field top ${p.fieldY}`); assert.ok(q.x >= 0 && q.x + q.w <= vw, `slot ${q.slot} inside the screen`); assert.ok(q.y >= p.hudH, 'below the HUD'); } assert.ok(noOverlap(p.positions)); assert.ok(p.mini.w >= L.TOP_MIN_W && p.mini.w <= L.TOP_MAX_W); }); } } it('few opponents keep the full size; more opponents shrink monotonically', () => { assert.equal(plan(412, 915, 3).mini.w, 80); let prev = Infinity; for (const n of [3, 6, 12, 16, 20]) { const w = plan(412, 915, n).mini.w; assert.ok(w <= prev, n + ': ' + w); prev = w; } }); it("Tim's case: 6 bots at ~460 px portrait no longer spill behind the field", () => { const p = plan(460, 900, 6); assert.ok(p.positions.every((q) => q.aboveField)); }); it('order is unchanged while everything fits, even with defeated opponents', () => { const p = plan(412, 915, 6); const elim = [true, false, true, false, false, false]; const pos = L.topPositions(elim, p); assert.deepEqual(pos.map((q) => q.slot), [0, 1, 2, 3, 4, 5]); }); it('when they do not fit even at the minimum: living first, defeated last, stable', () => { assert.deepEqual(L.topSlots([true, false, true, false, false], false), [3, 0, 4, 1, 2]); assert.deepEqual(L.topSlots([false, false, false], false), [0, 1, 2]); assert.deepEqual(L.topSlots([true, true], false), [0, 1]); }); it('overflow at 360x800 with 31 opponents: min size, defeated ones are the ones behind the field', () => { const n = 31; const p = plan(360, 800, n); assert.equal(p.mini.fits, false); assert.equal(p.mini.w, L.TOP_MIN_W); const cap = p.mini.capacity; assert.ok(cap > 0 && cap < n); const elim = Array.from({ length: n }, (_, i) => i % 3 === 0); // 11 defeated const alive = elim.filter((e) => !e).length; assert.ok(alive <= cap, 'all living fit'); const pos = L.topPositions(elim, p); for (const q of pos) { if (!q.eliminated) assert.ok(q.aboveField, 'living opponent ' + q.index + ' visible'); } const hidden = pos.filter((q) => !q.aboveField); assert.ok(hidden.length > 0 && hidden.every((q) => q.eliminated), 'only defeated ones fall behind'); // stable within groups const aliveSlots = pos.filter((q) => !q.eliminated).map((q) => q.slot); assert.deepEqual(aliveSlots, [...aliveSlots].sort((a, b) => a - b)); const elimSlots = pos.filter((q) => q.eliminated).map((q) => q.slot); assert.deepEqual(elimSlots, [...elimSlots].sort((a, b) => a - b)); }); it('wide screens still use the side layout (unchanged)', () => { assert.equal(plan(1280, 900, 6).mode, 'sides'); }); });