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 | 4x 4x 12x 4x 4x 20x 12x 38x 24x 168x 24x 20x 18x 18x 2x 1x 16x 15x 3x 210x | // Browser-side wiring for beatoraja themes.
//
// Mirrors `loadLR2ThemeSkinsFromFiles` from `@be-music/skin-lr2` so the host UI can keep its LR2 code path and pick
// up beatoraja themes through a parallel surface. The parser pipeline lives in `@be-music/skin-beatoraja`; this file
// only wires the dropped-File array up to that pipeline and doesn't open any PixiJS resources.
import {
asLoadedBytes,
discoverBeatorajaTheme,
loadAssetBytes,
pickBeatorajaPlaySkinVariant,
readFilesIntoBytesMap,
} from '@be-music/skin-beatoraja';
import { pickBeatorajaThemeBGMPaths } from '@be-music/skin-beatoraja/scene';
import type {
BeatorajaPlaySkinMap,
BeatorajaPlayVariant,
BeatorajaSkinConfig,
BeatorajaSkinEntry,
BeatorajaSkinFileEntry,
BeatorajaSkinHeader,
BeatorajaSkinInputFile,
BeatorajaTheme,
BeatorajaThemeDiscoveryWarning,
} from '@be-music/skin-beatoraja';
import type { ChartPlayVariant } from '@be-music/chart-model';
import type { LoadProgressCallback } from '../../collection/types.ts';
/** Single discovered skin entry, sized to live alongside its loaded byte map. */
export interface BeatorajaThemeBundle {
/** All files the user dropped, indexed by case-insensitive lookup key. */
files: ReadonlyMap<string, BeatorajaSkinFileEntry>;
/** Per-scene entries discovered from the bundle. */
theme: BeatorajaTheme;
/** Entries the discovery pass failed to parse. Surfaced for diagnostics; consumers can keep going. */
warnings: ReadonlyArray<BeatorajaThemeDiscoveryWarning>;
}
export interface LoadBeatorajaThemeOptions {
/**
* Optional progress hook fired as files are read. The bundle parser is fast (<50ms for the reference theme), so the
* dominant cost is reading file bytes off disk; the callback fires once per file as the read completes.
*/
onProgress?: LoadProgressCallback;
}
/**
* Read the dropped theme files into memory and discover every skin entry inside. Returns the
* file map alongside the discovered theme so the caller can pass both to `loadBeatorajaSkin`
* (from `@be-music/skin-beatoraja`) once the user picks a scene + variant.
*/
export async function loadBeatorajaThemeFromFiles(
files: ReadonlyArray<BeatorajaSkinInputFile>,
options: LoadBeatorajaThemeOptions = {},
): Promise<BeatorajaThemeBundle> {
const total = files.length;
const fileMap = await readFilesIntoBytesMap(files, {
shouldDefer: shouldDeferBeatorajaThemeFile,
onRead: (_path, current) => {
options.onProgress?.({ phase: 'reading', current, total });
},
});
const { theme, warnings } = discoverBeatorajaTheme(fileMap);
return { files: fileMap, theme, warnings };
}
const EAGER_BEATORAJA_THEME_EXTENSIONS = [
'.json',
'.luaskin',
'.lua',
'.png',
'.jpg',
'.jpeg',
'.bmp',
'.gif',
'.webp',
'.tga',
'.svg',
] as const;
function shouldDeferBeatorajaThemeFile(path: string): boolean {
// Whole beatoraja folder drops often include JRE/runtime artifacts. Keep only skin scripts and
// images eager; fonts/audio/other files are loaded on demand by their dedicated loaders.
const lower = path.toLowerCase();
return !EAGER_BEATORAJA_THEME_EXTENSIONS.some((extension) => lower.endsWith(extension));
}
/**
* Compact textual summary of the play skins inside a bundle. Useful for logging "loaded play=7,14" lines next to the
* LR2 equivalent.
*/
export function summarizeBeatorajaPlaySkins(playSkins: BeatorajaPlaySkinMap, separator = ','): string {
const variants: BeatorajaPlayVariant[] = ['7', '5', '14', '10', '9', '24', '24d'];
const present = variants.filter((v) => playSkins[v] !== undefined);
return present.join(separator);
}
/**
* Play variants the renderer is willing to mount — every variant beatoraja themes author, including the 24-key
* keyboard modes. Charts reach those through the extended `1A..1O` / `2A..2O` lane channels (`ChartPlayVariant`
* `'24'` / `'48'`), and the play bridge addresses their lanes via the `1000`-block timer bases upstream's
* `play24main.lua` uses.
*
* If the dropped theme doesn't ship the variant a chart needs, {@link pickBeatorajaPlayableSkinVariant} chains
* through the closest substitutes — same shape as `pickLR2PlaySkin` on the LR2 side.
*/
const BEATORAJA_PLAYABLE_VARIANTS = ['7', '5', '9', '10', '14', '24', '24d'] as const;
export type BeatorajaPlayableVariant = (typeof BEATORAJA_PLAYABLE_VARIANTS)[number];
/**
* Map a chart's key count + double-play flag to the corresponding beatoraja play variant. Mirrors the logic
* `pickLR2PlaySkin` uses on the LR2 side. Returns `undefined` for chart shapes the renderer doesn't support.
*/
export function pickBeatorajaPlayableVariant(chart: {
keys: number;
isDouble: boolean;
isPMS: boolean;
}): BeatorajaPlayableVariant | undefined {
Iif (chart.isPMS) return '9';
if (chart.isDouble) {
if (chart.keys === 24) return '24d';
Eif (chart.keys === 14) return '14';
if (chart.keys === 10) return '10';
return undefined;
}
if (chart.keys === 24) return '24';
Eif (chart.keys === 7) return '7';
if (chart.keys === 5) return '5';
return undefined;
}
/**
* Beatoraja play-skin variant → `ChartPlayVariant` (the engine / lane-layout vocabulary). The two spellings differ
* only for the keyboard DP mode: beatoraja names its skin `'24d'` (24 keys, double), while the chart classifier
* reports the total lane count as `'48'`.
*/
export function chartPlayVariantForBeatorajaVariant(variant: BeatorajaPlayableVariant): ChartPlayVariant {
return variant === '24d' ? '48' : variant;
}
/**
* The variant whose skin plays a `desired` chart: `desired` when the theme ships it, otherwise the closest substitute
* down the fallback list of `pickBeatorajaPlaySkinVariant` (`@be-music/skin-beatoraja`), which this calls. Many themes
* ship only the 7-keys variant and let the other charts re-use it. Returns `undefined` when the theme has no play skin
* at all.
*/
export function pickBeatorajaPlayableSkinVariant(
playSkins: BeatorajaPlaySkinMap,
desired: BeatorajaPlayableVariant,
): BeatorajaPlayableVariant | undefined {
return pickBeatorajaPlaySkinVariant(playSkins, desired);
}
export type {
BeatorajaPlaySkinMap,
BeatorajaPlayVariant,
BeatorajaSkinConfig,
BeatorajaSkinEntry,
BeatorajaSkinHeader,
BeatorajaTheme,
};
/** BGM byte arrays discovered inside a beatoraja theme bundle. Each slot is a decoded WAV / OGG / MP3
* payload ready to hand to `AudioContext.decodeAudioData`. Slots are `undefined` when no matching
* file exists in the dropped tree.
*/
export interface BeatorajaThemeBGM {
/** Splash audio for the decide scene — typically `decide.wav` / `*decide*.wav`. */
decide?: Uint8Array;
/** Result-scene jingle for cleared runs — `clear.wav`. */
clear?: Uint8Array;
/** Result-scene jingle for failed runs — `fail.wav`. */
fail?: Uint8Array;
/** Generic result jingle — `result.wav`. Used when neither `clear` nor `fail` matched the outcome. */
result?: Uint8Array;
/**
* Course-result jingle for a cleared course — `course_clear.wav` (beatoraja `SystemSoundManager.COURSE_CLEAR`).
* beatoraja falls back to the {@link clear} one without it.
*/
courseClear?: Uint8Array;
/** Course-result jingle for a failed course — `course_fail.wav`, falling back to {@link fail}. */
courseFail?: Uint8Array;
/** Played as a result screen starts to fade out, stopping its jingle — `resultclose.wav` (`RESULT_CLOSE`). */
resultClose?: Uint8Array;
/** Played as a course result starts to fade out — `course_close.wav` (`COURSE_CLOSE`), falling back to {@link resultClose}. */
courseClose?: Uint8Array;
}
/**
* Scan a beatoraja theme bundle for BGM files. The lookup is heuristic — beatoraja's spec doesn't
* pin BGM to a fixed path, so the file stems are matched against the conventional names (see
* `pickBeatorajaThemeBGMPaths` in `@be-music/skin-beatoraja/scene`).
*
* Returns synchronously when every matched entry was eagerly loaded. When some entries are
* deferred (lazy file readers), the helper awaits each `loadAssetBytes` call serially — each BGM
* is small enough (<1 MiB) that the latency is negligible, and serializing avoids spawning a
* concurrent read storm on the dropped-file IO layer.
*/
export async function findBeatorajaThemeBGM(bundle: BeatorajaThemeBundle): Promise<BeatorajaThemeBGM> {
const out: BeatorajaThemeBGM = {};
for (const [slot, path] of Object.entries(pickBeatorajaThemeBGMPaths(bundle.files.keys()))) {
const entry = bundle.files.get(path);
const bytes = asLoadedBytes(entry) ?? (await loadAssetBytes(entry));
if (bytes !== undefined) out[slot as keyof BeatorajaThemeBGM] = bytes;
}
return out;
}
|