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 | 4x 4x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 3x 3x 3x 3x 3x 3x 3x | import { optionDefault } from '../../option-defaults.ts';
import { selectBinding, paneOptions } from '../../pane-controls.ts';
// The Options dialog's Skin & display folder, and the controls in it that follow what is loaded: the Skin system picker,
// the LR2 theme picker and the Be-Music Skin's settings. They are built with the dialog as `this` (`OptionsDialog`).
import { resolveBeMusicSkinSettings } from '@be-music/player-skin-sdk';
import { hasAnyLR2Skin } from '../../family-dispatch.ts';
import { playerFullscreenElement, toggleFullscreen } from '../../fullscreen.ts';
import { renderResolutionLabel, renderResolutionSteps, storeRenderResolution } from '../../render-resolution.ts';
import { ADD_SKIN_ENABLED, BE_MUSIC_SKINS } from '../../services/built-in-skins.ts';
import { storePlayLayout, storeRenderer, storeSkinEffects } from '../../services/settings.ts';
import { describeSkinSettingControllers, setStoredSkinSetting, storeSkinSettings } from '../../skin-settings.ts';
import type { SkinFamilyOverride } from '../../types.ts';
import type { OptionsDialog } from './index.ts';
import { AUTO_DETECT_RESOLUTION_LABEL } from './render-resolution.ts';
/** How the skins look and lay out, the loaded themes' pickers, the Be-Music Skin's settings, and adding skins. */
export function buildSkinFolder(this: OptionsDialog): void {
// Skin family override — picks the active rendering family (LR2 / beatoraja / default) regardless of what's
// loaded. Unloaded families ask for a drop; rebuilding updates their availability labels in place.
this.rebuildSkinFamilyPicker();
this.confirmDroppedSkinController = this.place('confirmDroppedSkin')
.addBinding(this.guiState, 'confirmDroppedSkin', {
label: 'Confirm before using a dropped skin',
})
.on('change', () => {
this.guiState.skipDroppedSkin = false;
});
// One page per skin system (`skinPages`): Built-in, LR2 and beatoraja.
for (const [id, family, title] of [
['loadLR2Skin', 'lr2', 'Load LR2 skin…'],
['loadBeatorajaSkin', 'beatoraja', 'Load beatoraja skin…'],
] as const) {
this.skinControllers.push(
this.place(id)
.addButton({ title })
.on('click', () => this.deps.promptSkinDrop(family)),
);
}
// Built-in (Be-Music) skin used whenever the default family renders — i.e. no LR2 / beatoraja theme covers the
// scene. Persisted so a reload keeps the pick.
const skinOptions = () => Object.fromEntries(BE_MUSIC_SKINS.skins.map((skin) => [skin.label, skin.id]));
const skinPicker = selectBinding(
this.place('builtInSkin'),
this.guiState,
'builtInSkin',
'Built-in skin',
skinOptions(),
).on('change', ({ value: id }) => {
this.deps.handleBuiltInSkinChange(id);
});
// Skins added at runtime join the picker (in place: re-adding the controller would stack a second handler).
BE_MUSIC_SKINS.subscribe(() => {
skinPicker.options = paneOptions(skinOptions());
skinPicker.refresh();
});
const skinEffects = selectBinding(this.place('skinEffects'), this.guiState, 'skinEffects', 'Skin effects', {
Full: 'full',
Reduced: 'reduced',
Off: 'off',
}).on('change', ({ value: level }) => {
storeSkinEffects(level);
this.deps.handleSkinFamilyOverrideChange(this.guiState.skinFamilyOverride);
});
// Both make the select screen again, so they wait for the play to end.
this.skinControllers.push(skinPicker, skinEffects);
// Canvas pixels per CSS pixel, 1× up to the display's ratio. Lower trades sharpness for fill-rate (tablets drop
// under 30 fps at 2×); applies from the next frame. `?resolution=` in the URL overrides it until a pick here.
const resolutionSteps = renderResolutionSteps(window.devicePixelRatio || 1);
this.resolutionPicker = selectBinding(
this.place('renderResolution'),
this.guiState,
'renderResolution',
'Render resolution',
Object.fromEntries(resolutionSteps.map((value) => [renderResolutionLabel(value), value])),
).on('change', ({ value }) => {
storeRenderResolution(value);
this.sceneHost.setResolution(value);
});
// Measures the frame rate at each resolution on whatever screen is showing and keeps the highest that holds it.
this.autoDetectResolutionControl = this.place('autoDetectResolution')
.addButton({ title: AUTO_DETECT_RESOLUTION_LABEL })
.on('click', () => void this.detectRenderResolution());
if (resolutionSteps.length < 2) this.autoDetectResolutionControl.hidden = true;
// WebGL 2 by default; WebGPU for the GPUs it suits. The stage picks its renderer once, so a change waits for a reload.
selectBinding(this.place('renderer'), this.guiState, 'renderer', 'Renderer (applies on reload)', {
'WebGL 2': 'webgl',
WebGPU: 'webgpu',
}).on('change', ({ value: renderer }) => storeRenderer(renderer));
// Auto picks the touch layout on phones / tablets; applies from the next play.
selectBinding(this.place('playLayout'), this.guiState, 'playLayout', 'Play layout', {
Auto: 'auto',
Desktop: 'standard',
Touch: 'touch',
}).on('change', ({ value: choice }) => storePlayLayout(choice));
// The same toggle as double-clicking the playfield, for pointers where a double click is awkward.
this.place('toggleFullscreen')
.addButton({ title: 'Toggle fullscreen' })
.on('click', () => void toggleFullscreen(playerFullscreenElement(document)));
// Per-scene beatoraja skin picker, hidden until a beatoraja theme is dropped — `rebuildBeatorajaSkinPickers()`
// re-populates it on each load. Selecting a non-default entry for a scene records it on
// `beatorajaSkinOverridesByType`; the next mount picks it up via `pickBeatorajaSkinEntryWithOverride`.
this.beatorajaSkinPickerFolder = this.layout?.folder('beatorajaSkins');
if (this.beatorajaSkinPickerFolder) this.beatorajaSkinPickerFolder.hidden = true;
// The active Be-Music Skin's own settings, built from its `settings` schema (rebuilt when the skin changes).
this.layout?.folder('skinSettings').element.setAttribute('data-hide-empty-options-folder', '');
this.rebuildSkinSettingsFolder();
// LR2 theme picker — added once a drop discovers a theme (see `rebuildLR2ThemePicker`).
this.rebuildLR2ThemePicker();
// Add skin: a skin module from a URL (its default export, built with the skin SDK).
if (!ADD_SKIN_ENABLED) {
// Without the feature the folder would show as an empty heading.
const addSkin = this.layout?.folder('addSkin');
if (addSkin) addSkin.hidden = true;
return;
}
const skinSource = {
url: optionDefault<string>('addSkinURL'),
addFromURL: () => void this.deps.addBeMusicSkinFromURL(skinSource.url),
};
// Adding a skin switches to it, which makes the select screen again: the button waits for the play to end.
this.place('addSkinURL').addBinding(skinSource, 'url', { label: 'Skin module URL' });
this.skinControllers.push(
this.place('addSkinFromURL')
.addButton({ title: 'Add from URL' })
.on('click', () => skinSource['addFromURL']()),
);
}
/**
* Rebuilds (or first-builds) the Options dialog's "Skin family" dropdown. Called once during `buildGUI` and again
* after every theme load / wipe so the available options track the loaded asset state. When the user's
* previously-selected override becomes unavailable, silently resets to `'auto'` before swapping options in so
* the dropdown never displays a value that wouldn't actually be honoured.
*
* The native list's mutable options preserve its position and previously attached change handler.
*/
export function rebuildSkinFamilyPicker(this: OptionsDialog): void {
if (this.layout === undefined) return;
const lr2Available = hasAnyLR2Skin(this.deps.familyDispatchState()) || this.deps.hasPendingSkin?.('lr2') === true;
const beatorajaAvailable =
this.deps.beatorajaTheme() !== undefined || this.deps.hasPendingSkin?.('beatoraja') === true;
// Snap back to 'auto' BEFORE rebuilding options so the freshly-built controller initialises to a valid value.
// Without this guard a user-picked LR2 / beatoraja override that became unavailable mid-session would render
// as a phantom dropdown value the runtime silently ignored.
const override = this.guiState.skinFamilyOverride;
if ((override === 'lr2' && !lr2Available) || (override === 'beatoraja' && !beatorajaAvailable)) {
this.guiState.skinFamilyOverride = 'auto';
}
// The three skin systems are always listed; one without a loaded skin says so, and picking it asks for a drop.
const options: Record<string, SkinFamilyOverride> = { 'Auto (prefer loaded theme)': 'auto' };
options['Built-in'] = 'default';
options[lr2Available ? 'LR2' : 'LR2 (drop a skin)'] = 'lr2';
options[beatorajaAvailable ? 'beatoraja' : 'beatoraja (drop a skin)'] = 'beatoraja';
if (this.skinFamilyController !== undefined) {
// Update the public native list options, retaining the single change listener.
this.skinFamilyController.options = paneOptions(options);
this.skinFamilyController.refresh();
return;
}
// First-time build (called from `buildGUI` before any theme has been loaded).
this.skinFamilyController = selectBinding(
this.place('skinFamilyOverride'),
this.guiState,
'skinFamilyOverride',
'Skin system',
options,
).on('change', ({ value }) => {
const loaded =
value === 'lr2'
? hasAnyLR2Skin(this.deps.familyDispatchState()) || this.deps.hasPendingSkin?.('lr2') === true
: value === 'beatoraja'
? this.deps.beatorajaTheme() !== undefined || this.deps.hasPendingSkin?.('beatoraja') === true
: true;
if (!loaded) {
// Nothing of that system is loaded: stay on the current one and ask for a drop of its skin.
this.deps.promptSkinDrop(value === 'lr2' ? 'lr2' : 'beatoraja');
// Restored without `setValue`, which would run this handler again and rebuild the select screen for nothing.
this.guiState.skinFamilyOverride = this.activeSkinSystem;
this.skinFamilyController?.refresh();
return;
}
this.activeSkinSystem = value;
this.deps.handleSkinFamilyOverrideChange(value);
});
}
/**
* Refills the "Skin settings" folder from the active Be-Music Skin's `settings` schema — a dropdown per choice, a
* slider per number, a checkbox per toggle — seeded with the stored values, and hides it when the skin declares none.
* Every change is stored under the skin's id and reaches the scenes on screen at once.
*/
export function rebuildSkinSettingsFolder(this: OptionsDialog): void {
Iif (this.layout === undefined) return;
this.layout.setGroupReset('skinSettingRows', () => {
const skin = this.deps.beMusicSkin();
Iif (!this.skinSettings.delete(skin.id)) return;
storeSkinSettings(this.skinSettings);
this.scheduleSettingsSave();
this.deps.applyBeMusicSkinSettings();
this.rebuildSkinSettingsFolder();
});
for (const row of this.skinSettingRows.splice(0)) row.dispose();
const skin = this.deps.beMusicSkin();
const controllers = describeSkinSettingControllers(skin.settings);
if (controllers.length === 0) return;
const rows = this.place('skinSettingRows');
const values: Record<string, unknown> = { ...resolveBeMusicSkinSettings(skin, this.skinSettings.get(skin.id)) };
for (const controller of controllers) {
const added =
controller.kind === 'dropdown'
? selectBinding(rows, values, controller.id, controller.id, controller.options)
: controller.kind === 'slider'
? rows.addBinding(values, controller.id, {
min: controller.min,
max: controller.max,
step: controller.step,
})
: rows.addBinding(values, controller.id);
this.skinSettingRows.push(added);
added.label = controller.name;
added.on('change', ({ value }) => {
if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') return;
setStoredSkinSetting(this.skinSettings, skin.id, controller.id, value);
storeSkinSettings(this.skinSettings);
this.deps.applyBeMusicSkinSettings();
});
}
}
/**
* Builds (or rebuilds in place) the Options dialog's "LR2 theme" dropdown. Visible whenever at least one theme has
* been discovered from the dropped tree — a single-theme drop still gets the picker (with one option) so the
* user can SEE which theme is active, and subsequent drops that add more themes flip it into a real switcher
* without the picker disappearing and reappearing.
*
* Native mutable options keep the picker in place across theme discoveries.
*/
export function rebuildLR2ThemePicker(this: OptionsDialog): void {
if (this.layout === undefined) return;
const themes = this.deps.availableLR2Themes();
if (themes.length === 0) {
// No discovered theme (drop didn't carry an `LR2files/Theme/<name>/` shape, OR LR2 isn't loaded at all).
// Tear the controller down so the panel doesn't show a stale picker with options that no longer resolve.
this.lr2ThemeController?.dispose();
this.lr2ThemeController = undefined;
return;
}
// `themes` is already alphabetised by `discoverLR2Themes`. Use the theme name as both the dropdown label and
// the bound value — the picker proxy stores the name and `applyLR2ThemeByName` resolves it back to the files.
const options: Record<string, string> = {};
for (const theme of themes) {
options[theme.name] = theme.name;
}
if (this.lr2ThemeController !== undefined) {
this.lr2ThemeController.options = paneOptions(options);
this.lr2ThemeController.refresh();
return;
}
const proxy = { lr2Theme: this.deps.activeLR2ThemeName() ?? themes[0]!.name };
this.lr2ThemeController = selectBinding(this.place('lr2Theme'), proxy, 'lr2Theme', 'LR2 theme', options).on(
'change',
({ value }) => {
// Hosting the proxy on a literal lets us re-read the picked name without leaking a separate `guiState`
// field — the theme name is fully redundant with `activeLR2ThemeName`, which `mountLR2Theme` writes.
// No-op when the user "picks" the already-active theme — `applyLR2ThemeByName` early-returns inside
// `mountLR2Theme` since the same files re-mount to the same slots, but we still call through so a
// hypothetical future code path that observes the picker change has a single chokepoint to subscribe to.
void this.deps.applyLR2ThemeByName(value);
},
);
// A theme dropped during a play brings the picker in disabled, as the other skin controls are then.
this.lr2ThemeController.disabled = this.playLock.skinControlsLocked;
}
|