// What the measure's instrument modules share (dial, odometer, trail, // dial-finale): their faces -- the deck's, plus the manifest's display and // condensed faces when it names them (`render.fontDisplay`, // `render.fontCondensed`) -- and their frame-key model. import { INSTRUMENT_FONTS } from "../chrome-instruments.mjs"; import { instrumentsGeometry } from "../deck.mjs"; import { instrumentsPlacement, resolveDial } from "../instruments.mjs"; import { measureExtraGeometry } from "../measure-extras.mjs"; import { MEASURE_EXTRAS, resolveMeasureExtra } from "./measure-extras-settings.mjs"; /** * The faces a measure page draws in, copied in beside it: `{ DeckSans, * DeckSansBold, MeasureDisplay?, MeasureCond? }` asset paths. A display or * condensed face that cannot be copied is left out, and the page falls back * to the deck's bold or regular. */ export async function instrumentFonts(ctx) { const deck = await ctx.fonts({ regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); const out = { DeckSans: deck.regular, DeckSansBold: deck.bold }; for (const [key, name] of [["fontDisplay", INSTRUMENT_FONTS.display], ["fontCondensed", INSTRUMENT_FONTS.condensed]]) { const src = ctx.render?.[key]; if (typeof src !== "string" || !src) continue; const ext = (/\.[A-Za-z0-9]+$/.exec(src)?.[0] ?? ".ttf").toLowerCase(); try { out[name] = await ctx.asset(src, `${name}${ext}`); } catch { // The deck's face stands in. } } return out; } /** A whole-cut cue interpreter's frame keys (frame-keys.mjs): its data less what is keyed per frame. */ export const wholeCutKeys = (region) => ({ data: `${region}-data`, omit: ["init", "cues", "window", "total"] }); /** Is the measure in the schedule: what every instrument draws from. */ export const hasMeasure = (schedule) => !!(schedule?.measure && Array.isArray(schedule.measure.state) && schedule.measure.scale); /** The sentence a page refuses with when the schedule has no measure. */ export const noMeasure = (what) => `the ${what} needs a schedule with a measure (a manifest with a measure ledger and render.chrome.deck.measure)`; /** * In the corner (`deck.dial.placement: "corner"`) an instrument stands in the * footage box, where the measure extras (goals, peak, promise, diet, streak; * measure-extras.mjs) stand at their anchors: the sentence naming each one the * instrument `id` would cover and how to move one, or null. The column never * meets them (they are in the footage, it is beside it). */ export function cornerCollision(id, render) { if (instrumentsPlacement(render) !== "corner") return null; const mine = instrumentsGeometry(render)[id]; if (!mine) return null; const hit = (a, b) => a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height; const over = MEASURE_EXTRAS.filter((x) => { const cfg = resolveMeasureExtra(x, render); return cfg && cfg.show !== false && hit(mine, measureExtraGeometry(x, render)); }); if (!over.length) return null; const corner = resolveDial(render)?.corner ?? "bottom-right"; return `the corner ${id} (render.chrome.deck.dial.placement "corner", ${corner}) covers ${over.map((x) => `the ${x} (render.chrome.deck.${x}.position ${resolveMeasureExtra(x, render).position})`).join(" and ")}: ` + `move one -- deck.${over[0]}.position, or deck.dial.corner`; }