// THE UPDATE FLASH (update-flash.mjs; operator, 11 Nov): a measure widget's outline lights at the moment its // shown value changes -- exactly that widget, exactly then -- and never on frame 0, over the intro, or on a widget's // first appearance. Off by default: a cut renders as it did. import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; import { estimateSchedule } from "./deck.mjs"; import { dialHtml, odometerHtml, trailHtml } from "./chrome-instruments.mjs"; import { dietHtml, goalsHtml, shelfGoalStates } from "./chrome-measure-extras.mjs"; import { dietStates, goalStates } from "./measure-extras.mjs"; import { measureTrack } from "./measure-draw.mjs"; import { validateMeasureSettings } from "./measure-slice.mjs"; import { validateDial } from "./instruments.mjs"; import { validateMeasureExtra } from "./modules/measure-extras-settings.mjs"; import { trailPoints } from "./trail-plan.mjs"; import { FLASH_MOTION, flashOn, flashTimes } from "./update-flash.mjs"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const DIAL = JSON.parse(readFileSync(path.join(HERE, "fixtures", "measure-dial", "measure.json"), "utf8")); const EXTRAS = JSON.parse(readFileSync(path.join(HERE, "fixtures", "measure-extras", "measure.json"), "utf8")); const FPS = 30; const PALETTE = { bg: "#0F1312", fg: "#EDF0EC", muted: "#98A29B", accent: "#22AB83", amber: "#E8A33F" }; const deckOf = (deck) => ({ width: 1920, height: 1080, fps: FPS, transition: 0.4, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck } }); const INSTR = { dial: true, odometer: true, trail: true, qr: { show: false }, finale: { video: "side", totals: false } }; const ON = deckOf({ ...INSTR, measure: { flash: true } }); const OFF = deckOf(INSTR); /** The instruments' fixture cut: 9 clips, the last the finale -- optionally opening on the intro. */ function cut(render, { intro = false } = {}) { const timeline = Array.from({ length: 9 }, (_, i) => ({ type: "clip", id: `c${i + 1}`, video: "vidx", start: 10 * i, end: 10 * i + (i === 8 ? 14 : 8), cite: 1, section: 0, quote: "q", onscreen: { title: `Clip ${i + 1}` }, ...(i === 8 ? { layout: "finale" } : {}), })); if (intro) timeline.unshift({ type: "intro", id: "brand-intro", style: "boot-dark", seconds: 4.75, heading: "Intro" }); return { ...estimateSchedule({ slug: "m", title: "M", provenance: {}, render, timeline }), measure: DIAL }; } const dataOf = (html, id) => JSON.parse(new RegExp(``, "s").exec(html)[1]); /** The moments an outline `k` lights: its rising cues. */ const lit = (data, k = "fl") => data.cues.filter((c) => c.k === k && c.to.opacity === 1).map((c) => c.at); const near = (a, b) => a.length === b.length && a.every((x, i) => Math.abs(x - b[i]) < 0.02); test("off by default: no outline on any widget, and the pages are the pages they were", () => { const s = cut(OFF); for (const [id, html] of [["dial", dialHtml(s, OFF, {})], ["odometer", odometerHtml(s, OFF, {})], ["trail", trailHtml(s, OFF, {})]]) { assert.doesNotMatch(html, /data-k="fl"/, id); assert.equal(lit(dataOf(html, id)).length, 0, id); } assert.equal(flashOn(OFF), false); assert.equal(flashOn(ON), true); assert.equal(flashOn(ON, false), false, "a widget's own false beats the measure's true"); assert.equal(flashOn(OFF, true), true); }); test("a value change at t lights exactly the widget whose value changed, at t -- and nothing else does", () => { const s = cut(ON); const track = measureTrack(DIAL); const frame = 1 / FPS; const want = (times) => flashTimes(times, { fps: FPS }); const dialT = want([...track.current.slice(1), ...track.remembered, ...track.goals.slice(1)].map((x) => x.t)); const odoT = want([...track.lost.slice(1), ...track.net.slice(1)].map((x) => x.t)); const trailT = want(trailPoints(DIAL).map((p) => p.t)); const got = { dial: lit(dataOf(dialHtml(s, ON, {}), "dial")), odometer: lit(dataOf(odometerHtml(s, ON, {}), "odometer")), trail: lit(dataOf(trailHtml(s, ON, {}), "trail")) }; assert.ok(near(got.dial, dialT), `dial ${got.dial} vs ${dialT}`); assert.ok(near(got.odometer, odoT), `odometer ${got.odometer} vs ${odoT}`); assert.ok(near(got.trail, trailT), `trail ${got.trail} vs ${trailT}`); assert.ok(got.dial.length && got.odometer.length && got.trail.length); // A moment only the odometer changes at (a loss claim, no weight stated): the odometer lights, the dial does not. const onlyOdo = odoT.find((t) => !dialT.some((d) => Math.abs(d - t) < 0.02) && !trailT.some((d) => Math.abs(d - t) < 0.02)); assert.ok(onlyOdo !== undefined, "the fixture has a loss claim with no weight stated with it"); assert.ok(!got.dial.some((t) => Math.abs(t - onlyOdo) < 0.02)); // A stated weight lights the dial and the trail together, at the same instant. const both = dialT.find((t) => trailT.some((d) => Math.abs(d - t) < 0.02)); assert.ok(both !== undefined && got.trail.some((t) => Math.abs(t - both) < 0.02)); // Up over 0.15 s, down over 0.7 s; never before frame 1. const d = dataOf(dialHtml(s, ON, {}), "dial"); const up = d.cues.find((c) => c.k === "fl" && c.to.opacity === 1); const down = d.cues.find((c) => c.k === "fl" && c.to.opacity === 0); assert.equal(up.dur, FLASH_MOTION.up); assert.equal(down.dur, FLASH_MOTION.down); assert.ok(Object.values(got).flat().every((t) => t >= frame)); assert.deepEqual(d.init.fl, { opacity: 0 }, "dark on frame 0"); }); test("never over the intro: a change said while the deck is away does not light anything", () => { const s = cut(ON, { intro: true }); const introEnd = s.segments[1].start; for (const [id, html] of [["dial", dialHtml(s, ON, {})], ["odometer", odometerHtml(s, ON, {})], ["trail", trailHtml(s, ON, {})]]) { const times = lit(dataOf(html, id)); assert.ok(times.every((t) => t >= introEnd), `${id}: ${times} after ${introEnd}`); } // The fixture's changes at 2 and 3.75 s fall inside the 4.75 s intro: they are dropped, not moved. assert.ok(!lit(dataOf(dialHtml(s, ON, {}), "dial")).some((t) => t < introEnd)); }); test("the goal stack and the diet tags: a goal set / a new diet lights the card that lands -- never the first", () => { const FAN = { dial: true, odometer: true, trail: true, shelf: { items: ["diet", "goals"] }, diet: { position: "shelf", form: "tags", overlap: 0.6, days: true }, goals: { position: "shelf" }, streak: false, measure: { flash: true } }; const r = deckOf(FAN); const sched = { kind: "deck", fps: FPS, total: 740, transition: 0.4, segments: [{ id: "a", start: 0, duration: 740, end: 740 }], measure: EXTRAS }; const shelf = shelfGoalStates(sched, goalStates(sched, r)); const g = dataOf(goalsHtml(sched, r, { fonts: {} }).html, "goals"); const gLit = g.cues.filter((c) => /\.fl$/.test(c.k) && c.to.opacity === 1); const wantG = shelf.filter((st, j) => j > 0 && st.top).map((st) => st.at); assert.ok(near(gLit.map((c) => c.at), wantG), `goals ${gLit.map((c) => c.at)} vs ${wantG}`); assert.ok(!gLit.some((c) => c.k.startsWith("s0.")), "the first goal is the stack's entrance"); // A board-only change (met, missed) is not a goal set: no outline. assert.ok(shelf.some((st) => !st.top), "the fixture's board changes on its own") ; const states = dietStates(sched, r); const d = dataOf(dietHtml(sched, r, { fonts: {} }).html, "diet"); const dLit = d.cues.filter((c) => /\.fl$/.test(c.k) && c.to.opacity === 1).map((c) => c.at); const wantD = states.filter((st, j) => j > 0 && st.tags[0]?.id !== states[j - 1].tags[0]?.id).map((st) => st.at); assert.ok(near(dLit, wantD), `diet ${dLit} vs ${wantD}`); // The running day count changes far more often than the diet: it never lights the tag. assert.ok(dLit.length < d.cues.filter((c) => /\.y\d+$/.test(c.k)).length); // Off: nothing. const off = deckOf({ ...FAN, measure: undefined }); assert.doesNotMatch(goalsHtml(sched, off, { fonts: {} }).html, /class="fl"/); assert.doesNotMatch(dietHtml(sched, off, { fonts: {} }).html, /class="fl"/); }); test("the knobs: deck.measure.flash and each widget's own flash validate", () => { assert.deepEqual(validateMeasureSettings({ flash: true }), []); assert.match(validateMeasureSettings({ flash: "on" }).join(), /measure\.flash must be true or false/); assert.deepEqual(validateDial({ flash: false }), []); assert.match(validateDial({ flash: 1 }).join(), /dial\.flash must be true or false/); assert.deepEqual(validateMeasureExtra("goals", { flash: true }), []); assert.match(validateMeasureExtra("diet", { flash: "x" }).join(), /flash must be true, false or null/); });