All files / app-play/src/ui/options action-labels.ts

97.36% Statements 37/38
90.9% Branches 30/33
100% Functions 9/9
100% Lines 25/25

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                      13x                 13x                                                                                                                                                   52x             13x       5328x         1749x 1749x 1749x         6x 5x 4x 3x 3x 2x 1x         3x 3x 3x 3x 2x 1x         432x 332x 4928x 1232x    
// The names the key config gives the lanes and the screens' operations and their keys (`keys.ts`, `action-keys.ts`),
// apart from the pages so `labels.ts` and the Help entries read them without the pages.
import {
  type ControlActionDefinition,
  type ControlActionKey,
  type ControlScheme,
  type ControlScreen,
} from '@be-music/player-browser/host';
import { LANE_KEY_CONFIG, type LaneKeyConfigLane, type LaneKeyGroup } from '@be-music/player-engine/lanes';
 
/** Each screen's heading on the page. */
export const ACTION_SCREEN_TITLES: Readonly<Record<ControlScreen, string>> = {
  global: 'Every screen',
  select: 'Select screen',
  decide: 'Decide screen',
  play: 'Play',
  result: 'Result screen',
};
 
/** The Japanese of each operation's name and of the screens' headings, for `labels.ts`. */
export const ACTION_LABELS_JA: Readonly<Record<string, string>> = {
  'Full screen': 'フルスクリーン',
  Screenshot: 'スクリーンショット',
  'Frame rate': 'フレームレート',
  'Open folder': 'フォルダを開く',
  'Ranking (hold)': 'ランキング (長押し)',
  'Edit level (hold)': 'レベルの編集 (長押し)',
  Help: 'ヘルプ',
  'Option panel 2': 'オプションパネル 2',
  'Option panel 3': 'オプションパネル 3',
  'Next difficulty': '次の難易度',
  'AUTO play': 'AUTO プレイ',
  Sort: 'ソート',
  'Key mode filter': '鍵盤数の絞り込み',
  'LN mode': 'LN モード',
  'BATTLE (????)': 'BATTLE (????)',
  'M-RAN 1P': 'M-RAN 1P',
  'M-RAN 2P': 'M-RAN 2P',
  Search: '検索',
  'Copy MD5': 'MD5 をコピー',
  'Copy SHA-256': 'SHA-256 をコピー',
  'AUTO play the folder': 'フォルダを AUTO で再生',
  'Open its folder': '譜面のフォルダを開く',
  'Text file': 'テキストファイル',
  'Reload folders': 'フォルダの再読み込み',
  'Retry (same arrangement)': 'リトライ (同じ配置)',
  'Gauge graph': 'ゲージグラフの切り替え',
  'LR2 mania options': 'LR2 マニアオプション',
  'Favorite song': 'お気に入りの曲',
  'Favorite chart': 'お気に入りの譜面',
  'Every screen': 'すべての画面',
  'Next bar': '次のバー',
  'Previous bar': '前のバー',
  'Ten bars down': '10 バー下へ',
  'Ten bars up': '10 バー上へ',
  'First bar': '最初のバー',
  'Last bar': '最後のバー',
  'Random bar': 'ランダムなバー',
  'Open / play': '開く / プレイ',
  Back: '戻る',
  'Close folder': 'フォルダを閉じる',
  'PLAY OPTION panel': 'PLAY OPTION パネル',
  'Next replay slot': '次のリプレイスロット',
  Replay: 'リプレイ',
  Continue: '進む',
  'Back to select': '選曲画面へ戻る',
  Quit: '中断',
  'Quit (hold)': '中断 (長押し)',
  Restart: 'リスタート',
  Pause: 'ポーズ',
  'Lane cover up': 'レーンカバーを上げる',
  'Lane cover down': 'レーンカバーを下げる',
  'Hi-speed up': 'ハイスピードを上げる',
  'Hi-speed down': 'ハイスピードを下げる',
  'FLOATING HI-SPEED': 'FLOATING HI-SPEED',
  'Restore green number (twice)': '緑数字を戻す (2 回押し)',
  'Seek back (AUTO)': '5 秒戻る (AUTO)',
  'Seek forward (AUTO)': '5 秒進む (AUTO)',
  'SUDDEN+ up': 'SUDDEN+ を上げる',
  'SUDDEN+ down': 'SUDDEN+ を下げる',
  'LIFT up': 'LIFT を上げる',
  'LIFT down': 'LIFT を下げる',
  'HIDDEN+ on / off': 'HIDDEN+ のオン / オフ',
  'HIDDEN+ up': 'HIDDEN+ を上げる',
  'HIDDEN+ down': 'HIDDEN+ を下げる',
  'M-SUDDEN down': 'M-SUDDEN を下げる',
  'AUTO speed ×0.25': 'AUTO の速度 ×0.25',
  'AUTO speed ×0.5': 'AUTO の速度 ×0.5',
  'AUTO speed ×2': 'AUTO の速度 ×2',
  'AUTO speed ×3': 'AUTO の速度 ×3',
  'M-SUDDEN up': 'M-SUDDEN を上げる',
  Next: '次へ',
  Leave: '抜ける',
  Retry: 'リトライ',
  ...Object.fromEntries([1, 2, 3, 4].map((slot) => [`Save replay ${slot}`, `リプレイを保存 ${slot}`])),
  'Select screen': '選曲画面',
  'Decide screen': '決定画面',
  Play: 'プレイ',
  'Result screen': 'リザルト画面',
};
 
