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 | 9x 9x 9x 5x 25x 25x 12x 9x 23x 19x 18x 17x 15x 3x 12x 9x 9x 6x 14x 7x 6x 6x 4x 3x 3x 1x 1x 3x 1x 1x 1x 2x 1x 1x 1x 11x 3x 2x 10x 9x 6x 6x 4x 3x 3x 1x 12x 8x 8x 5x 2x 8x 7x 6x 6x 8x | // The replay ghost's play options (the Options dialog's Replay / ghost folder) and its sources. "Ghost" picks the replay a
// ghost plays: none (OFF), the player's own best on the chart (the replay slot keeping the highest EX score, which the
// default auto-save rule of slot 1 keeps up to date), one replay slot, the Leaderboard's top run on the chart, or a
// replay file the player picked. "Ghost mode" picks how it shows: a second playfield, a pacemaker alone, or a pacemaker
// with the recorded inputs over the player's own lanes. Whether a play can show the pick is worked out here, so the
// Options dialog can say why not, and the play route asks for a ghost only where it shows.
import type { GhostPresentationMode, GhostSource } from '@be-music/player-browser/host';
import type { ChartPlayVariant } from '@be-music/chart-model';
import type { BeMusicReplay } from '@be-music/player-engine/replay';
import {
replaySlotTargetOfReplay,
type ReplaySlotList,
type ReplaySlotRecord,
type ReplaySlotStore,
type ReplaySlotTarget,
} from './replay-slots.ts';
/** The "Ghost" option: which replay a ghost plays, or none. */
export const GHOST_SOURCES = [
'OFF',
'OWN_BEST',
'REPLAY_SLOT_1',
'REPLAY_SLOT_2',
'REPLAY_SLOT_3',
'REPLAY_SLOT_4',
'LEADERBOARD_TOP',
'REPLAY_FILE',
] as const;
export type GhostSourceSetting = (typeof GHOST_SOURCES)[number];
/** The "Ghost mode" option: how the ghost shows (see `GhostPresentationMode`). */
export const GHOST_MODES = ['PLAYFIELD', 'PACEMAKER', 'LANE_OVERLAY'] as const;
export type GhostModeSetting = (typeof GHOST_MODES)[number];
const PRESENTATION_MODES: Readonly<Record<GhostModeSetting, GhostPresentationMode>> = {
PLAYFIELD: 'side-playfield',
PACEMAKER: 'pacemaker',
LANE_OVERLAY: 'lane-overlay',
};
/** The play session's presentation mode for a "Ghost mode" setting. */
export function toGhostPresentationMode(mode: GhostModeSetting): GhostPresentationMode {
return PRESENTATION_MODES[mode];
}
/** The replay slot (0-based) a "Ghost" setting names, or `undefined` for another source. */
export function ghostReplaySlotOf(source: GhostSourceSetting): number | undefined {
const match = /^REPLAY_SLOT_(\d)$/.exec(source);
return match === null ? undefined : Number(match[1]) - 1;
}
/** Whether a mode draws a field of its own, which only the built-in family has room for. */
export function ghostModeDrawsOnPlayfield(mode: GhostModeSetting): boolean {
return mode !== 'PACEMAKER';
}
/** The play variants a second playfield has room beside: the single-play 5 / 7 KEY charts, whose 2P side it takes. */
const SIDE_PLAYFIELD_VARIANTS: ReadonlySet<ChartPlayVariant> = new Set(['5', '7']);
/** What decides whether a play can show the picked ghost. */
export interface GhostAvailabilityInput {
/** How the ghost would show. */
readonly mode: GhostModeSetting;
/** The family drawing the play: only the built-in one has room for a field of the ghost's own. */
readonly family: 'built-in' | 'lr2' | 'beatoraja';
/** The chart's play variant; absent for a course bar or a folder. */
readonly playVariant?: ChartPlayVariant;
/** A replay plays back instead of the player. */
readonly replay?: boolean;
/** A course stage or a NONSTOP run. */
readonly course?: boolean;
/** A battle mode (LR2 BATTLE, SP TO DP, ...) other than OFF: the chart becomes a double-play one. */
readonly battle?: boolean;
/** Whether the picked source holds a replay of the chart; `undefined` when that is only known once read. */
readonly hasReplay?: boolean;
}
/** Why a play cannot show the picked ghost; `undefined` when it can. */
export type GhostUnavailableReason = 'family' | 'replay' | 'course' | 'chart' | 'no-replay';
/** Why a play described by `input` cannot show the picked ghost, or `undefined` when it can. */
export function resolveGhostUnavailableReason(input: GhostAvailabilityInput): GhostUnavailableReason | undefined {
if (input.family !== 'built-in' && ghostModeDrawsOnPlayfield(input.mode)) return 'family';
if (input.replay === true) return 'replay';
if (input.course === true) return 'course';
if (input.playVariant === undefined) return 'chart';
if (input.mode === 'PLAYFIELD' && (input.battle === true || !SIDE_PLAYFIELD_VARIANTS.has(input.playVariant)))
return 'chart';
if (input.hasReplay === false) return 'no-replay';
return undefined;
}
/** What the Options dialog says of a ghost the bar under the cursor cannot show. */
export const GHOST_UNAVAILABLE_LABELS: Readonly<Record<GhostUnavailableReason, string>> = {
family: 'Built-in skins only',
replay: 'Not in a replay',
course: 'Not on a course',
chart: 'Not on this chart',
'no-replay': 'No replay kept',
};
/** The slot keeping the player's best: the highest EX score, the latest save among equals; `undefined` when empty. */
export function selectOwnBestReplaySlot(slots: ReplaySlotList): ReplaySlotRecord | undefined {
let best: ReplaySlotRecord | undefined;
for (const record of slots) {
if (record === undefined || record.target.kind !== 'chart') continue;
if (
best === undefined ||
record.exScore > best.exScore ||
(record.exScore === best.exScore && record.savedAt > best.savedAt)
)
best = record;
}
return best;
}
/** The ghost source of the player's own best on the chart `target` names, read from `store` when the play loads. */
export function createOwnBestGhostSource(
store: Pick<ReplaySlotStore, 'slots' | 'read'>,
target: ReplaySlotTarget,
): GhostSource {
return {
kind: 'own-best',
label: 'MY GHOST',
async load() {
const best = selectOwnBestReplaySlot(store.slots(target));
if (best === undefined) return undefined;
const payload = await store.read(target, best.slot);
return payload?.kind === 'chart' ? payload.replay : undefined;
},
};
}
/** The ghost source of replay slot `slot` (0-based) of the chart `target` names. */
export function createReplaySlotGhostSource(
store: Pick<ReplaySlotStore, 'read'>,
target: ReplaySlotTarget,
slot: number,
): GhostSource {
return {
kind: 'replay-slot',
label: `SLOT ${slot + 1}`,
async load() {
const payload = await store.read(target, slot);
return payload?.kind === 'chart' ? payload.replay : undefined;
},
};
}
/** The ghost source of the Leaderboard's top run on the chart, fetched by `fetchTopReplay` when the play loads. */
export function createLeaderboardGhostSource(fetchTopReplay: () => Promise<BeMusicReplay | undefined>): GhostSource {
return { kind: 'leaderboard', label: 'TOP', load: fetchTopReplay };
}
/**
* The replay file the player picked as a ghost (Options dialog → Replay / ghost → "Ghost replay file…"), held for this
* visit only. It is the ghost of the chart it was recorded on, wherever "Ghost" is REPLAY FILE.
*/
export class GhostReplayFile {
private picked: { readonly replay: BeMusicReplay; readonly name: string; readonly target?: string } | undefined;
/** The picked file's name, for the menu; `undefined` before one is picked. */
public get name(): string | undefined {
return this.picked?.name;
}
public set(replay: BeMusicReplay, name: string): void {
const target = replaySlotTargetOfReplay(replay)?.id;
this.picked = { replay, name, ...(target !== undefined ? { target } : {}) };
}
public clear(): void {
this.picked = undefined;
}
/** The picked replay when it was recorded on the chart `target` names. */
public replayFor(target: ReplaySlotTarget | undefined): BeMusicReplay | undefined {
if (this.picked === undefined || target === undefined || this.picked.target !== target.id) return undefined;
return this.picked.replay;
}
}
/** The ghost source of the picked replay file, for the chart `target` names. */
export function createReplayFileGhostSource(
file: Pick<GhostReplayFile, 'replayFor'>,
target: ReplaySlotTarget,
): GhostSource {
return { kind: 'replay-file', label: 'FILE', load: () => Promise.resolve(file.replayFor(target)) };
}
/** Where the ghost sources read from. */
export interface GhostSourceDeps {
/** The replay slots the own best and a slot are read from. */
readonly replays?: Pick<ReplaySlotStore, 'slots' | 'read'>;
/** Fetches the Leaderboard's top run on a chart, by its chart fingerprint. */
readonly fetchLeaderboardTopReplay?: (chartFingerprint: string) => Promise<BeMusicReplay | undefined>;
/** The picked replay file. */
readonly replayFile?: Pick<GhostReplayFile, 'replayFor'>;
}
/** The ghost source a "Ghost" setting names for the chart `target` names, or `undefined` when there is none to read. */
export function createGhostSource(
setting: GhostSourceSetting,
target: ReplaySlotTarget,
deps: GhostSourceDeps,
): GhostSource | undefined {
if (setting === 'OFF') return undefined;
if (setting === 'OWN_BEST') return deps.replays && createOwnBestGhostSource(deps.replays, target);
const slot = ghostReplaySlotOf(setting);
if (slot !== undefined) return deps.replays && createReplaySlotGhostSource(deps.replays, target, slot);
if (setting === 'REPLAY_FILE') return deps.replayFile && createReplayFileGhostSource(deps.replayFile, target);
// The Leaderboard keys charts by their chart fingerprint; a chart with only a file hash is not on it.
const fetchTop = deps.fetchLeaderboardTopReplay;
if (fetchTop === undefined || target.id.startsWith('sha256:')) return undefined;
return createLeaderboardGhostSource(() => fetchTop(target.id));
}
/**
* Whether the source a "Ghost" setting names holds a replay of the chart, as far as is known without reading it:
* `exists` lists which replay slots of the chart are kept. A Leaderboard run is only known once fetched (`undefined`).
*/
export function ghostSourceHasReplay(
setting: Exclude<GhostSourceSetting, 'OFF'>,
exists: readonly boolean[],
replayFile: boolean,
): boolean | undefined {
if (setting === 'OWN_BEST') return exists.some(Boolean);
const slot = ghostReplaySlotOf(setting);
if (slot !== undefined) return exists[slot] === true;
if (setting === 'REPLAY_FILE') return replayFile;
return undefined;
}
/** What the select screen knows of the bar under the cursor, for whether a ghost would show on it. */
export interface GhostBarFacts extends Omit<GhostAvailabilityInput, 'mode' | 'hasReplay'> {
/** The bar's chart as the replay slots and the ghost sources name it; absent for a course or a folder. */
readonly target?: ReplaySlotTarget;
/** Which replay slots of the chart are kept. */
readonly slotsKept: readonly boolean[];
}
/**
* What the Options dialog's "Ghost status" row says for the picked source and mode on the bar `facts` describe: `OFF`, why
* the bar would show no ghost, or `READY` (a Leaderboard run is only known once fetched, so it reads `READY` too).
*/
export function resolveGhostStatus(
source: GhostSourceSetting,
mode: GhostModeSetting,
facts: GhostBarFacts | undefined,
replayFile: Pick<GhostReplayFile, 'replayFor'>,
): string {
if (source === 'OFF') return 'OFF';
if (facts === undefined) return '-';
const hasReplay = ghostSourceHasReplay(source, facts.slotsKept, replayFile.replayFor(facts.target) !== undefined);
const reason = resolveGhostUnavailableReason({
...facts,
mode,
...(hasReplay !== undefined ? { hasReplay } : {}),
});
return reason === undefined ? 'READY' : GHOST_UNAVAILABLE_LABELS[reason];
}
|