clone

a browser grid puzzle game where you push words around to rewrite the rules of each level

fix: align ledger property colors with board palette

Dami committed 1a04d70
commit
1a04d702cea64778065807e87bad5077f4deb07d
parent
136662e7c14af7d6fe427071d4366c1037ae4422
author
Dami <dami.etoile@gmail.com>
2 files changed, +38 -8
Msrc/render/stage-hud.js15+++++++++------
Mtests/stage-hud.test.js31++++++++++++++++++++++++++++--
M src/render/stage-hud.js +9 -6
M tests/stage-hud.test.js +29 -2
@@ -1,10 +1,11 @@
11 import test from 'node:test';22 import assert from 'node:assert/strict';33 import { drawInlineActions, drawLedger, drawStepCounter } from '../src/render/stage-hud.js';4+import { BOARD_COLORS } from '../src/render/board/model.js';45 56 function context() {67 const calls = [];7- return {8+ const ctx = {89 calls,910 font: '',1011 save() { calls.push(['save']); },
@@ -18,12 +19,38 @@ function context() {
1819 rect(...args) { calls.push(['rect', ...args]); },1920 clip() { calls.push(['clip']); },2021 stroke() { calls.push(['stroke']); },21- fillRect(...args) { calls.push(['fillRect', ...args]); },22+ fillRect(...args) { calls.push(['fillRect', ...args, this.fillStyle]); },2223 fillText(...args) { calls.push(['fillText', ...args]); },2324 measureText(text) { return { width: String(text).length * 6 }; },2425 };26+ Object.defineProperty(ctx, 'fillStyle', {27+ get() { return this._fillStyle; },28+ set(value) { this._fillStyle = value; },29+ });30+ return ctx;2531 }2632 33+test('drawLedger uses the board palette for every core property tile', () => {34+ const ctx = context();35+ const properties = ['YOU', 'PUSH', 'STOP', 'WIN', 'SINK', 'DEFEAT', 'TICK'];36+ const entries = properties.map((property) => ({ text: `MIAU IS ${property}` }));37+ drawLedger(38+ ctx,39+ entries,40+ 10,41+ 20,42+ 2000,43+ );44+ const tileFills = ctx.calls45+ .filter((call) => call[0] === 'fillRect' && call[5] !== '#000000')46+ .map((call) => call[5]);47+ const expected = properties.map((property) => BOARD_COLORS[property]);48+ const propertyFills = tileFills.filter((fill) => expected.includes(fill));49+ assert.equal(propertyFills.length, expected.length + 1, 'only the fallback PUSH tile adds a second core fill');50+ assert.deepEqual(propertyFills.slice(0, expected.length), expected);51+ assert.equal(propertyFills.at(-1), BOARD_COLORS.PUSH);52+});53+2754 test('drawLedger consumes physical frame entries with stamp, strike, and exit state', () => {2855 const ctx = context();2956 drawLedger(ctx, [{ text: 'MIAU IS YOU' }], 10, 20, 300, {