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 | 373x 1x 372x 114x 122x 366x 122x 122x 122x 122x 117x 117x 117x 7x 7x 7x 7x 7x 110x 94x 117x 117x 116x 7x 16x 2x 2x 12x 7x 4x 1x 2x 3x 1x 1x 1x 2x 4x 1x 1x 1x 1x 15x 3x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 8x 1x 1x 2x 1x 1x 2x 10x 1x 1x 2x 1x 2x 1x 2x 7x 1x 2x 2x 2x 5x 1x 1x 1x 2x 3675x 3675x | import { LR2_BAR_BODY, LR2_BAR_LAMP } from '../ids/bar.ts';
import type { ParseContext, SourceRect } from './parse-context.ts';
import type {
LR2BarBodyKind,
LR2BarGraphMuki,
LR2BarLampKind,
LR2BarLevelKind,
LR2BarRankKind,
LR2BarRivalKind,
LR2DestinationRect,
LR2NumberAlignment,
LR2SliderMuki,
LR2TextAlignment,
} from './types.ts';
export function clampColorByte(value: number): number {
if (!Number.isFinite(value)) {
return 0;
}
return Math.min(255, Math.max(0, Math.trunc(value)));
}
export function parseSource(row: string[], context: ParseContext): SourceRect {
return {
gr: toNumber(row[2], 0),
x: toNumber(row[3], 0),
y: toNumber(row[4], 0),
w: toNumber(row[5], 0),
h: toNumber(row[6], 0),
// LR2 frequently sets divx/divy=0 to mean "treat as 1" (single cell).
divx: Math.max(1, Math.trunc(toNumber(row[7], 1)) || 1),
divy: Math.max(1, Math.trunc(toNumber(row[8], 1)) || 1),
cycle: Math.max(0, Math.trunc(toNumber(row[9], 0))),
timer: Math.max(0, Math.trunc(toNumber(row[10], 0))),
// Stamp every parsed source with the next free CSV-stream index so the renderer can compare it against the bar
// layout's own index to decide which side of the bar list this element sits on.
declarationOrder: context.nextDeclarationOrder++,
};
}
export function parseDestination(row: string[]): LR2DestinationRect {
// #DST_*,(NULL),time,x,y,w,h,acc,a,r,g,b,blend,filter,angle,center,loop,timer,op1,op2,op3 row index: 0 1 2 3 4 5 6 7
// 8 9 10 11 12 13 14 15 16 17 18 19 20 (row[0] is the command itself when split by parseRow.)
const ops = [toNumber(row[18], 0), toNumber(row[19], 0), toNumber(row[20], 0)].filter(
(op) => Number.isFinite(op) && op !== 0,
);
// LR2 keyframes commonly leave the trailing fields blank past the first row (e.g. `#DST_IMAGE,0,1500,...,,,,,`). An
// empty field for `timer` should be treated as "keep the first keyframe's control", not as `timer=0` -- this is what
// kept things like the "STAGE FAILED" plate (timer=3 on the first keyframe) drawing during gameplay. Use -1 here as a
// sentinel and let the DST-list builder normalize the element-wide controls.
const timerRaw = row[17];
const timerProvided = typeof timerRaw === 'string' && timerRaw.trim() !== '';
const timer = timerProvided ? Math.max(0, Math.trunc(toNumber(timerRaw, 0))) : -1;
return {
time: Math.max(0, toNumber(row[2], 0)),
x: toNumber(row[3], 0),
y: toNumber(row[4], 0),
w: toNumber(row[5], 0),
h: toNumber(row[6], 0),
acc: Math.max(0, Math.min(3, Math.trunc(toNumber(row[7], 0)))),
alpha: Math.max(0, Math.min(1, toNumber(row[8], 255) / 255)),
r: clampColorByte(toNumber(row[9], 255)),
g: clampColorByte(toNumber(row[10], 255)),
b: clampColorByte(toNumber(row[11], 255)),
blend: Math.max(0, Math.trunc(toNumber(row[12], 0))),
filter: Math.max(0, Math.trunc(toNumber(row[13], 0))),
angle: toNumber(row[14], 0),
center: Math.max(0, Math.trunc(toNumber(row[15], 0))),
loop: toNumber(row[16], 0),
timer,
ops,
op4: Math.trunc(toNumber(row[21], 0)),
};
}
/** Append geometry keyframes while retaining the first row's element-wide controls (OpenLR2 ReadDST). */
export function appendDestinationKeyframe(group: LR2DestinationRect[], row: string[], context?: ParseContext): void {
const dst = parseDestination(row);
const first = group[0];
if (first) {
dst.timer = first.timer;
dst.loop = first.loop;
dst.ops = first.ops;
dst.op4 = first.op4;
Iif (isBlank(row[7])) dst.acc = group[group.length - 1]!.acc;
} else if (dst.timer === -1) {
dst.timer = 0;
}
group.push(dst);
// Feed the right-bottom corner into the canvas auto-detector's sample set. We skip entries with negative `x` or
// `y` (animation slide-in / slide-out start points authored off-screen) so the detector's percentile is dominated
// by ON-screen authored geometry. Entries with zero width / height also drop out — they don't render anything
// and add noise at the origin. `context` is optional so callers that just want the inheritance semantics
// (currently none, but the signature stays open for unit tests) can pass `undefined`.
if (context !== undefined && dst.x >= 0 && dst.y >= 0 && dst.w > 0 && dst.h > 0) {
context.observedDstCorners.push([dst.x + dst.w, dst.y + dst.h]);
}
}
function isBlank(value: string | undefined): boolean {
return typeof value !== 'string' || value.trim() === '';
}
export function parseNumberAlignment(value: string | undefined): LR2NumberAlignment {
switch (toNumber(value, 0)) {
case 1:
return 'left';
case 2:
return 'center';
default:
return 'right';
}
}
// LR2 NOWCOMBO_1P alignment. The spec says 0=left/1=center/2=right but matching the LR2 reference video visually
// requires NUMBER's encoding (0=right, 1=left, 2=center) — for the LR2 default 7-keys skin (`align=1`) the combo digits
// sit IMMEDIATELY to the right of the judgement plate (left-aligned at the relative x), not centered on it.
export function parseNowComboAlignment(value: string | undefined): LR2NumberAlignment {
switch (toNumber(value, 0)) {
case 1:
return 'left';
case 2:
return 'center';
default:
return 'right';
}
}
/** LR2 SRC_TEXT alignment: 0=left, 1=center, 2=right. */
export function parseTextAlignment(value: string | undefined): LR2TextAlignment {
switch (toNumber(value, 0)) {
case 1:
return 'center';
case 2:
return 'right';
default:
return 'left';
}
}
/** LR2 SRC_BARGRAPH `muki`: 0=horizontal, 1=vertical. */
export function parseBarGraphMuki(value: string | undefined): LR2BarGraphMuki {
return toNumber(value, 0) === 1 ? 'vertical' : 'horizontal';
}
/**
* LR2 SRC_SLIDER `muki`: empirically derived from the LR2 default 7-keys skin's song-progress slider
* (`#SRC_SLIDER,…,muki=2,range=278,type=6`) and the verified behavior that the indicator travels top → bottom over 278
* px starting at y=15. So muki=2 ⇒ "down" — vertical, growing downward.
*
* 0=right (horizontal default), 1=left, 2=down, 3=up.
*/
export function parseSliderMuki(value: string | undefined): LR2SliderMuki {
switch (toNumber(value, 0)) {
case 1:
return 'left';
case 2:
return 'down';
case 3:
return 'up';
default:
return 'right';
}
}
export function parseBarBodyKind(value: string | undefined): LR2BarBodyKind | undefined {
switch (Math.trunc(toNumber(value, -1))) {
case LR2_BAR_BODY.SONG:
return 'song';
case LR2_BAR_BODY.FOLDER:
return 'folder';
case LR2_BAR_BODY.CUSTOM_FOLDER:
return 'customFolder';
case LR2_BAR_BODY.NEW_SONG_FOLDER:
return 'newSongFolder';
case LR2_BAR_BODY.RIVAL_FOLDER:
return 'rivalFolder';
case LR2_BAR_BODY.RIVAL_SONG:
return 'rivalSong';
case LR2_BAR_BODY.COURSE_FOLDER:
return 'courseFolder';
case LR2_BAR_BODY.COURSE_CREATE:
return 'courseCreate';
case LR2_BAR_BODY.COURSE:
return 'course';
case LR2_BAR_BODY.RANDOM_COURSE:
return 'randomCourse';
default:
return undefined;
}
}
export function parseBarLevelKind(value: string | undefined): LR2BarLevelKind | undefined {
switch (Math.trunc(toNumber(value, -1))) {
case 0:
return 'undefined';
case 1:
return 'beginner';
case 2:
return 'normal';
case 3:
return 'hyper';
case 4:
return 'another';
case 5:
return 'insane';
case 6:
return 'irRanking';
default:
return undefined;
}
}
export function parseBarLampKind(value: string | undefined): LR2BarLampKind | undefined {
switch (Math.trunc(toNumber(value, -1))) {
case LR2_BAR_LAMP.NO_PLAY:
return 'noplay';
case LR2_BAR_LAMP.FAILED:
return 'failed';
case LR2_BAR_LAMP.EASY:
return 'easy';
case LR2_BAR_LAMP.CLEAR:
return 'clear';
case LR2_BAR_LAMP.HARD:
return 'hard';
case LR2_BAR_LAMP.FULL_COMBO:
return 'fullcombo';
default:
return undefined;
}
}
export function parseBarRankKind(value: string | undefined): LR2BarRankKind | undefined {
switch (Math.trunc(toNumber(value, -1))) {
case 0:
return 'noplay';
case 1:
return 'F';
case 2:
return 'E';
case 3:
return 'D';
case 4:
return 'C';
case 5:
return 'B';
case 6:
return 'A';
case 7:
return 'AA';
case 8:
return 'AAA';
default:
return undefined;
}
}
export function parseBarRivalKind(value: string | undefined): LR2BarRivalKind | undefined {
switch (Math.trunc(toNumber(value, -1))) {
case 0:
return 'win';
case 1:
return 'lose';
case 2:
return 'draw';
default:
return undefined;
}
}
export function toNumber(value: string | undefined, fallback: number): number {
const number = Number.parseFloat(value ?? '');
return Number.isFinite(number) ? number : fallback;
}
|