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 | 248x 390x 37x 37x 37x 37x 248x 105x 105x 248x 3x 3x 37x 37x 37x 37x 37x 37x 37x 205x 37x 69x 67x 66x 37x 30x 30x 30x 37x 244x 244x 133x 133x 111x 89x 89x 30x 111x 137x 137x 42x 111x 193x 193x 36x 193x 33x 6x 6x 33x 20x 13x 12x 12x 10x 10x 10x 10x 10x 10x 2x 12x 12x 12x 12x 12x 45x 12x 192x 192x 192x 243x 243x 243x 36x | import {
resolveLR2ExtraLevel,
resolveLR2ExtraSoundLanes,
type LR2ExtraLaneObject,
type LR2ExtraLevel,
} from './lr2-extra-lanes.ts';
export interface LR2ExtraObject extends LR2ExtraLaneObject {
/** LR2's realTiming, in playback milliseconds (already divided by the selected tempo). */
timeMs: number;
/** LR2's converted bmsTiming, used for its end-of-chart cutoff. */
position: number;
}
/**
* Executable-backed MakeExtraChart (beta3 100201, 0x4add90), after LN decoding.
* Its caller has reset every head's endpoint to its start; tails remain op 50+.
* Inputs retain their source indices; output ops are the actual conversion, not a
* separately generated interpretation of the finished chart. No input is mutated.
*/
export function applyLR2Extra(
source: readonly LR2ExtraObject[],
options: {
keyMode: 5 | 7 | 9 | 10 | 14;
level: LR2ExtraLevel;
initialBPM: number;
soundFamilies: readonly number[];
},
): { ops: number[]; level: LR2ExtraLevel; changes: number } {
const objects = source.map((object, index) => ({ ...object, index }));
// The original comparator truncates a nonzero time difference to a C int.
objects.sort((a, b) => (a.timeMs === b.timeMs ? a.op - b.op : Math.trunc(a.timeMs - b.timeMs)));
let normalObjectCount = 0;
let endPosition = 0;
let changes = 0;
for (const object of objects) {
if (object.op >= 10 && object.op <= 30) {
normalObjectCount++;
endPosition = object.position;
}
if (options.keyMode >= 10 && (object.op === 10 || object.op === 20)) {
object.op = 1;
changes++;
}
}
const level = resolveLR2ExtraLevel(options.level, normalObjectCount);
const soundLanes = resolveLR2ExtraSoundLanes(objects, options.keyMode, options.soundFamilies);
let minimumGap =
options.initialBPM > 0 ? Math.max(125, Math.trunc([60000, 45000, 30000][level]! / options.initialBPM)) : 125;
const occupied = Array<number>(20).fill(0);
let rowStart = 0;
let rowTime = 0;
let alternate = false;
const isNormal = (op: number): boolean => op >= 10 && op < 30;
const isFree = (lane: number): boolean => {
// The beta3 DP search can address beyond this array into native stack locals.
// Do not silently turn such a read into a different placement policy.
// Slot 21 aliases the current fallback direction (0x4ae56c), always +1/-1.
if (lane === 21) return false;
if (lane < 0 || lane >= occupied.length) throw new RangeError('LR2 EXTRA addressed outside its native lane table.');
return occupied[lane] === 0;
};
const place = (object: (typeof objects)[number], lane: number): void => {
occupied[lane] = 2;
object.op = lane + 10;
changes++;
};
for (let index = 0; index < objects.length; index++) {
const object = objects[index]!;
if (object.timeMs === rowTime) {
if (isNormal(object.op)) occupied[object.op - 10] = 2;
if (object.op === 3 || object.op === 8) minimumGap = Math.max(125, Math.trunc(30000 / object.value));
} else {
// Only surrounding ordinary objects reserve neighbouring rows; LN ops and
// hidden objects do not acquire an invented hold reservation.
for (let previous = rowStart - 1; previous >= 0; previous--) {
const note = objects[previous]!;
if (rowTime - note.timeMs >= minimumGap) break;
if (isNormal(note.op) && occupied[note.op - 10] === 0) occupied[note.op - 10] = 1;
}
for (let next = index; next < objects.length; next++) {
const note = objects[next]!;
if (note.timeMs - rowTime >= minimumGap) break;
if (isNormal(note.op) && occupied[note.op - 10] === 0) occupied[note.op - 10] = 1;
}
for (let previous = rowStart; previous < index; previous++) {
const background = objects[previous]!;
if (background.op !== 1 || background.position < 0) continue;
let lane = soundLanes[background.value] ?? -1;
if (lane < 0 || lane >= 20) continue;
if (options.keyMode === 10 || options.keyMode === 14) {
lane = (lane % 10) + (alternate ? 0 : 10);
alternate = !alternate;
}
if (isFree(lane) && lane % 10 <= options.keyMode % 10) {
place(background, lane);
} else if (lane !== 0 && lane !== 10) {
const direction = background.value % 2 === 0 ? -1 : 1;
if (options.keyMode < 10) {
for (let distance = 1; distance <= options.keyMode; distance++) {
const next = lane + distance * direction,
previous = lane - distance * direction;
Eif (next >= 1 && next <= options.keyMode && isFree(next)) {
place(background, next);
break;
}
if (previous >= 1 && previous <= options.keyMode && isFree(previous)) {
place(background, previous);
break;
}
}
} else {
for (let distance = 1; distance <= options.keyMode / 2; distance++) {
const gap = distance * direction;
const candidates = [lane + gap, lane - gap];
lane += lane <= 10 ? 10 : -10;
candidates.push(lane + gap, lane - gap);
const available = candidates.find(
(candidate) => candidate % 10 >= 1 && candidate % 10 <= options.keyMode / 2 && isFree(candidate),
);
Iif (available !== undefined) {
place(background, available);
break;
}
}
}
}
}
occupied.fill(0);
rowTime = object.timeMs;
rowStart = index;
}
// No final row flush: the original only converts a row when it encounters
// another timestamp, and stops after the first object beyond the last tap.
if (object.position > endPosition) break;
}
const ops = Array<number>(source.length);
for (const object of objects) ops[object.index] = object.op;
return { ops, level, changes };
}
|