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 | 92x 1435x 25x 29x 26x 22x 11x 11x 63x 27x 27x 11x 16x 16x 16x 25x 22x 3x 16x 16x 16x 28x 28x 2x 26x 43x 43x 66x 37x 43x 12x 31x 6x 28x 43x 43x 48x 38x 10x 5x 1511x 1511x | import { dirname, normalizePath } from '@be-music/shared-utils/core';
export interface BrowserDropFileLike {
readonly name: string;
readonly webkitRelativePath?: string;
}
export interface SplitDroppedSongAndThemeFilesResult<TFile extends BrowserDropFileLike> {
themeFiles: TFile[];
chartFiles: TFile[];
}
const CHART_EXTENSIONS = new Set(['.bms', '.bme', '.bml', '.pms', '.bmson', '.n2s', '.lrs']);
export function isChartFilePath(path: string): boolean {
return CHART_EXTENSIONS.has(extensionOf(path));
}
/**
* `true` when the dropped file looks like an LR2 skin entry. Used to gate the LR2 theme loader so a stray text file
* inside a chart pack doesn't reset the active theme to "no LR2 theme".
*/
export function isLR2SkinFilePath(path: string): boolean {
return extensionOf(path) === '.lr2skin';
}
/**
* `true` when the dropped file looks like a beatoraja Lua skin entry. We treat `.luaskin` as the unambiguous marker;
* `.json` is too generic to count by itself (charts ship `score.json`, packs ship `info.json`, etc.). The discovery
* pass inspects neighbouring `.json` files once a `.luaskin` is confirmed.
*/
export function isBeatorajaLuaSkinFilePath(path: string): boolean {
return extensionOf(path) === '.luaskin';
}
/**
* Heuristic for "this dropped folder probably contains a beatoraja skin theme". Used to gate the beatoraja theme
* loader the same way {@link isLR2SkinFilePath} gates LR2's. Triggers on:
*
* - any `.luaskin` file (definitive),
* - or a `.json` file whose path includes a `skin/` segment (matches the standard `beatoraja/skin/<name>/…` layout).
*/
export function isBeatorajaSkinIndicator(path: string): boolean {
if (isBeatorajaLuaSkinFilePath(path)) return true;
if (extensionOf(path) !== '.json') return false;
const lower = path.toLowerCase();
return lower.includes('/skin/') || lower.startsWith('skin/');
}
export function resolveDropFilePath(file: BrowserDropFileLike): string {
return normalizePath(file.webkitRelativePath || file.name);
}
export function splitDroppedChartAndThemeFiles<TFile extends BrowserDropFileLike>(
files: readonly TFile[],
): SplitDroppedSongAndThemeFilesResult<TFile> {
const isChartPath = createChartPathMatcher(files.map(resolveDropFilePath));
if (!isChartPath) {
return { themeFiles: [...files], chartFiles: [] };
}
const themeFiles: TFile[] = [];
const chartFiles: TFile[] = [];
for (const file of files) {
if (isChartPath(resolveDropFilePath(file))) {
chartFiles.push(file);
} else {
themeFiles.push(file);
}
}
return { themeFiles, chartFiles };
}
/**
* Returns a predicate telling which dropped paths must be opened as soon as the drop lands: everything that
* {@link splitDroppedChartAndThemeFiles} would route to the theme side, replays (`.bmplay.json`) and archives
* (`.zip`). The remaining paths are song-bundle files — charts, audio, BGA — which the song loader only reads on
* demand, so the drop walk can leave them as unopened handles instead of paying a `FileSystemFileEntry.file()` call
* for each of them up front.
*/
export function createEagerDropPathPredicate(paths: readonly string[]): (path: string) => boolean {
const isChartPath = createChartPathMatcher(paths);
return (path) => {
const lower = path.toLowerCase();
if (lower.endsWith('.bmplay.json') || lower.endsWith('.zip')) {
return true;
}
return !isChartPath?.(path);
};
}
/**
* Builds the "is this path inside a chart directory?" test shared by the drop helpers. `undefined` when no chart was
* dropped, in which case every path counts as a theme candidate.
*/
function createChartPathMatcher(paths: readonly string[]): ((path: string) => boolean) | undefined {
const chartDirectoryPrefixes = new Set<string>();
for (const path of paths) {
if (isChartFilePath(path)) {
chartDirectoryPrefixes.add(dirname(path));
}
}
if (chartDirectoryPrefixes.size === 0) {
return undefined;
}
if (chartDirectoryPrefixes.has('')) {
return () => true;
}
return (path) => {
// Walk the path's own ancestors instead of scanning every chart directory, so a pack with hundreds of song
// folders stays linear in the number of dropped files.
let slash = path.lastIndexOf('/');
while (slash > 0) {
if (chartDirectoryPrefixes.has(path.slice(0, slash))) {
return true;
}
slash = path.lastIndexOf('/', slash - 1);
}
return chartDirectoryPrefixes.has(path);
};
}
function extensionOf(path: string): string {
const dotIndex = path.lastIndexOf('.');
return dotIndex >= 0 ? path.slice(dotIndex).toLowerCase() : '';
}
|