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 | 9x 5x 5x 4x 304x 304x 6x 5x 4x 6x 6x 4x 16x 16x 6x 6x 4x 9x 3x 12x 9x 3x 3x 3x 3x 12x 12x 3x 4x 4x 4x 117x 7x 3x 4x | // The player's own START / SELECT keys (Options → Keys): read back from storage, and assigning one the way the lane key
// config does — a key START or SELECT already has moves over, and that one takes this one's. The defaults are
// `CONTROL_KEY_CONFIG`'s (Q / W, O / P); the screens read them as control buttons over the lane keys.
import {
CONTROL_KEY_CONFIG,
effectiveControlKey,
type ControlKeyId,
type ControlKeyOverrides,
type ControlScheme,
type ControlSettings,
CONTROL_ACTIONS,
type ControlActionOverrides,
} from '@be-music/player-browser/host';
import type { LaneKeyOverrides } from '@be-music/player-engine/lanes';
/** The key maps a built-in skin's screens can read. */
export const CONTROL_SCHEMES: readonly ControlScheme[] = ['lr2', 'beatoraja'];
/** The screens' control settings (`ControlSettings`) of the player's keys and the built-in skins' key map. */
export function controlSettingsOf(state: {
readonly laneKeys: LaneKeyOverrides;
readonly controlKeys: ControlKeyOverrides;
readonly builtInControlScheme: ControlScheme;
readonly actionKeys: ControlActionOverrides;
}): ControlSettings {
return {
laneKeys: state.laneKeys,
controlKeys: state.controlKeys,
builtInScheme: state.builtInControlScheme,
actionKeys: state.actionKeys,
};
}
/** Stored keys for the screens' operations, keeping only known operations with a non-empty list of key codes. */
export function parseActionKeys(raw: unknown): ControlActionOverrides {
const keys: Record<string, string[]> = {};
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return keys;
for (const { id } of CONTROL_ACTIONS) {
const codes = (raw as Record<string, unknown>)[id];
if (!Array.isArray(codes)) continue;
const valid = codes.filter((code): code is string => typeof code === 'string' && code !== '');
if (valid.length > 0) keys[id] = valid;
}
return keys as ControlActionOverrides;
}
/** Stored START / SELECT keys, keeping only known ids with a non-empty token list. */
export function parseControlKeys(raw: unknown): ControlKeyOverrides {
const keys: ControlKeyOverrides = {};
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return keys;
for (const { id } of CONTROL_KEY_CONFIG) {
const tokens = (raw as Record<string, unknown>)[id];
if (!Array.isArray(tokens)) continue;
const valid = tokens.filter((token): token is string => typeof token === 'string' && token !== '');
if (valid.length > 0) keys[id] = valid;
}
return keys;
}
/**
* Gives START / SELECT `id` the key `token`. The one that has the key now takes the key `id` had, so no two share one.
* One left on its default keeps no entry.
*/
export function assignControlKey(keys: ControlKeyOverrides, id: ControlKeyId, token: string): ControlKeyOverrides {
if (!CONTROL_KEY_CONFIG.some((entry) => entry.id === id) || token === '') return keys;
const previous = effectiveControlKey(keys, id);
const next = new Map(CONTROL_KEY_CONFIG.map((entry) => [entry.id, effectiveControlKey(keys, entry.id)]));
const taken = CONTROL_KEY_CONFIG.find((entry) => entry.id !== id && next.get(entry.id) === token);
next.set(id, token);
if (taken !== undefined) next.set(taken.id, previous);
const own: ControlKeyOverrides = {};
for (const entry of CONTROL_KEY_CONFIG) {
const key = next.get(entry.id)!;
if (key !== entry.defaultToken) own[entry.id] = [key];
}
return own;
}
/**
* The screens' keys after picking the built-in skins' key map `scheme`: it overwrites the key config, so every operation
* that key map has goes back to its keys there (the player's own keys for it are dropped). Keys for operations only the
* other key map has are kept. Returns `keys` itself when nothing changes.
*/
export function overwriteActionKeysWithScheme(
keys: ControlActionOverrides,
scheme: ControlScheme,
): ControlActionOverrides {
const kept: Record<string, readonly string[]> = {};
let changed = false;
for (const [id, codes] of Object.entries(keys) as [string, readonly string[]][]) {
const definition = CONTROL_ACTIONS.find((action) => action.id === id);
if (definition?.defaults[scheme] !== undefined) changed = true;
else kept[id] = codes;
}
return changed ? (kept as ControlActionOverrides) : keys;
}
|