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 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | 173343x 173343x 13345x 13345x 173343x 4910x 4910x 3120x 700x 700x 425x 275x 705x 705x 10x 8x 705x 965x 965x 965x 258x 707x 707x 965x 965x 275x 707x 500x 500x 707x 707x 435x 131x 433702x 433702x 433702x 433702x 433702x 265151x 265151x 12x 265139x 265139x 79445x 185694x 251x 185443x 4910x 4910x 4910x 433702x 4027x 6490x 4027x 9820x 736x 9084x 9084x 4174x 4174x 4910x 4910x 736x 433702x 5143x 86887x 86887x 28465x 58422x 58422x 219x 58203x 58203x 58203x 39582x 39582x 2x 39580x 39580x 12062x 27518x 24690x 2828x 229x 346815x 346815x 346815x 2950x 2950x 1x 1x 2949x 2616x 333x 333x 346815x 346815x 346815x 347844x 3607x 3607x 221x 347844x 49485x 49485x 16324x 16324x 16324x 15464x 860x 1x 859x 347844x 346815x 1029x 51x 1029x 1080x 859x 1029x 859x 859x 859x 859x 860x 859x 859x 859x 859x 859x 854x 222x 222x 854x 222x 222x 222x 122x 222x 222x 632x 632x 975x 430x 545x 545x 545x 545x 545x 539x 545x 221x 221x 221x 221x 221x 3x 221x 221x 221x 346815x 346815x 346815x 346815x 974728x 974728x 300484x 674244x 331189x 343055x 343055x 49451x 346815x 33045x 346815x 124618x 33045x 33045x 33045x 49451x 49451x 49451x 11353x 49451x 6752x 42699x 42699x 42699x 42699x 41789x 42699x 42699x 42699x 42699x 610x 610x 525x 15472x 15472x 15472x 15x 15472x 15472x 1x 15472x 1257x 15472x 15472x 15472x 15472x 1923x 15472x 15472x 15472x 1923x 58789x 58789x 58789x 53767x 5022x 5022x 6x 5022x 5022x 5022x 5022x 5022x 5022x 5022x 4745x 5022x 9624x 9624x 8847x 8847x 175266x 4773x 4773x 14x 4773x 8437x 346815x 300437x 78687x 46378x 99969x 99974x 6241x 99974x 95236x 95236x 4738x 4738x 4733x 170393x 8479x 8224x 8224x 8224x 131x 346815x 346815x 346815x 346815x 346815x 346815x 168007x 346815x 270494x 270494x 270494x 270494x 270494x 270494x 3561x 3561x 3561x 3561x 266933x 30717x 30717x 24x 24x 24x 24x 30693x 23601x 7092x 3300x 3300x 3300x 3792x 3792x 30717x 30717x 236216x 4663x 4663x 4663x 4663x 4663x 346815x 346815x 346815x 346815x 346815x 306512x 306512x 306512x 306512x 1351894x 406452x 306512x 239981x 239981x 779x 239981x 110x 239871x 239871x 145843x 306512x 93379x 306512x 3195x 306512x 44595x 13949x 13949x 13949x 13949x 306512x 306512x 1462389x 1462389x 239864x 1222525x 370453x 852072x 852072x 306512x 306512x 185452x 185452x 185452x 50343x 135109x 210x 134899x 306512x 2679x 2679x 331x 2348x 2348x 2353x 2353x 2348x 5x 5x 5x 2348x 2348x 2348x 85881x 85283x 598x 598x 598x 598x 2348x 1x 2348x 2x 2x 2x 2348x 2348x 2348x 70x 70x 70x 66x 70x | import type { BeMusicEvent } from '@be-music/chart-source';
import { advancePlugoutHiddenSounds, notePlugoutLaneJudged } from './plugout-lane-sound.ts';
import type { TimedLandmineNote, TimedPlayableNote } from '../playable-notes.ts';
import { judgeWindowLateReachUs } from '../ruleset/judge.ts';
import { addHCNPassing, HCNTickCounter, isChargeLongNoteMode } from '../ruleset/long-note.ts';
import {
combineLongNoteJudges,
insertPendingAutoLongNote,
longNoteScoresTail,
resolveLoggedLongNoteMode,
resolveLongNoteEndSeconds,
resolveLongNoteEarlyReleaseJudge,
resolveManualTimedJudge,
resolveRulesetLongNoteMode,
toUILongNoteMode,
type PendingAutoLongNoteState,
type TimedManualJudge,
} from './judge-rules.ts';
import { resolveLandmineGaugeEffect } from './landmine.ts';
import { applyJudgeToSummary } from './scoring.ts';
import {
applyGaugeDelta,
applyGaugeJudge,
applyResolvedManualJudge,
applyTailMissPoor,
badWindowSeconds,
clampToReversal,
applyHCNGaugeTick,
compareJudgeChannels,
judgeWindowsFor,
markInvisibleJudged,
markLandmineJudged,
markScorableJudged,
noteOwesTailMiss,
resolveMissDeadlineSeconds,
resolveMissDeadlineUs,
setCombo,
toJudgeClock,
toJudgeUs,
windowTablesAt,
isJudgingClosed,
} from './judge-core-score.ts';
import {
type ActiveLongNoteState,
type HCNPassingState,
type JudgeCoreEffectSink,
type JudgeCoreState,
LANDMINE_EXPLOSION_SAMPLE_KEY,
} from './judge-core-types.ts';
import { createLaneHoldHistory, type LaneHoldHistory, wasLaneDownAt } from './lane-hold.ts';
/**
* Judgment-core time steps: long-note holds and tails, HCN ticks, mines, auto-scratch, misses
* and the end-of-play charge.
*/
// ---- mines ----------------------------------------------------------------------------------------------------
/** The press / release history of `channel`, created on first use. */
export function laneHoldHistory(state: JudgeCoreState, channel: string): LaneHoldHistory {
let history = state.laneHolds.get(channel);
if (history === undefined) {
history = createLaneHoldHistory();
state.laneHolds.set(channel, history);
}
return history;
}
/**
* Whether `channel`'s key was down at `atMs`, read off the recorded presses and releases, so it does not matter when
* the question is asked or in what order the driver applied the inputs around `atMs`; an input at `atMs` itself comes
* first.
*/
function wasLaneDownAtMs(state: JudgeCoreState, channel: string, atMs: number): boolean {
const history = state.laneHolds.get(channel);
// A key-state hold that came without a press is only known to be down now.
if (history === undefined || history.spans.length === 0) return state.heldChannels.has(channel);
return wasLaneDownAt(history, atMs);
}
/**
* The explosion sample event of a mine, or `undefined` when its slot (`#WAV00` unless `sampleKey` names another, as
* a stitched NONSTOP stage's does) has no file.
*/
export function resolveLandmineExplosionEvent(
landmineEvent: BeMusicEvent,
resources: Readonly<Record<string, string>>,
sampleKey: string = LANDMINE_EXPLOSION_SAMPLE_KEY,
): BeMusicEvent | undefined {
const sourcePath = resources[sampleKey];
if (typeof sourcePath !== 'string' || sourcePath.length === 0) {
return undefined;
}
return {
...landmineEvent,
value: sampleKey,
};
}
/**
* The explosion slot of a mine at `seconds` under `cues` (`JudgeCoreConfig.landmineSampleKeys`): the last cue at or
* before it, `undefined` (silent) when that cue names none, and `#WAV00` without cues or before the first.
*/
export function resolveLandmineSampleKey(
cues: ReadonlyArray<{ seconds: number; sampleKey?: string }> | undefined,
seconds: number,
): string | undefined {
let key: string | undefined = LANDMINE_EXPLOSION_SAMPLE_KEY;
for (const cue of cues ?? []) {
if (cue.seconds > seconds) break;
key = cue.sampleKey;
}
return key;
}
function detonateLandmine(
state: JudgeCoreState,
landmine: TimedLandmineNote,
nowSec: number,
emit: JudgeCoreEffectSink,
): void {
Iif (!markLandmineJudged(state, landmine)) {
return;
}
const { config } = state;
if (isJudgingClosed(state)) {
return;
}
const landmineGaugeEffect = resolveLandmineGaugeEffect(landmine.event, config.idBase, config.sourceFormat);
const explosionKey = landmine.silent
? undefined
: resolveLandmineSampleKey(config.landmineSampleKeys, landmine.seconds);
const landmineExplosionEvent =
explosionKey === undefined
? undefined
: resolveLandmineExplosionEvent(landmine.event, config.wavResources, explosionKey);
if (landmineExplosionEvent) {
emit({
kind: 'sound',
source: 'mine-hit',
event: landmineExplosionEvent,
seconds: nowSec,
channel: landmine.channel,
});
}
// LR2beta3 counts one POOR without applying an ordinary POOR judgment: no combo break or judge gauge damage.
// That-Which-Must-Not-Be-Named imports that policy (#1169); beatoraja stays gauge-only. Raw damage bypasses guts and TOTAL modifiers.
if (config.ruleset.mineTrigger === 'press-ahead-or-hold') {
state.summary.poor += 1;
state.summary.minePoor = (state.summary.minePoor ?? 0) + 1;
}
applyGaugeDelta(state, nowSec, landmineGaugeEffect.gaugeDelta, 'mine-hit', emit);
if (!state.config.omitTraceEffects) {
emit({
kind: 'trace',
name: 'mine-hit',
seconds: nowSec,
fields: [
['channel', landmine.channel],
['value', landmineGaugeEffect.objectValue],
['damage', landmineGaugeEffect.damage],
],
});
}
}
/** Upper bound (µs) on the scanned mine reach, so a mine scan can stop at mines too far ahead to matter. */
const LANDMINE_SCAN_AHEAD_US = 1_000_000;
/**
* Held mines detonate at crossing, then retire: no ruleset has a late window. The same timed events run in the
* simulator.
*/
export function processLandminePassage(
state: JudgeCoreState,
nowSec: number,
nowMs: number,
emit: JudgeCoreEffectSink,
): void {
const { config } = state;
const landmineNotes = config.landmineNotes;
const reversalSeconds = config.reversalSeconds;
const nowUs = toJudgeUs(nowSec);
// Allocated only once a check falls due: most frames have none.
let due: Array<{ atUs: number; landmine: TimedLandmineNote; phase: 2 | 3 }> | undefined;
for (let index = state.landmineExpireCursor; index < landmineNotes.length; index += 1) {
const landmine = landmineNotes[index]!;
if (reversalSeconds !== undefined && landmine.seconds >= reversalSeconds) {
// Mines at or behind the LR2 reversal are frozen with the pump (#134) — they neither detonate nor retire.
break;
}
const mineUs = toJudgeUs(landmine.seconds);
if (mineUs - LANDMINE_SCAN_AHEAD_US >= nowUs) {
break;
}
if (landmine.judged) {
continue;
}
// The crossing check (2) runs before the mine retires (3), both at the crossing.
if (mineUs < nowUs) {
Eif ((state.landminePhases.get(landmine) ?? 0) < 2) {
(due ??= []).push({ atUs: mineUs, landmine, phase: 2 });
}
(due ??= []).push({ atUs: mineUs, landmine, phase: 3 });
}
}
if (due !== undefined) {
due.sort(
(left, right) =>
left.atUs - right.atUs ||
compareJudgeChannels(left.landmine.channel, right.landmine.channel) ||
left.phase - right.phase,
);
for (const check of due) {
if (check.landmine.judged) {
continue;
}
state.landminePhases.set(check.landmine, check.phase);
if (check.phase === 3) {
markLandmineJudged(state, check.landmine);
continue;
}
const atMs = nowMs - (nowSec - check.atUs / 1e6) * config.judgeMsPerChartSecond;
if (wasLaneDownAtMs(state, check.landmine.channel, atMs)) {
detonateLandmine(state, check.landmine, nowSec, emit);
}
}
}
while (state.landmineExpireCursor < landmineNotes.length && landmineNotes[state.landmineExpireCursor]!.judged) {
state.landmineExpireCursor += 1;
}
}
/**
* LR2beta3 key-down detonates only ahead of the line, strictly inside GREAT; That-Which-Must-Not-Be-Named imports the rule on its own
* GREAT window. Detonation never consumes the press: note judgment still runs.
*/
export function detonateLandminesOnPress(
state: JudgeCoreState,
channels: ReadonlySet<string>,
nowSec: number,
emit: JudgeCoreEffectSink,
): void {
const { config } = state;
if (config.ruleset.mineTrigger === 'hold') {
return;
}
const reversalSeconds = config.reversalSeconds;
if (reversalSeconds !== undefined && toJudgeUs(nowSec) > toJudgeUs(reversalSeconds)) {
// The press leg is dead past the reversal (#134); a press at the reversal itself still counts.
return;
}
const landmineNotes = config.landmineNotes;
const nowUs = toJudgeUs(nowSec);
for (let index = state.landmineExpireCursor; index < landmineNotes.length; index += 1) {
const landmine = landmineNotes[index]!;
if (reversalSeconds !== undefined && landmine.seconds >= reversalSeconds) {
// The early reach must not detonate mines positioned behind the reversal (#134).
break;
}
const mineUs = toJudgeUs(landmine.seconds);
if (mineUs - LANDMINE_SCAN_AHEAD_US > nowUs) {
break;
}
if (landmine.judged || !channels.has(landmine.channel)) {
continue;
}
// Read the window in force at the press (`#EXRANK` can change it).
if (mineUs >= nowUs && mineUs - nowUs < windowTablesAt(config, nowSec).note.judges[1][1]) {
detonateLandmine(state, landmine, nowSec, emit);
}
}
}
function markExpiredInvisibleNotes(state: JudgeCoreState, referenceSeconds: number): void {
const invisibleNotes = state.config.invisibleNotes;
const horizon = badWindowSeconds(state.config);
while (state.invisibleExpireCursor < invisibleNotes.length) {
const invisible = invisibleNotes[state.invisibleExpireCursor]!;
if (invisible.judged) {
state.invisibleExpireCursor += 1;
continue;
}
if (referenceSeconds - invisible.seconds <= horizon) {
break;
}
markInvisibleJudged(state, invisible);
state.invisibleExpireCursor += 1;
}
}
// ---- auto scratch ---------------------------------------------------------------------------------------------
/** An AUTO SCRATCH judgment due this step: a pending long-note tail (`order` 0) or a scratch note's head (`order` 1). */
interface AutoScratchDue {
atUs: number;
channel: string;
order: 0 | 1;
pending: PendingAutoLongNoteState | undefined;
note: TimedPlayableNote | undefined;
}
/**
* AUTO SCRATCH: the scratch notes whose time has passed, and the auto-played long notes whose tail has, in time order
* (a tail before a head at the same instant, then channel order), each at its own microsecond.
*/
function applyAutoScratchJudgements(state: JudgeCoreState, referenceSeconds: number, emit: JudgeCoreEffectSink): void {
const { config } = state;
const nowUs = toJudgeUs(referenceSeconds);
for (;;) {
// Plain records rather than closures, so a frame with nothing due allocates nothing (closures over this frame's
// arguments would make V8 allocate their context on every call).
let due: AutoScratchDue[] | undefined;
for (const pending of state.pendingAutoScratchLongNotes) {
const atUs = toJudgeUs(pending.endSeconds);
if (atUs < nowUs) {
(due ??= []).push({
atUs,
channel: pending.note.channel,
order: 0,
pending,
note: undefined,
});
}
}
if (config.autoScratch) {
const autoScratchNotes = state.autoScratchNotes;
for (let index = state.autoScratchCursor; index < autoScratchNotes.length; index += 1) {
const note = autoScratchNotes[index]!;
const atUs = toJudgeUs(note.seconds);
if (atUs >= nowUs) {
break;
}
if (note.judged) {
continue;
}
(due ??= []).push({
atUs,
channel: note.channel,
order: 1,
pending: undefined,
note,
});
}
}
if (due === undefined) {
break;
}
due.sort(
(left, right) =>
left.atUs - right.atUs || left.order - right.order || compareJudgeChannels(left.channel, right.channel),
);
for (const entry of due) {
if (entry.pending !== undefined) completeAutoScratchLongNote(state, entry.pending, referenceSeconds, emit);
else startAutoScratchNote(state, entry.note!, referenceSeconds, emit);
}
while (
state.autoScratchCursor < state.autoScratchNotes.length &&
state.autoScratchNotes[state.autoScratchCursor]!.judged
) {
state.autoScratchCursor += 1;
}
}
}
function startAutoScratchNote(
state: JudgeCoreState,
note: TimedPlayableNote,
referenceSeconds: number,
emit: JudgeCoreEffectSink,
): void {
const { config } = state;
Iif (!markScorableJudged(state, note)) {
return;
}
for (const event of note.soundEvents ?? [note.event])
emit({ kind: 'sound', source: 'auto-scratch', event, seconds: note.seconds, channel: note.channel });
Iif (note.chainSounds)
emit({ kind: 'chain-sounds', sounds: note.chainSounds, seconds: note.seconds, channel: note.channel });
notePlugoutLaneJudged(state, note.channel, note);
const endSeconds = resolveLongNoteEndSeconds(note);
emit({ kind: 'ui', command: { kind: 'flash-lane', channel: note.channel } });
// plugout's AUTO SCRATCH only sounds the note: no judgment, combo or gauge, and the note is not counted.
if (config.ruleset.autoScratchUnjudged === true) return;
if (typeof note.endBeat === 'number' && Number.isFinite(note.endBeat) && note.endBeat > note.beat) {
note.visibleUntilBeat = note.endBeat;
emit({ kind: 'ui', command: { kind: 'hold-lane-until-beat', channel: note.channel, beat: note.endBeat } });
}
if (endSeconds !== undefined) {
emit({
kind: 'long-note',
seconds: note.seconds,
channel: note.channel,
state: 'start',
mode: resolveLoggedLongNoteMode(note),
event: note.event,
endSeconds,
});
insertPendingAutoLongNote(state.pendingAutoScratchLongNotes, note, endSeconds);
if (longNoteScoresTail(config.ruleset.longNoteStyle, note)) {
// Charge modes judge the head and the tail separately: auto scratch clears the head now, the tail at the tail
// (beatoraja's autoplay).
applyAutoPerfect(state, note.channel, referenceSeconds, emit);
}
emit({
kind: 'ui',
command: {
kind: 'long-note-start',
channel: note.channel,
beat: note.beat,
mode: toUILongNoteMode(resolveRulesetLongNoteMode(config.ruleset.longNoteStyle, note) ?? 2),
},
});
return;
}
applyAutoPerfect(state, note.channel, referenceSeconds, emit);
emit({ kind: 'poor-trace', action: 'clear', seconds: referenceSeconds });
}
function applyAutoPerfect(state: JudgeCoreState, channel: string, seconds: number, emit: JudgeCoreEffectSink): void {
if (isJudgingClosed(state)) {
return;
}
applyJudgeToSummary(state.summary, 'PERFECT', state.scoreTracker);
applyGaugeJudge(state, seconds, 'PERFECT', emit);
emit({ kind: 'poor-bga', action: 'clear', seconds });
setCombo(state, seconds, state.combo + 1, 'judge', emit, 'PERFECT', channel);
if (!state.config.omitTraceEffects) {
emit({
kind: 'trace',
name: 'auto-judge',
seconds,
fields: [
['result', 'PERFECT'],
['channel', channel],
],
});
}
emit({ kind: 'judge-combo', judge: 'PERFECT', combo: state.combo, channel });
}
function completeAutoScratchLongNote(
state: JudgeCoreState,
pending: PendingAutoLongNoteState,
referenceSeconds: number,
emit: JudgeCoreEffectSink,
): void {
const index = state.pendingAutoScratchLongNotes.indexOf(pending);
Iif (index < 0) {
return;
}
state.pendingAutoScratchLongNotes.splice(index, 1);
emit({
kind: 'long-note',
seconds: pending.endSeconds,
channel: pending.note.channel,
state: 'complete',
mode: resolveLoggedLongNoteMode(pending.note),
event: pending.note.event,
endSeconds: pending.endSeconds,
});
if (pending.note.endSoundEvent)
emit({
kind: 'sound',
source: 'long-note-end',
event: pending.note.endSoundEvent,
seconds: pending.endSeconds,
channel: pending.note.channel,
});
// The LN's one judgment, or a charge note's tail (its head was cleared at the head).
applyAutoPerfect(state, pending.note.channel, referenceSeconds, emit);
// Pair the `hold-lane-until-beat` emitted at the head so the LN-hold timer / lane laser fade out at the tail.
emit({ kind: 'ui', command: { kind: 'long-note-end', channel: pending.note.channel, outcome: 'complete' } });
emit({ kind: 'ui', command: { kind: 'release-lane', channel: pending.note.channel } });
}
// ---- misses ---------------------------------------------------------------------------------------------------
function applyExpiredScorableJudgements(
state: JudgeCoreState,
referenceSeconds: number,
emit: JudgeCoreEffectSink,
): void {
const { config } = state;
const scorableNotes = config.scorableNotes;
const nowUs = toJudgeUs(referenceSeconds);
// Every note past its own deadline, whatever lane it is on (the deadlines differ by lane and by `#EXRANK`), missed in
// time order and, at one instant, in channel order.
// Allocated only once a note falls due: most frames miss nothing.
let due: Array<{ atUs: number; note: TimedPlayableNote }> | undefined;
for (let index = state.scorableMissCursor; index < scorableNotes.length; index += 1) {
const note = scorableNotes[index]!;
if (toJudgeUs(note.seconds) >= nowUs) {
break;
}
if (note.judged) {
continue;
}
const deadlineUs = resolveMissDeadlineUs(config, note);
if (deadlineUs < nowUs) {
(due ??= []).push({ atUs: deadlineUs, note });
}
}
if (due !== undefined) {
applyMissedScorableNotes(state, due, referenceSeconds, emit);
}
while (state.scorableMissCursor < scorableNotes.length && scorableNotes[state.scorableMissCursor]!.judged) {
state.scorableMissCursor += 1;
}
}
/** Misses the notes past their deadline, in time order and, at one instant, in channel order. */
function applyMissedScorableNotes(
state: JudgeCoreState,
due: Array<{ atUs: number; note: TimedPlayableNote }>,
referenceSeconds: number,
emit: JudgeCoreEffectSink,
): void {
const { config } = state;
due.sort((left, right) => left.atUs - right.atUs || compareJudgeChannels(left.note.channel, right.note.channel));
for (const { atUs, note } of due) {
Iif (!markScorableJudged(state, note)) {
continue;
}
startHCNPassing(state, note, atUs, emit);
if (typeof note.endBeat === 'number' && Number.isFinite(note.endBeat) && note.endBeat > note.beat) {
note.visibleUntilBeat = note.endBeat;
}
if (isJudgingClosed(state)) {
continue;
}
applyJudgeToSummary(state.summary, 'POOR', state.scoreTracker);
applyGaugeJudge(state, referenceSeconds, 'POOR', emit, 'miss');
emit({ kind: 'poor-bga', action: 'trigger', seconds: referenceSeconds });
if (!state.config.omitTraceEffects) {
emit({
kind: 'trace',
name: 'judge',
seconds: referenceSeconds,
fields: [
['result', 'POOR'],
['channel', note.channel],
['deltaMs', Math.round((referenceSeconds - note.seconds) * 1000)],
['reason', 'miss'],
],
});
}
emit({ kind: 'poor-trace', action: 'trigger', seconds: referenceSeconds });
setCombo(state, referenceSeconds, 0, 'miss', emit, 'POOR', note.channel);
// Miss-without-press: positive `signedDeltaMs` because the deadline passed without an input — the "late" band.
emit({
kind: 'judge-combo',
judge: 'POOR',
combo: state.combo,
channel: note.channel,
signedDeltaMs: (referenceSeconds - note.seconds) * 1000,
});
if (noteOwesTailMiss(config.ruleset, note)) {
applyTailMissPoor(state, referenceSeconds, emit);
if (!state.config.omitTraceEffects) {
emit({
kind: 'trace',
name: 'judge',
seconds: referenceSeconds,
fields: [
['result', 'POOR'],
['channel', note.channel],
['reason', 'charge-tail-miss'],
],
});
}
}
}
}
// ---- long notes -----------------------------------------------------------------------------------------------
export function finalizeActiveLongNote(
state: JudgeCoreState,
channel: string,
judge: TimedManualJudge,
atSeconds: number,
emit: JudgeCoreEffectSink,
): void {
const hold = state.activeLongNotes.get(channel);
const heldNote = hold?.note;
// LN settles at its tail while held, or on release. CN/HCN require a release; a missed tail stays silent.
if (heldNote?.endSoundEvent && (hold?.mode === 1 || state.longHoldReleaseSeconds.has(channel)))
emit({ kind: 'sound', source: 'long-note-end', event: heldNote.endSoundEvent, seconds: atSeconds, channel });
let passing = state.hcnPassing.get(channel);
while (passing !== undefined && passing.note !== heldNote) {
passing = passing.next;
}
if (passing !== undefined && isGoodOrBetter(judge.kind)) {
// A Hell Charge tail released at GOOD or better keeps its lane gaining until the tail passes.
passing.tailGood = true;
}
state.activeLongNotes.delete(channel);
state.longNoteSettleMs.delete(channel);
state.longHoldReleaseSeconds.delete(channel);
if (passing !== undefined) {
setHCNGaining(state, channel, toJudgeUs(atSeconds), emit);
}
// Pair the head's `hold-lane-until-beat` so the renderer fades the LN-hold timer and lane laser out right here.
emit({
kind: 'ui',
command: {
kind: 'long-note-end',
channel,
outcome: judge.kind === 'BAD' || judge.kind === 'POOR' ? 'dropped' : 'complete',
},
});
emit({ kind: 'ui', command: { kind: 'release-lane', channel } });
applyResolvedManualJudge(state, channel, judge, atSeconds, emit, true);
}
// ---- Hell Charge gauge ticks -----------------------------------------------------------------------------------
function isGoodOrBetter(kind: TimedManualJudge['kind']): boolean {
return kind === 'PERFECT' || kind === 'GREAT' || kind === 'GOOD';
}
/**
* Starts the gauge ticks of a Hell Charge note whose head was just judged at `judgedUs` (pressed, or missed at its
* deadline): they run from the later of the head and that instant until the tail passes. AUTO SCRATCH lanes have
* none.
*/
export function startHCNPassing(
state: JudgeCoreState,
note: TimedPlayableNote,
judgedUs: number,
emit: JudgeCoreEffectSink,
): void {
const { config } = state;
const endSeconds = resolveLongNoteEndSeconds(note);
if (endSeconds === undefined || resolveRulesetLongNoteMode(config.ruleset.longNoteStyle, note) !== 3) {
return;
}
Iif (config.autoScratch && (config.autoScratchChannels ?? config.scratchChannels).has(note.channel)) {
return;
}
for (let passing = state.hcnPassing.get(note.channel); passing !== undefined; passing = passing.next) {
Iif (passing.note === note) {
return;
}
}
const startUs = Math.max(toJudgeUs(note.seconds), judgedUs);
const counter = new HCNTickCounter(startUs);
const gaining = isLaneDown(state, note.channel);
counter.setGaining(gaining, startUs, () => undefined);
const passing: HCNPassingState = { note, endUs: toJudgeUs(endSeconds), counter, tailGood: false };
const chain = addHCNPassing(state.hcnPassing.get(note.channel), passing, startUs);
if (chain !== undefined) {
state.hcnPassing.set(note.channel, chain);
}
reportHCNGaining(passing, gaining, emit);
}
/**
* Tells the UI that a passing Hell Charge note switched between gaining and draining (`hell-charge` command), once per
* switch. The judge core alone sends it, from its own state, so a replay sends what the play did.
*/
function reportHCNGaining(passing: HCNPassingState, gaining: boolean, emit: JudgeCoreEffectSink): void {
const reported = gaining ? 'gaining' : 'draining';
if (passing.reported === reported) return;
passing.reported = reported;
emit({
kind: 'ui',
command: { kind: 'hell-charge', channel: passing.note.channel, beat: passing.note.beat, state: reported },
});
}
/** Re-reads whether a lane with a passing Hell Charge note gains (a key on it is down, or its tail went well). */
export function setHCNGaining(state: JudgeCoreState, channel: string, atUs: number, emit: JudgeCoreEffectSink): void {
for (let passing = state.hcnPassing.get(channel); passing !== undefined; passing = passing.next) {
const gaining = passing.tailGood || isLaneDown(state, channel);
passing.counter.setGaining(gaining, Math.min(atUs, passing.endUs), (gain, tickUs) =>
applyHCNGaugeTick(state, tickUs / 1e6, gain, emit),
);
// Past its tail a note no longer gains or drains: the next advance reports it passed.
if (atUs < passing.endUs) reportHCNGaining(passing, gaining, emit);
}
}
function isLaneDown(state: JudgeCoreState, channel: string): boolean {
return (state.laneHolds.get(channel)?.activeTokens.size ?? 0) > 0;
}
/** Runs every passing Hell Charge note's ticks up to `nowUs` (channel order), and ends those whose tail has passed. */
function advanceHCNPassing(state: JudgeCoreState, nowUs: number, emit: JudgeCoreEffectSink): void {
if (state.hcnPassing.size === 0) {
return;
}
const passings = [...state.hcnPassing.entries()].sort(([left], [right]) => compareJudgeChannels(left, right));
for (const [channel, first] of passings) {
for (let passing: HCNPassingState | undefined = first; passing !== undefined; passing = passing.next) {
passing.counter.advance(Math.min(nowUs, passing.endUs), (gain, tickUs) =>
applyHCNGaugeTick(state, tickUs / 1e6, gain, emit),
);
if (nowUs <= passing.endUs) {
state.hcnPassing.set(channel, passing);
break;
}
emit({ kind: 'ui', command: { kind: 'hell-charge', channel, beat: passing.note.beat, state: 'passed' } });
if (passing.next === undefined) {
state.hcnPassing.delete(channel);
}
}
}
}
/** The microsecond past which a charge tail still held is a missed POOR: the tail's late window closes there. */
function resolveChargeTailDeadlineUs(state: JudgeCoreState, channel: string, hold: ActiveLongNoteState): number {
return (
toJudgeUs(hold.endSeconds) + judgeWindowLateReachUs(judgeWindowsFor(state.config, channel, hold.endSeconds, true))
);
}
/**
* The judgment a long note's tail contributes. Charge modes already scored the head on the press, so the tail is its
* own judgment; LN mode defers both and resolves them into the worse of the two.
*/
function resolveLongNoteTailJudge(hold: ActiveLongNoteState, tail: TimedManualJudge): TimedManualJudge {
return hold.headScored ? tail : combineLongNoteJudges(hold.headJudge, tail);
}
function stopLongNoteSound(
hold: ActiveLongNoteState,
channel: string,
nowSec: number,
state: 'release' | 'break',
emit: JudgeCoreEffectSink,
): void {
emit({
kind: 'long-note',
seconds: nowSec,
channel,
state,
mode: hold.mode,
event: hold.note.event,
endSeconds: hold.endSeconds,
});
emit({
kind: 'stop-sound',
channel,
seconds: nowSec,
reason: state === 'release' ? 'long-note-release' : 'long-note-break',
event: hold.note.event,
});
hold.audioStopped = true;
}
const NO_ACTIVE_LONG_NOTES: readonly (readonly [string, ActiveLongNoteState])[] = [];
/**
* One judgment step at a single chart instant: long-note hold / tail resolution, auto-scratch, misses, mines and
* invisible-note expiry.
*/
export function advanceJudgeState(
state: JudgeCoreState,
nowSec: number,
nowMs: number,
emit: JudgeCoreEffectSink,
): void {
const { config } = state;
state.advancedThroughSeconds = Math.max(state.advancedThroughSeconds, nowSec);
advancePlugoutHiddenSounds(state, nowSec);
// Holds are judged on the judge clock: past an LR2 reversal it is the mirrored `t' = 2R - now`, which never reaches
// a tail beyond R — a hold spanning the reversal stays open while held and BADs on release, as in LR2
// (`LR2f.cpp:7613-7616`). Judgments, logs and UI cues keep the true clock.
const judgeSec = toJudgeClock(config, nowSec);
const judgeUs = toJudgeUs(judgeSec);
// Tails reached at one instant settle in channel order, the tie-break the replay simulator uses.
// Snapshot only while a long note is held: most frames hold none.
const holds =
state.activeLongNotes.size === 0
? NO_ACTIVE_LONG_NOTES
: [...state.activeLongNotes.entries()].sort(([left], [right]) => compareJudgeChannels(left, right));
for (const [channel, hold] of holds) {
// A long note is held while its lane is down, and while a let-go one waits out the ruleset's release margin.
const settleMs = state.heldChannels.has(channel) ? undefined : state.longNoteSettleMs.get(channel);
const isHolding = state.heldChannels.has(channel) || (settleMs !== undefined && nowMs <= settleMs);
// The tail is judged against the release instant when there was one — a frame can be hundreds of chart
// milliseconds wide at high `speed`, and quantizing to it would turn a clean release into a GOOD.
const releaseSeconds = state.longHoldReleaseSeconds.get(channel);
const tailJudgeSeconds = releaseSeconds === undefined ? judgeSec : toJudgeClock(config, releaseSeconds);
// When the tail resolves on the true clock (the release instant, or this step).
const tailAtSeconds = releaseSeconds ?? nowSec;
if (hold.mode === 1 && !isHolding && tailJudgeSeconds < hold.endSeconds) {
Eif (!hold.audioStopped) {
stopLongNoteSound(hold, channel, nowSec, 'release', emit);
}
// Let go before the tail: the ruleset decides whether that is a BAD or keeps (or worsens) the head judgment.
finalizeActiveLongNote(
state,
channel,
resolveLongNoteEarlyReleaseJudge(
config.ruleset,
hold.headJudge,
(tailJudgeSeconds - hold.endSeconds) * 1000,
judgeWindowsFor(config, channel, tailJudgeSeconds, true),
),
tailAtSeconds,
emit,
);
continue;
}
// A tail settles once time has moved past it (whole microseconds, like every timed judgment).
if (judgeUs > toJudgeUs(hold.endSeconds)) {
const heldTail = config.ruleset.heldChargeTail;
if (
heldTail !== undefined &&
isChargeLongNoteMode(hold.mode) &&
isHolding &&
config.scratchChannels.has(channel)
) {
// plugout: a scratch still held reaches its tail as a PGREAT, without a release (0x440d75).
emit({
kind: 'long-note',
seconds: nowSec,
channel,
state: 'complete',
mode: hold.mode,
event: hold.note.event,
endSeconds: hold.endSeconds,
});
const signedDeltaMs = (judgeSec - hold.endSeconds) * 1000;
finalizeActiveLongNote(
state,
channel,
resolveLongNoteTailJudge(hold, { kind: 'PERFECT', signedDeltaMs }),
nowSec,
emit,
);
continue;
}
if (
isChargeLongNoteMode(hold.mode) &&
(isHolding || hold.backSpinScratch === true) &&
judgeUs <= resolveChargeTailDeadlineUs(state, channel, hold)
) {
// Charge modes judge the tail on the RELEASE. Still holding past the tail is not yet a judgment — the player
// has until the tail's late window closes to let go, exactly as the replay simulator models it.
continue;
}
if (hold.mode === 1) {
emit({
kind: 'long-note',
seconds: nowSec,
channel,
state: 'complete',
mode: hold.mode,
event: hold.note.event,
endSeconds: hold.endSeconds,
});
finalizeActiveLongNote(state, channel, hold.headJudge, nowSec, emit);
continue;
}
emit({
kind: 'long-note',
seconds: nowSec,
channel,
state: 'complete',
mode: hold.mode,
event: hold.note.event,
endSeconds: hold.endSeconds,
});
// A charge tail that was never let go is a missed POOR, whether the hold broke (HCN) or ran past the tail's late
// window: only a release is judged against the windows (beatoraja's `CN end poor`). A back-spin scratch's tail
// that was never spun back is missed the same way, held or not.
// plugout: a key held past its tail's late window is a BAD, not a missed POOR (0x440d75).
const finalJudge =
isChargeLongNoteMode(hold.mode) && releaseSeconds === undefined
? resolveLongNoteTailJudge(hold, {
kind: heldTail !== undefined ? heldTail.note : 'POOR',
signedDeltaMs: (judgeSec - hold.endSeconds) * 1000,
})
: resolveLongNoteTailJudge(
hold,
resolveManualTimedJudge(
(tailJudgeSeconds - hold.endSeconds) * 1000,
judgeWindowsFor(config, channel, tailJudgeSeconds, true),
),
);
finalizeActiveLongNote(state, channel, finalJudge, tailAtSeconds, emit);
continue;
}
// A back-spin scratch's tail waits for the reverse spin (`judgeBackSpinScratchTail`): letting go settles nothing,
// unless the release ended it (beatoraja's early POOR release, which records the release instant).
if (
isChargeLongNoteMode(hold.mode) &&
!isHolding &&
(hold.backSpinScratch !== true || releaseSeconds !== undefined)
) {
Eif (!hold.audioStopped) {
stopLongNoteSound(hold, channel, nowSec, 'release', emit);
}
const released = resolveManualTimedJudge(
(tailJudgeSeconds - hold.endSeconds) * 1000,
judgeWindowsFor(config, channel, tailJudgeSeconds, true),
);
// plugout: a release before the tail's windows is a BAD ("RELASE TOO FAST"), not a missed POOR.
const earlyRelease = config.ruleset.heldChargeTail?.earlyRelease;
finalizeActiveLongNote(
state,
channel,
resolveLongNoteTailJudge(
hold,
earlyRelease !== undefined && released.kind === 'POOR' && released.signedDeltaMs < 0
? { ...released, kind: earlyRelease }
: released,
),
tailAtSeconds,
emit,
);
}
}
advanceHCNPassing(state, toJudgeUs(nowSec), emit);
// Clamped to the reversal: notes whose miss deadline falls before it are still missed on time, while everything past
// it stays unjudged forever — matching LR2's frozen judge pump.
applyAutoScratchJudgements(state, clampToReversal(config, nowSec), emit);
applyExpiredScorableJudgements(state, clampToReversal(config, nowSec), emit);
processLandminePassage(state, nowSec, nowMs, emit);
markExpiredInvisibleNotes(state, nowSec);
}
/**
* The earliest microsecond, at or after `afterUs`, at which a timed judgment falls due: a long-note tail, a charge
* tail's late window or a release waiting to settle, an AUTO SCRATCH note or tail, a miss deadline, a mine check. A
* judgment falls due once time has moved past its microsecond, so a replay that steps to the microsecond after each
* settles one instant per step, in the same order as the replay simulator. `Infinity` when nothing is pending.
*/
export function nextTimedJudgmentUs(state: JudgeCoreState, afterUs: number): number {
const { config } = state;
const reversalUs =
config.reversalSeconds === undefined ? Number.POSITIVE_INFINITY : toJudgeUs(config.reversalSeconds);
let next = Number.POSITIVE_INFINITY;
const consider = (atUs: number): void => {
if (atUs >= afterUs && atUs < next) {
next = atUs;
}
};
for (const [channel, hold] of state.activeLongNotes) {
const settleMs = state.longNoteSettleMs.get(channel);
if (!state.heldChannels.has(channel) && settleMs !== undefined && Number.isFinite(settleMs)) {
consider(toJudgeUs(settleMs / config.judgeMsPerChartSecond));
}
if (toJudgeUs(hold.endSeconds) >= reversalUs) {
// The mirrored judge clock never reaches a tail past the LR2 reversal.
continue;
}
consider(toJudgeUs(hold.endSeconds));
if (isChargeLongNoteMode(hold.mode)) {
consider(resolveChargeTailDeadlineUs(state, channel, hold));
}
}
for (const passing of state.hcnPassing.values()) {
consider(Math.min(passing.counter.nextTickUs(), passing.endUs));
}
for (const pending of state.pendingAutoScratchLongNotes) {
if (toJudgeUs(pending.endSeconds) < reversalUs) consider(toJudgeUs(pending.endSeconds));
}
if (config.autoScratch) {
for (let index = state.autoScratchCursor; index < state.autoScratchNotes.length; index += 1) {
const note = state.autoScratchNotes[index]!;
Eif (!note.judged && toJudgeUs(note.seconds) >= afterUs) {
Eif (toJudgeUs(note.seconds) < reversalUs) consider(toJudgeUs(note.seconds));
break;
}
}
}
const scorableNotes = config.scorableNotes;
for (let index = state.scorableMissCursor; index < scorableNotes.length; index += 1) {
const note = scorableNotes[index]!;
if (toJudgeUs(note.seconds) > next) {
break;
}
if (note.judged) {
continue;
}
const deadlineUs = resolveMissDeadlineUs(config, note);
if (deadlineUs < reversalUs) consider(deadlineUs);
}
const landmineNotes = config.landmineNotes;
for (let index = state.landmineExpireCursor; index < landmineNotes.length; index += 1) {
const landmine = landmineNotes[index]!;
const mineUs = toJudgeUs(landmine.seconds);
if (mineUs >= reversalUs || mineUs - LANDMINE_SCAN_AHEAD_US > next) {
break;
}
if (landmine.judged) {
continue;
}
consider(mineUs);
}
return next;
}
/**
* Safety net for notes the per-step sweep never reached (an audio tail that outran the loop, a hold still open at the
* end). Counted from the notes themselves rather than from `summary.total`: the total is the ruleset's EX-SCORE
* denominator, and under That-Which-Must-Not-Be-Named a missed charge note owes only ONE judgment even though it counts for two.
*/
export function finishJudgeState(state: JudgeCoreState, totalSeconds: number, emit: JudgeCoreEffectSink): void {
const { config } = state;
if (isJudgingClosed(state)) {
// A play that ended on failure leaves the rest of the chart unjudged; no end-of-play rule applies.
return;
}
const { ruleset, reversalSeconds } = config;
// Settle every timed judgment still pending — misses, tails, AUTO SCRATCH, mines, Hell Charge ticks — each at its
// own instant, as the replay simulator does when its clock runs out.
for (let afterUs = Number.NEGATIVE_INFINITY; ;) {
const nextUs = nextTimedJudgmentUs(state, afterUs);
if (!Number.isFinite(nextUs)) {
break;
}
const stepSec = (nextUs + 1) / 1e6;
advanceJudgeState(state, stepSec, stepSec * config.judgeMsPerChartSecond, emit);
afterUs = nextUs + 1;
}
let missingCount = 0;
// Notes the LR2 negative-BPM reversal left unreachable (#134). LR2 never misses them — its mirrored judge clock
// recedes before their deadline — and zeroes HP when the play ends with them outstanding.
let outstandingPastReversal = false;
for (const note of config.scorableNotes) {
if (note.judged) {
continue;
}
note.judged = true;
Eif (reversalSeconds !== undefined && note.seconds + resolveMissDeadlineSeconds(config, note) >= reversalSeconds) {
outstandingPastReversal = true;
continue;
}
missingCount += 1;
if (noteOwesTailMiss(ruleset, note)) {
missingCount += 1;
}
}
if (reversalSeconds !== undefined && state.pendingAutoScratchLongNotes.length > 0) {
// An AUTO SCRATCH long note whose tail lies past the reversal is never cleared either.
outstandingPastReversal = true;
}
for (const hold of state.activeLongNotes.values()) {
Eif (reversalSeconds !== undefined) {
// A hold still open at the end of a reversed run spans the reversal: the mirrored clock never reaches its tail,
// so LR2 never judges it.
outstandingPastReversal = true;
continue;
}
// The head already scored; only the unresolved tail is outstanding.
if (hold.headScored) {
missingCount += 1;
}
}
state.activeLongNotes.clear();
Iif (missingCount > 0) {
chargeRemainingNotes(state, totalSeconds, missingCount, emit);
}
if (outstandingPastReversal) {
// LR2 sets HP = 0 when a play ends with notes unjudged (OpenLR2 `LR2f.cpp:12980-12982`, LR2body.exe 0x42c525), so
// a reversed run that leaves notes behind is always FAILED.
drainGaugeAtReversalEnd(state, totalSeconds, emit);
}
}
/** Empties the gauge at the end of a reversed run with notes outstanding (see {@link finishJudgeState}). */
function drainGaugeAtReversalEnd(state: JudgeCoreState, totalSeconds: number, emit: JudgeCoreEffectSink): void {
state.drainGaugeToZero();
if (!state.config.omitTraceEffects) {
emit({
kind: 'trace',
name: 'gauge',
seconds: totalSeconds,
fields: [
['value', 0],
['reason', 'notes-outstanding-past-reversal'],
],
});
}
emit({ kind: 'frame', seconds: totalSeconds });
}
function chargeRemainingNotes(
state: JudgeCoreState,
totalSeconds: number,
missingCount: number,
emit: JudgeCoreEffectSink,
): void {
for (let index = 0; index < missingCount; index += 1) {
applyJudgeToSummary(state.summary, 'POOR', state.scoreTracker);
applyGaugeJudge(state, totalSeconds, 'POOR', emit, 'remaining-notes');
}
emit({ kind: 'poor-bga', action: 'trigger', seconds: totalSeconds });
if (!state.config.omitTraceEffects) {
emit({
kind: 'trace',
name: 'judge',
seconds: totalSeconds,
fields: [
['result', 'POOR'],
['reason', 'remaining-notes'],
['count', missingCount],
],
});
}
emit({ kind: 'poor-trace', action: 'trigger', seconds: totalSeconds });
setCombo(state, totalSeconds, 0, 'remaining-notes', emit, 'POOR');
emit({ kind: 'judge-combo', judge: 'POOR', combo: state.combo, poor: 'remaining' });
emit({ kind: 'frame', seconds: totalSeconds });
}
|