const SCHEME_NAMES: Readonly<Record<ControlScheme, string>> = { lr2: 'LR2', beatoraja: 'beatoraja' };
 
/** The key maps an operation is on. */
export function schemesOf(definition: ControlActionDefinition): ControlScheme[] {
  return (['lr2', 'beatoraja'] as const).filter((scheme) => definition.defaults[scheme] !== undefined);
}
 
/** An operation's name in the key config, with the key map it is on when only one has it (`Ten bars down (beatoraja)`). */
export function actionKeyConfigLabel(definition: ControlActionDefinition, lang = 'en'): string {
  const name = lang === 'ja' ? (ACTION_LABELS_JA[definition.label] ?? definition.label) : definition.label;
  const schemes = schemesOf(definition);
  return schemes.length === 1 ? `${name} (${SCHEME_NAMES[schemes[0]!]})` : name;
}
 
/** How a key code reads (`R`, `4`, `↓`, `Num 0`, `Esc`). */
export function keyCodeLabel(code: string): string {
  if (/^Key[A-Z]$/u.test(code)) return code.slice(3);
  if (/^Digit\d$/u.test(code)) return code.slice(5);
  if (/^Numpad\d$/u.test(code)) return `Num ${code.slice(6)}`;
  const arrows: Record<string, string> = { ArrowUp: '↑', ArrowDown: '↓', ArrowLeft: '←', ArrowRight: '→' };
  if (arrows[code] !== undefined) return arrows[code]!;
  if (code === 'Escape') return 'Esc';
  return code;
}
 
/** How an operation's key reads: a code, or a button (`1P START`, `1P key 6`, `1P scratch ↺` for its second key). */
export function actionKeyLabel(key: ControlActionKey): string {
  Iif ('code' in key) return keyCodeLabel(key.code);
  const [side, ...rest] = key.button.split('-');
  const name = rest.join('-');
  if (name === 'start' || name === 'select') return `${side} ${name.toUpperCase()}`;
  if (name.startsWith('key')) return `${side} key ${name.slice(3)}`;
  return `${side} scratch ${name === 'scratch-ccw' ? '↺' : '↻'}`;
}
 
/** A lane's name in the key config (`1P scratch`, `2P key 3`, `Key 9`), which `labels.ts` translates. */
export function laneKeyConfigLabel(group: LaneKeyGroup, lane: LaneKeyConfigLane): string {
  if (group === 'popn') return `Key ${lane.id}`;
  if (lane.scratch) return `${lane.side} scratch`;
  const keys = LANE_KEY_CONFIG.beat.filter((entry) => entry.side === lane.side && !entry.scratch);
  return `${lane.side} key ${keys.findIndex((entry) => entry.id === lane.id) + 1}`;
}