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 | // Help's Keyboard tab: a screen's keys drawn on a keyboard (`<be-music-keyboard-map>`) with the list of what each key
// does, from the player's own keys. The player picks the screen, the key map (LR2's or beatoraja's, starting on the one
// the current skin reads) and the keyboard's size (full or laptop, starting on the one the device most likely has); a Mac
// gets a Mac's keyboard, anything else a Windows PC's. Pointing at a line of the list lights its keys.
import { html, nothing, render, type TemplateResult } from 'lit';
import type { ControlScheme, ControlScreen, ControlSettings } from '@be-music/player-browser/host';
import { defineKeyboardMapElement } from './keyboard-element.ts';
import { buildGamepadGuide } from './gamepad-guide.ts';
import { buildKeyboardGuide, type KeyboardGuideLang, type KeyboardGuideRow } from './keyboard-guide.ts';
import { guessKeyboard, KEYBOARD_FORMS, type KeyboardForm, type KeyboardPlatform } from './keyboard-layout.ts';
/** Where the page reads the player's keys and the key map the current screen reads. */
export interface HelpKeyboardSource {
readonly settings: ControlSettings;
readonly scheme: ControlScheme;
}
const SCREENS: readonly ControlScreen[] = ['select', 'decide', 'play', 'result', 'global'];
const SCHEMES: readonly ControlScheme[] = ['lr2', 'beatoraja'];
const COPY = {
en: {
screen: 'Screen',
keyMap: 'Key map',
form: 'Keyboard size',
forms: { full: 'Full', laptop: 'Laptop' },
screens: { select: 'Select', decide: 'Decide', play: 'Play', result: 'Result', global: 'Every screen' },
diagram: (screen: string) => `The keys of the ${screen} screen`,
lanes: 'Lane keys',
actions: 'Operations',
legend: 'Numbers are the lane keys (white and black), ◎ the turntable, ST / SL START / SELECT, ● an operation.',
note: 'Point at a line to light its keys. On a laptop, a key it lacks reads as the Fn combination that gives it (the number pad is the one built into the letter keys, where the laptop has one). Combinations and held keys are on the Usage tab; Options → Keys moves any key.',
none: 'No operation on this key map.',
gamepad: 'Gamepad',
iidx: 'IIDX controller',
gamepadNote:
'A gamepad button does what the key it stands for does, on the same key map. The first pad is 1P, the second 2P. Outside a play the D-pad is the arrow keys, and a held turntable or D-pad repeats; in a play the D-pad is key 1.',
},
ja: {
screen: '画面',
keyMap: 'キー操作',
form: 'キーボードの大きさ',
forms: { full: 'フル', laptop: 'ノート' },
screens: { select: '選曲', decide: '決定', play: 'プレイ', result: 'リザルト', global: '全画面' },
diagram: (screen: string) => `${screen}画面のキー`,
lanes: 'レーンのキー',
actions: '操作',
legend: '数字はレーンの鍵盤 (白鍵・黒鍵)、◎ はスクラッチ、ST / SL は START / SELECT、● は操作のキーです。',
note: '行にカーソルを合わせるとそのキーが光ります。ノートにないキーは、それを入力する Fn との組み合わせで示します (テンキーは、文字キーに内蔵されたテンキーがあるノートでの組み合わせです)。同時押しや長押しは「使い方」タブに、キーの変更は Options → Keys にあります。',
none: 'このキー操作にはありません。',
gamepad: 'ゲームパッド',
iidx: 'IIDX コントローラー',
gamepadNote:
'ゲームパッドのボタンは、対応するキーと同じキー操作で同じ働きをします。1 台目が 1P、2 台目が 2P です。プレイ以外の画面では十字キーが矢印キーになり、スクラッチや十字キーは押し続けるとくり返します。プレイ中の十字キーは鍵盤 1 です。',
},
} as const;
const SCHEME_NAMES: Readonly<Record<ControlScheme, string>> = { lr2: 'LR2', beatoraja: 'beatoraja' };
/** Draws Help's Keyboard tab into `root` and keeps it there. */
export class HelpKeyboard {
private screen: ControlScreen = 'play';
private scheme: ControlScheme | undefined;
private readonly platform: KeyboardPlatform;
private form: KeyboardForm;
private active: readonly string[] = [];
private lang: KeyboardGuideLang = 'en';
private readonly root: HTMLElement;
private readonly source: () => HelpKeyboardSource;
public constructor(root: HTMLElement, source: () => HelpKeyboardSource) {
this.root = root;
this.source = source;
({ platform: this.platform, form: this.form } = guessKeyboard(devicePlatform()));
defineKeyboardMapElement();
}
/** Draws the page in `lang`, on the key map the current screen reads the first time. */
public show(lang: KeyboardGuideLang): void {
this.lang = lang;
this.scheme ??= this.source().scheme;
this.update();
}
/** Starts again from the current screen's key map the next time Help opens. */
public reset(): void {
this.scheme = undefined;
this.active = [];
}
private update(): void {
render(this.template(), this.root);
}
private template(): TemplateResult {
const copy = COPY[this.lang];
const scheme = this.scheme ?? 'lr2';
const guide = buildKeyboardGuide(this.screen, scheme, this.source().settings, this.lang, this.platform, this.form);
const gamepad = buildGamepadGuide(this.screen, this.lang);
const pick = <T>(value: T, current: T, label: string, set: () => void): TemplateResult =>
html`<button
type="button"
class="btn"
data-size="sm"
data-variant=${value === current ? 'secondary' : 'outline'}
aria-pressed=${value === current ? 'true' : 'false'}
@click=${() => {
set();
this.active = [];
this.update();
}}
>
${label}
</button>`;
// The pickers and the keyboard stay at the top of the panel while the lists scroll under them.
return html`<div class="help-keyboard">
<div class="help-keyboard-sticky">
<div class="help-keyboard-controls">
<div class="button-group" role="group" aria-label=${copy.screen}>
${SCREENS.map((screen) => pick(screen, this.screen, copy.screens[screen], () => (this.screen = screen)))}
</div>
<div class="button-group" role="group" aria-label=${copy.keyMap}>
${SCHEMES.map((value) => pick(value, scheme, SCHEME_NAMES[value], () => (this.scheme = value)))}
</div>
<div class="button-group" role="group" aria-label=${copy.form}>
${KEYBOARD_FORMS.map((value) => pick(value, this.form, copy.forms[value], () => (this.form = value)))}
</div>
</div>
<be-music-keyboard-map
.marks=${guide.marks}
.active=${this.active}
platform=${this.platform}
form=${this.form}
label=${copy.diagram(copy.screens[this.screen])}
></be-music-keyboard-map>
</div>
<p class="help-keyboard-legend">${copy.legend}</p>
<div class="help-keyboard-lists">
${this.list(copy.actions, guide.actions, copy.none)} ${this.list(copy.lanes, guide.lanes)}
</div>
<p class="help-keyboard-note">${copy.note}</p>
${
gamepad.standard.length === 0
? nothing
: html`<div class="help-keyboard-lists">
${this.list(copy.gamepad, gamepad.standard)} ${this.list(copy.iidx, gamepad.iidx)}
</div>
<p class="help-keyboard-note">${copy.gamepadNote}</p>`
}
</div>`;
}
private list(title: string, rows: readonly KeyboardGuideRow[], empty?: string): TemplateResult {
const light = (codes: readonly string[]): void => {
this.active = codes;
this.update();
};
return html`<section class="help-keyboard-list">
<h4>${title}</h4>
${
rows.length === 0 && empty !== undefined
? html`<p class="help-keyboard-empty">${empty}</p>`
: html`<ul>
${rows.map(
(row) =>
html`<li
tabindex="0"
?data-active=${row.codes.length > 0 && row.codes.every((code) => this.active.includes(code))}
@pointerenter=${() => light(row.codes)}
@pointerleave=${() => light([])}
@focus=${() => light(row.codes)}
@blur=${() => light([])}
>
<span class="help-keyboard-name">${row.name}</span>
<span class="help-keyboard-keys"
>${row.keys.length === 0 ? '—' : nothing}${row.keys.map((key) => html`<kbd>${key}</kbd>`)}</span
>
</li>`,
)}
</ul>`
}
</section>`;
}
}
/** The device's platform as the browser reports it (`macOS`, `Windows`, `MacIntel`, `Win32`), if it does. */
function devicePlatform(): string | undefined {
if (typeof navigator === 'undefined') return undefined;
const hinted = (navigator as Navigator & { userAgentData?: { platform?: string } }).userAgentData?.platform;
return hinted !== undefined && hinted !== '' ? hinted : navigator.platform;
}
|