Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | 113x 113x 113x 28x 28x 28x 28x 113x 67x 67x 113x 113x 28x 26x 28x 28x 28x 28x 28x 47x 47x 47x 47x 47x 1x 46x 1x 47x 2x 47x 26x 26x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 3x 2x 2x 1x 1x 1x 1x 1x 1x 17x 17x 113x 13x 13x 13x 10x 10x 10x 11x 11x 11x 1x 10x 10x 10x 10x 12x 12x 12x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 9x 7x 7x 7x 7x 7x 7x 7x 7x 7x 10x 9x 9x 13x 9x 41x 2x 2x 2x 2x 2x 130x 130x 130x 67x 70x 130x 130x 28x 28x 56x 56x 56x 69x 69x 56x | // Strict-typed normalization for beatoraja's `judge` element.
//
// Each entry in `skin.judge` configures the per-side judgement display: 6 graphics (PERFECT,
// GREAT, GOOD, BAD, POOR, MISS) and an optional 6-entry parallel set of "number" graphics for
// showing the early/late ms offset. Both are author-shaped as `Destination`-style objects with
// their own `id` / `timer` / `dst[]` keyframes — meaning the skin authors them as if each
// judgement kind is its own destination.
//
// We don't render judge entries through a dedicated render kind — instead we **expand** the
// per-kind sub-destinations into the normal destination list with the appropriate per-judge op
// gate (`P1_JUDGE_PERFECT = 241`, etc.) and a synthesized `id` matching the sub-entry's `id`.
// The standard image / value pipeline then handles them: the op gate makes only the active
// judge kind visible, and the existing timer / dst-keyframe sampler handles the per-judge
// fly-in / fade-out animation.
//
// `index` selects the player side (0 = 1P, 1 = 2P). `shift` is unused in our path (no FAST /
// SLOW label displacement yet — surfaced via `BEATORAJA_OP.P*_JUDGE_EARLY` / `_LATE` ops).
import { flattenBeatorajaElements } from './base.ts';
import type { BeatorajaImageId } from './image.ts';
import {
SYNTHETIC_NUM_JUDGE_COMBO_1P,
SYNTHETIC_NUM_JUDGE_COMBO_2P,
SYNTHETIC_NUM_JUDGE_COMBO_3P,
SYNTHETIC_OFFSET_JUDGE_WORD_SHIFT_1P,
SYNTHETIC_OFFSET_JUDGE_WORD_SHIFT_2P,
SYNTHETIC_OP_JUDGE_DISPLAY_HIDDEN,
} from '../runtime-ids.ts';
import type { BeatorajaValueElement } from './value.ts';
/**
* One `judge[]` entry as authored. The renderer's expansion pass consumes this and emits 12
* synthetic destinations (6 images + 6 numbers) targeting the standard destination pipeline.
*/
export interface BeatorajaJudgeElement {
/** Author-given id. Not directly used by the renderer; preserved for diagnostics. */
id: string;
/** Player side. 0 = 1P, 1 = 2P. Drives which `_*P_JUDGE_*` op set the gates use. */
index: number;
/** Per-judge image destinations (PG / GR / GD / BD / PR / MS, in that order). */
images: ReadonlyArray<Readonly<Record<string, unknown>>>;
/** Per-judge number destinations — typically the early/late ms readout. Same order as images. */
numbers: ReadonlyArray<Readonly<Record<string, unknown>>>;
/**
* `shift` flag from the source. Authors set this to displace the readout based on FAST /
* SLOW; the renderer doesn't honor this yet (parsed for forward compatibility).
*/
shift: boolean;
}
export function normalizeBeatorajaJudges(input: unknown): BeatorajaJudgeElement[] {
const flattened = flattenBeatorajaElements(input);
const out: BeatorajaJudgeElement[] = [];
for (const entry of flattened) {
const f = entry.fields;
const id = typeof f.id === 'string' ? f.id : typeof f.id === 'number' ? String(f.id) : undefined;
Iif (id === undefined) continue;
out.push({
id,
index: numberField(f, 'index', 0),
images: arrayField(f.images),
numbers: arrayField(f.numbers),
shift: typeof f.shift === 'boolean' ? f.shift : false,
});
}
return out;
}
/**
* Per-judge op codes per side (1P / 2P / 3P), in PG → MS order. From prop.lua's `_*p_*` block.
*
* Side 3 is the POPN-9 third judge plate (`play9.json` `id: 2012`, `index: 2`). Upstream only
* defines PERFECT / GREAT / GOOD ops for the 3P plate (`SkinProperty.java:830-834`); BAD / POOR /
* MISS aren't routed per-plate (combo-breaks are treated globally on the 1P bank), so those
* slots fall back to the 1P ops — the 1P gate would activate when a combo-break verdict hits
* any plate, but the plate's `timer = 247` only re-fires when plate 3 itself was judged, so the
* fallback image only paints during plate 3's recent-verdict window.
*/
const SIDE_JUDGE_OPS: Record<1 | 2 | 3, ReadonlyArray<number>> = {
1: [
241, // _1p_perfect
242, // _1p_great
243, // _1p_good
244, // _1p_bad
245, // _1p_poor
246, // _1p_miss
],
2: [
261, // _2p_perfect
262, // _2p_great
263, // _2p_good
264, // _2p_bad
265, // _2p_poor
266, // _2p_miss
],
3: [
361, // _3p_perfect
362, // _3p_great
363, // _3p_good
244, // BAD / POOR / MISS fall back to the 1P ops (upstream has no `_3p_bad/poor/miss`).
245,
246,
],
};
/**
* Synthetic "gauge is currently at max" op codes per side (audit 1.2). Mirrors the keys
* defined in `beatoraja-runtime-ids.ts` (`BEATORAJA_OP.GAUGE_NOW_AT_MAX_*`); kept inline as
* literal numbers here to avoid a circular import with the broader OP registry. Side 3 (POPN-9
* third plate) reuses 1P's gauge-max op — POPN-9 plays the single-player gauge.
*/
const SIDE_GAUGE_MAX_OPS: Record<1 | 2 | 3, number> = { 1: 90100, 2: 90101, 3: 90100 };
/**
* Expand the parsed judge entries into raw destination-shaped records the standard destination
* pipeline can ingest. Each sub-image / sub-number gains an `op = [...currentOp, judgeKindOp]`
* gate so only the active judge kind paints. The existing op gate (if the author set one) is
* preserved by appending — both must be active for visibility.
*
* Indices beyond the 6-tier `PG/GR/GD/BD/PR/MS` set alias back to PERFECT — beatoraja themes
* use the extra slots for popn-style PG-only secondary effects. Default 9K's `play9.json`
* authors a 7-image judge with `judgef-pg2` at index 6, and the engine fires both that AND
* the standard `judgef-pg` simultaneously on a PERFECT verdict. Without this aliasing the
* 7th entry was silently dropped (`i < ops.length` cap), so 9K plays missed half of the
* authored PG splash.
*
* Every image and number is also gated on NOT `SYNTHETIC_OP_JUDGE_DISPLAY_HIDDEN`, so a play that hides the judgment
* display (LR2's SILENT automatic judge timing) lights that op and the whole `judge[]` display goes.
*
* Returns the freshly-allocated destination records; caller concats them with `skin.destination`
* before passing to `normalizeBeatorajaDestinations`.
*/
export function expandBeatorajaJudgeDestinations(
judges: ReadonlyArray<BeatorajaJudgeElement>,
/**
* Mutable lookup of `value[]` declarations by id. When supplied, judge.numbers[i] children
* receive upstream's combo-digit-specific treatment:
*
* 1. PRE-SHIFT: each child dst's `x` is decremented by `dst.w * value.digit / 2`. Mirrors
* `JsonPlaySkinObjectLoader.java:267-270` (`for ani: ani.x -= ani.w * value.digit / 2`).
* Effectively converts the authored child.x from "left edge of digit row" to "centre of
* digit row".
* 2. ALIGN OVERRIDE: the matching value's `align` is mutated to `2` (CENTER), mirroring
* `SkinJudge`'s hard-coded center-align mode for combo digits regardless of any
* `value.align` the JSON authored.
* 3. PER-PLATE REF + ID CLONE: each non-1P plate's combo digit gets a freshly-cloned value
* entry with a plate-suffixed id (`judgen-pg__plate2` / `__plate3`) so the renderer sees
* a distinct `value.ref` per plate. Without the clone, all plates referencing the same
* original `judgen-*` id share a single `value` object and the last-processed plate's
* ref overwrites the others' — making every plate display the same `lastJudgeCombo`.
* The matching destination's `id` is rewritten to the clone so it picks up the cloned
* value at render time.
*
* Without these, default `play5.json`'s combo digit "46" rendered far to the right of the
* judge popup (= 4 leading-blank slot widths × 40 px = 160 px gap before the visible "46"),
* because the value declaration has `digit:6` with no align field (defaults to RIGHT in our
* convention) and our fold treated child.x as the left edge of the digit row.
*
* Omitting the lookup falls back to the previous behaviour (parent.x + child.x as-is, no
* align override) — useful for tests that don't need the full skin context.
*/
valuesById?: Map<BeatorajaImageId, BeatorajaValueElement>,
/**
* Optional set of judge-element ids that the skin's `parts.destination` actually
* references — produced upstream by walking `parts.destination[]` and collecting every
* destination's `id`. When provided, judge entries whose `id` is NOT in the set are
* SKIPPED entirely.
*
* Mirrors upstream `JsonPlaySkinObjectLoader.java:220-221`'s instantiation guard:
*
* for (JSONSkin.Judgment judge : sk.judge) {
* if (dst.id.equals(judge.id)) { ... instantiate ... }
* }
*
* Only the judge whose `id` matches the current destination's id is built; the rest of
* `parts.judge[]` is dead authoring kept as alternate layouts. ModernChic's `judge.lua`
* authors 5 judge entries (`def`, `laneCoverRest_{1,2}`, `constantRest_{1,2}`) and toggles
* which one's id appears in `parts.destination` based on user options. Without honoring
* this filter our expansion emitted destinations for ALL 5 layouts simultaneously — even
* when the user-selected layout was just `def`, the other 4 still painted (gated by their
* `draw` predicates), so a single judge fire produced up to 3 stacked image sprites with
* different alphas / cycle phases. Visually that reads as "the judge popup is flickering"
* and "the wrong verdict image is showing" — the user-reported symptoms.
*
* Omitting the set falls back to "expand every judge entry" (the previous behaviour),
* which keeps tests / hosts that haven't wired the destination scan working.
*/
referencedJudgeIds?: ReadonlySet<string>,
): Array<Readonly<Record<string, unknown>>> {
const out: Array<Readonly<Record<string, unknown>>> = [];
for (const judge of judges) {
if (referencedJudgeIds !== undefined && !referencedJudgeIds.has(judge.id)) continue;
// `judge.index` is the plate index in upstream's `judge[]` array (`SkinJudge(images,
// numbers, judge.index, judge.shift)`). 0 = 1P plate, 1 = 2P plate, 2 = POPN-9 third plate
// (only present in `play9.json`-class skins). Map to our `BeatorajaSide` (1 / 2 / 3); any
// unknown index falls back to side 1 defensively.
const side: 1 | 2 | 3 = judge.index === 1 ? 2 : judge.index === 2 ? 3 : 1;
const ops = SIDE_JUDGE_OPS[side];
// Detect whether the skin authored the modern fullgauge-PG substitute at index 6 (audit
// 1.2). When it has, beatoraja's `SkinJudge.prepare()` makes `judge[0]` and `judge[6]`
// mutually exclusive: PG with full gauge → judge[6], PG without full gauge → judge[0].
// Without this flag the previous TS impl emitted both side-by-side, so default play9's
// `judgef-pg2` (the only sample skin that authors the slot today) double-rendered on
// every PG, not just full-gauge PGs.
const hasFullgaugeSubstitute = judge.images.length > 6 && judge.images[6] !== undefined;
const gaugeMaxOp = SIDE_GAUGE_MAX_OPS[side];
// `judge.shift = true` triggers upstream's combo-width-aware repositioning:
// `nowJudge.region.x += -nowCount.getLength() / 2`. The judge word slides LEFT by
// half the rendered combo's pixel width, so (word + combo) stays centred on the
// authored anchor regardless of digit count. Implemented by appending a synthetic
// offset id that the runtime adapter resolves to the dynamic shift value (= the
// adapter knows the live combo and slot width).
// Plate 3 (POPN-9 third plate) falls through to the 2P shift offset — upstream `play9.json`
// authors `"shift": false` on every plate so this path doesn't fire in practice for POPN-9,
// but the fallback keeps the contract well-defined if a future skin opts in. Both 1P and 2P
// shift offsets resolve to a per-plate `-combo_width/2` value in the adapter; a 3P plate
// sharing the 2P resolver would still produce a sensible centre-of-digit-row shift, just
// computed against `maxCombo` rather than the plate-3 latch.
const judgeWordShiftOffsetId = judge.shift
? side === 1
? SYNTHETIC_OFFSET_JUDGE_WORD_SHIFT_1P
: SYNTHETIC_OFFSET_JUDGE_WORD_SHIFT_2P
: undefined;
for (let i = 0; i < judge.images.length; i += 1) {
const child = judge.images[i];
Iif (child === undefined) continue;
const gate = ops[i] ?? ops[0]!;
let withGate = addOpGate(child, gate);
// When a fullgauge substitute is present, gate the PG slot (i=0) on NOT-fullgauge and
// the substitute slot (i=6) on fullgauge. All other slots (1..5, plus 7+ aliases)
// keep their per-tier op only.
if (hasFullgaugeSubstitute && i === 0) {
withGate = addOpGate(withGate, -gaugeMaxOp);
} else if (hasFullgaugeSubstitute && i === 6) {
withGate = addOpGate(withGate, gaugeMaxOp);
}
// Append the judge-word-shift offset so each judgef-* destination picks up the
// dynamic `-combo_width/2` x adjustment from the adapter.
if (judgeWordShiftOffsetId !== undefined) {
withGate = appendOffset(withGate, judgeWordShiftOffsetId);
}
out.push(addOpGate(withGate, -SYNTHETIC_OP_JUDGE_DISPLAY_HIDDEN));
}
// judge.numbers[] (the ms / count readouts paired with each judge tier) are only emitted
// for the top three tiers (PG / GR / GD) per beatoraja's `SkinJudge.java:96`:
// `nowCount = judgenow < 3 ? count[judgenow] : null;`
// Tiers 3..5 (BD / PR / MS) get NO number — beatoraja deliberately hides the readout on
// failed judgments so a stale combo / FAST-SLOW digit doesn't linger over a miss splash.
//
// Position fold: `judge.numbers[i].dst` is RELATIVE to the matching `judge.images[i].dst`
// — beatoraja's `SkinJudge.draw()` paints the number at `(parent.x + child.x, parent.y +
// child.y)`. The previous TS impl emitted children verbatim with their `(child.x, child.y)`
// as ABSOLUTE skin coords, so default `play5.json`'s `judgen-pg` at `{x:200, y:0}` painted
// at the bottom of the screen (Y-UP `y=0`) next to DURATION instead of "to the right of
// the PERFECT word". Folded dst keyframes are emitted per parent variant (the parent's
// `if[layout]`-gated rect drives the absolute position; the child's `(x, y, w, h)` adds the
// offset and overrides the size). Pure-time keyframes (e.g. `{time:500}` fade-out) pass
// through unchanged so the animation timeline survives the fold.
const numberLimit = Math.min(judge.numbers.length, 3);
for (let i = 0; i < numberLimit; i += 1) {
const child = judge.numbers[i];
const parent = judge.images[i];
Iif (child === undefined) continue;
const gate = ops[i] ?? ops[0]!;
// Look up the matching `value[]` declaration to apply the combo-digit-specific
// adjustments (see {@link expandBeatorajaJudgeDestinations}'s `valuesById` doc).
const valueId = typeof child.id === 'string' || typeof child.id === 'number' ? child.id : undefined;
const originalValue = valueId !== undefined ? valuesById?.get(valueId as BeatorajaImageId) : undefined;
const valueDigit = originalValue !== undefined ? Math.max(1, Math.trunc(originalValue.digit)) : undefined;
const folded = parent !== undefined ? foldChildDestIntoParent(child, parent, valueDigit) : child;
// Resolve the per-plate combo-ref + matching value-id. Plate 1 keeps the original `value[]`
// entry; plates 2 / 3 get a freshly-cloned value with a plate-suffixed id so each plate's
// `value.ref` is independent. Without the clone, every `judgen-pg` reference across the
// three judge entries would point at the same `value` object, and the last expansion's
// ref write would overwrite the earlier plates' refs — making all three plates display
// the same `lastJudgeCombo`. Mirrors upstream's per-`(plate, player)` combo display in
// `SkinJudge.prepare()` (`SkinJudge.java:108`) where `getNowCombo(player)` returns the
// plate-local latched value.
const perPlateRef =
side === 1
? SYNTHETIC_NUM_JUDGE_COMBO_1P
: side === 2
? SYNTHETIC_NUM_JUDGE_COMBO_2P
: SYNTHETIC_NUM_JUDGE_COMBO_3P;
let foldedId = (folded as { id?: unknown }).id;
if (originalValue !== undefined && valuesById !== undefined && valueId !== undefined) {
if (side === 1) {
// Plate 1 mutates the original value in place — there's only one plate-1 entry per
// chart, so the mutation is unambiguous and there's no shared-aliasing risk.
(originalValue as { align: number }).align = 2;
(originalValue as { ref: number }).ref = perPlateRef;
} else {
const clonedId = `${String(valueId)}__plate${side}` as unknown as BeatorajaImageId;
let clone = valuesById.get(clonedId);
if (clone === undefined) {
clone = { ...originalValue, id: clonedId, align: 2, ref: perPlateRef } as BeatorajaValueElement;
valuesById.set(clonedId, clone);
} else E{
// Per-frame idempotency: an earlier walk over the same judge already cloned this
// value; re-apply the per-plate mutations defensively so a future caller can't
// race the clone state into an unexpected combination.
(clone as { align: number }).align = 2;
(clone as { ref: number }).ref = perPlateRef;
}
foldedId = clonedId;
}
}
// Stamp the (possibly-cloned) value id on the destination so the renderer's value lookup
// picks up THIS plate's ref / align rather than the shared original's.
const idStamped =
foldedId !== undefined && foldedId !== (folded as { id?: unknown }).id
? ({ ...folded, id: foldedId } as Readonly<Record<string, unknown>>)
: folded;
out.push(addOpGate(addOpGate(idStamped, gate), -SYNTHETIC_OP_JUDGE_DISPLAY_HIDDEN));
}
}
return out;
}
/**
* Fold each child dst keyframe's `(x, y)` into the matching parent's authored position so the
* combined record paints at the parent's anchor + child offset. The CHILD'S `(w, h)` overrides
* the parent (numbers are typically smaller than the judgef word sprite); other fields like
* `r/g/b/a/angle` pass through from the child verbatim.
*
* Layout-variant handling: parent dst entries wrapped in `{if:[...], value:{...}}` (= dst alts
* gated on layout option ops) emit one matching `{if:[...], value:{...}}` entry per parent
* variant in the output, joined with the child's position-defining keyframe. Direct keyframes
* (`{time:N, x:X, ...}`) on the parent emit one position-folded keyframe per child position
* keyframe at that parent's coords. Pure-time child keyframes (e.g. `{time:500}` fade) pass
* through unchanged.
*/
function foldChildDestIntoParent(
child: Readonly<Record<string, unknown>>,
parent: Readonly<Record<string, unknown>>,
/**
* When set, applies upstream's combo-digit pre-shift `(ckf.w * digit) / 2` to each
* folded x. Mirrors `JsonPlaySkinObjectLoader.java:267-270`. Skipped when `undefined`
* (= the child isn't a judge.numbers entry, or no matching value declaration is
* available to read `digit` from).
*/
valueDigitForPreShift?: number,
): Readonly<Record<string, unknown>> {
const childDst = Array.isArray(child.dst) ? (child.dst as ReadonlyArray<unknown>) : [];
const parentDst = Array.isArray(parent.dst) ? (parent.dst as ReadonlyArray<unknown>) : [];
if (childDst.length === 0 || parentDst.length === 0) return child;
// Split the child's keyframes: position-bearing entries get folded against parent positions;
// pure-time entries (no x/y) survive verbatim as fade-out / hold cues.
const childPositionKfs: Array<Readonly<Record<string, unknown>>> = [];
const childPureKfs: Array<Readonly<Record<string, unknown>>> = [];
for (const kf of childDst) {
Iif (kf === null || typeof kf !== 'object') continue;
const obj = kf as Readonly<Record<string, unknown>>;
if (typeof obj.x === 'number' || typeof obj.y === 'number') childPositionKfs.push(obj);
else childPureKfs.push(obj);
}
Iif (childPositionKfs.length === 0) return child;
// Walk parent keyframes. For each one that defines a position, emit folded child variants.
const out: Array<Readonly<Record<string, unknown>>> = [];
let parentHadPositionedKf = false;
for (const parentKf of parentDst) {
Iif (parentKf === null || typeof parentKf !== 'object') continue;
const parentObj = parentKf as Readonly<Record<string, unknown>>;
// `{if:[...], value:{...}}` wrapper — preserve the if-gating around the folded child entries.
if (Array.isArray(parentObj.if) && parentObj.value !== undefined) {
const inner = parentObj.value as Readonly<Record<string, unknown>>;
Eif (typeof inner.x === 'number' || typeof inner.y === 'number') {
parentHadPositionedKf = true;
const px = numberOrZero(inner.x);
const py = numberOrZero(inner.y);
for (const ckf of childPositionKfs) {
const folded: Record<string, unknown> = { ...ckf };
const preShiftX = valueDigitForPreShift !== undefined ? (numberOrZero(ckf.w) * valueDigitForPreShift) / 2 : 0;
folded.x = px + numberOrZero(ckf.x) - preShiftX;
folded.y = py + numberOrZero(ckf.y);
out.push({ if: parentObj.if, value: folded });
}
}
continue;
}
// Direct keyframe with x/y. Combine with each child position kf.
if (typeof parentObj.x === 'number' || typeof parentObj.y === 'number') {
parentHadPositionedKf = true;
const px = numberOrZero(parentObj.x);
const py = numberOrZero(parentObj.y);
for (const ckf of childPositionKfs) {
const folded: Record<string, unknown> = { ...ckf };
const preShiftX = valueDigitForPreShift !== undefined ? (numberOrZero(ckf.w) * valueDigitForPreShift) / 2 : 0;
folded.x = px + numberOrZero(ckf.x) - preShiftX;
folded.y = py + numberOrZero(ckf.y);
out.push(folded);
}
}
}
// Parent never authored a positioned keyframe → no fold to perform. Pass the child through
// verbatim so authors that intentionally pin numbers to absolute coords (rare; no in-tree
// skin currently does this) keep their authored layout.
if (!parentHadPositionedKf) return child;
for (const kf of childPureKfs) out.push(kf);
// SkinNumber.prepare receives the already-offset judge word's position, then applies its own offsets.
// Keep the parent's ids separate: its dimensions, alpha and rotation do not belong to the child number.
const parentOffsets = Array.isArray(parent.offsets) ? [...parent.offsets] : [];
Iif (typeof parent.offset === 'number' && parent.offset !== 0) parentOffsets.push(parent.offset);
return { ...child, dst: out, ...(parentOffsets.length > 0 ? { parentOffsets } : {}) };
}
function numberOrZero(v: unknown): number {
return typeof v === 'number' && Number.isFinite(v) ? v : 0;
}
/**
* Produce a copy of the destination record with `op` extended to AND-include `gateOp`. If the
* source already has an `op` array, the new code is appended; otherwise a fresh single-element
* array is set. Other fields pass through unchanged — this is a lightweight clone that doesn't
* deep-copy the `dst[]` keyframes (those are read-only at this point).
*/
/**
* Append an offset id to the destination's `offsets[]` array. Used to plumb the
* synthetic judge-word-shift id through the standard offset-summing path so the runtime
* adapter's `resolveOffset` can supply the dynamic `-combo_width/2` x offset.
*/
function appendOffset(child: Readonly<Record<string, unknown>>, offsetId: number): Readonly<Record<string, unknown>> {
const existing = child.offsets;
const merged: number[] = [];
Iif (Array.isArray(existing)) {
for (const v of existing) {
if (typeof v === 'number' && Number.isFinite(v)) merged.push(v);
}
}
merged.push(offsetId);
return { ...child, offsets: merged };
}
function addOpGate(child: Readonly<Record<string, unknown>>, gateOp: number): Readonly<Record<string, unknown>> {
const existingOp = child.op;
const merged: number[] = [];
if (Array.isArray(existingOp)) {
for (const v of existingOp) {
Eif (typeof v === 'number' && Number.isFinite(v)) merged.push(v);
}
}
merged.push(gateOp);
return { ...child, op: merged };
}
function numberField(record: Readonly<Record<string, unknown>>, key: string, fallback: number): number {
const v = record[key];
return typeof v === 'number' && Number.isFinite(v) ? v : fallback;
}
function arrayField(value: unknown): ReadonlyArray<Readonly<Record<string, unknown>>> {
Iif (!Array.isArray(value)) return [];
const out: Array<Readonly<Record<string, unknown>>> = [];
for (const v of value) {
Eif (v !== null && typeof v === 'object' && !Array.isArray(v)) {
out.push(v as Readonly<Record<string, unknown>>);
}
}
return out;
}
|