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 | 48x 48x | import {
html,
nothing,
type CSSResultGroup,
type PropertyDeclarations,
type PropertyValues,
type TemplateResult,
} from 'lit';
import type { BeMusicDOMGameplayFrame } from '@be-music/player-skin-sdk';
import { FrameElement } from '../base.ts';
import { resolveGameplayPanels, resolveSecondPlayerPanels, type BeMusicGameplayPanels } from '../gameplay-data.ts';
import { cabinetStyles } from '../styles/cabinet.ts';
import { screenStyles } from '../styles/screen.ts';
import { gameplayStyles } from '../styles/gameplay.ts';
import { stats } from '../templates.ts';
import { renderGameplayCabinet } from './gameplay-cabinet.ts';
type SecondPlayerPanels = ReturnType<typeof resolveSecondPlayerPanels>;
/**
* Layout composition only; the individual panels can also be mounted independently. With `cabinet` set, a landscape
* play in the standard layout is arranged as the skin SDK's cabinet layout (`resolveCabinetLayout`) instead of a column
* beside the lanes.
*/
export class BeMusicGameplayHUDElement extends FrameElement<BeMusicDOMGameplayFrame> {
static override properties: PropertyDeclarations = {
...FrameElement.properties,
cabinet: { type: Boolean, reflect: true },
};
static override styles: CSSResultGroup = [screenStyles, gameplayStyles, cabinetStyles];
declare cabinet: boolean;
private orientation: string | undefined;
private detailsOpen = true;
/** The cabinet's play information, shown over the BGA: closed until asked for. */
private cabinetDetailsOpen = false;
constructor() {
super();
this.cabinet = false;
}
protected override willUpdate(_changed: PropertyValues): void {
if (this.frame && this.orientation !== this.frame.layout.orientation) {
this.orientation = this.frame.layout.orientation;
this.detailsOpen = this.orientation === 'landscape';
}
}
protected override render(): TemplateResult | typeof nothing {
const f = this.frame;
if (!f) return nothing;
const panels = resolveGameplayPanels(f);
const r = f.runtime;
const second = r.secondPlayer === undefined ? undefined : resolveSecondPlayerPanels(r.secondPlayer, f.state2P);
if (this.cabinet && f.layout.orientation === 'landscape' && f.layout.mode === 'standard') {
const toggle = html`<button
class="btn"
data-size="sm"
data-variant="outline"
aria-expanded=${String(this.cabinetDetailsOpen)}
@click=${() => {
this.cabinetDetailsOpen = !this.cabinetDetailsOpen;
this.requestUpdate();
}}
>
Info
</button>`;
return renderGameplayCabinet({
frame: f,
panels,
second,
actions: this.renderActions(f, toggle),
details: this.cabinetDetailsOpen
? html`<div class="hud-extra" part="details">${this.renderDetails(f, panels, second)}</div>`
: nothing,
});
}
return this.renderColumn(f, panels, second);
}
private renderActions(f: BeMusicDOMGameplayFrame, extra: TemplateResult | typeof nothing = nothing): TemplateResult {
if (f.layout.orientation === 'portrait')
return html`<div class="actions portrait-actions" part="actions">
<button class="btn" @click=${() => this.emit('pause-request', undefined)}>
${f.stage === 'paused' ? 'Resume' : 'Pause'}
</button>
<details class="play-menu">
<summary class="btn">Menu</summary>
<div class="panel">
<button class="btn" @click=${() => this.emit('retry-request', undefined)}>Retry</button>
<button class="btn" @click=${() => this.emit('quit-request', undefined)}>Back</button>
<slot name="actions"></slot>
</div>
</details>
</div>`;
return html`<div class="actions" part="actions">
<button class="btn" data-size="sm" @click=${() => this.emit('pause-request', undefined)}>
${f.stage === 'paused' ? 'Resume' : 'Pause'}</button
><button class="btn" data-size="sm" data-variant="outline" @click=${() => this.emit('retry-request', undefined)}>
Retry</button
><button class="btn" data-size="sm" data-variant="outline" @click=${() => this.emit('quit-request', undefined)}>
Back</button
>${extra}<slot name="actions"></slot>
</div>`;
}
/** Every panel of the play: the score, the judgments, the gauge, the timing, the settings and the chart. */
private renderDetails(
f: BeMusicDOMGameplayFrame,
panels: BeMusicGameplayPanels,
second: SecondPlayerPanels,
): TemplateResult {
const { state: s, runtime: r, chart } = f;
const { score, gauge, judgments, facts, totalNotes: total, seconds } = panels;
return html`<be-music-score-summary exportparts="panel:score-panel" .data=${score}></be-music-score-summary>
${
// The player turned the judgment counts off.
r.hidesJudgeCounts
? nothing
: html`<be-music-judgment-table
exportparts="panel:judgment-panel,table:judgment-table"
.data=${judgments}
></be-music-judgment-table>`
}
${
second && !r.hidesJudgeCounts
? html`<be-music-judgment-table
exportparts="panel:judgment-panel,table:judgment-table"
.data=${second.judgments}
></be-music-judgment-table>`
: nothing
}
<be-music-gauge-panel exportparts="panel:gauge-panel,graph:gauge-graph" .data=${gauge}></be-music-gauge-panel>
<be-music-timing-graph
exportparts="panel:timing-panel,graph:timing-graph"
.data=${{ timings: s.judgeTimings }}
></be-music-timing-graph>
<be-music-play-settings
exportparts="panel:settings-panel"
.data=${{ view: s.view, options: f.playOptions, runtime: r }}
></be-music-play-settings>
<section class="panel" part="chart-panel">
<h3>Chart & course</h3>
<p class="muted">${chart?.artist ?? ''} · ${facts} · ${total} notes</p>
<p class="muted">${chart?.chartPath ?? ''}</p>
<p class="muted">${courseLine(f)}</p>
${stats([['Time left', `${Math.ceil(Math.max(0, s.totalSeconds - seconds))} s`]])}
</section>
<slot></slot>`;
}
/** The column beside the lanes: the heading, the live figures, the actions and the play information below. */
private renderColumn(
f: BeMusicDOMGameplayFrame,
panels: BeMusicGameplayPanels,
second: SecondPlayerPanels,
): TemplateResult {
const { state: s, runtime: r, chart } = f;
const { score, gauge, title, facts, seconds } = panels;
const style = `--stage-ratio:${f.layout.stage.width / f.layout.stage.height};--hud-left:${((f.layout.playfield.right + 20) / f.layout.stage.width) * 100}%;--playfield-center:${(f.layout.playfield.centerX / f.layout.stage.width) * 100}%;--be-music-compact-combo-display:none`;
return html`<section
class="gameplay"
data-orientation=${f.layout.orientation}
data-bga=${r.hasBGA ? 'on' : 'off'}
style=${style}
>
<aside class="hud" part="hud" data-orientation=${f.layout.orientation} aria-label="Play status">
<div class="hud-heading" part="heading">
<div>
<span class="eyebrow">${f.replay ? 'Replay' : f.autoPlay ? 'Auto play' : 'Live'}</span>
<span class="muted"
>${f.stage === 'loading' ? `Loading ${Math.round((f.progress ?? 0) * 100)}%` : f.stage}</span
>
</div>
<h2 title=${title}>${title}</h2>
<p class="muted">${chart?.artist ?? ''}</p>
<p class="muted">${facts}</p>
<p class="muted">${f.course ? courseLine(f) : ''}</p>
</div>
<div class="hud-primary" part="primary">
<be-music-score-summary
compact
exportparts="summary:score-summary,value:score-value"
.data=${score}
></be-music-score-summary>
<dl class="hud-live">
<dt>Combo</dt>
<dd>${s.combo}</dd>
<dt>BPM</dt>
<dd>${f.bpm === undefined ? '—' : Math.round(f.bpm)}</dd>
<dt>Time</dt>
<dd>${Math.floor(seconds)} / ${Math.ceil(s.totalSeconds)} s</dd>
</dl>
<be-music-gauge-panel compact exportparts="meter:gauge-meter" .data=${gauge}></be-music-gauge-panel>
${
second
? html`<div class="hud-second" part="second-player" aria-label="2P">
<span class="eyebrow">2P</span>
<be-music-score-summary
compact
exportparts="summary:score-summary,value:score-value"
.data=${second.score}
></be-music-score-summary>
<be-music-gauge-panel
compact
exportparts="meter:gauge-meter"
.data=${second.gauge}
></be-music-gauge-panel>
</div>`
: nothing
}
<progress
max="1"
.value=${s.totalSeconds > 0 ? seconds / s.totalSeconds : 0}
aria-label="Chart progress"
></progress>
</div>
${this.renderActions(f)}
<details
class="hud-details"
.open=${this.detailsOpen}
@toggle=${(event: Event) => {
this.detailsOpen = (event.currentTarget as HTMLDetailsElement).open;
}}
>
<summary>All play information</summary>
<div class="hud-extra" part="details">${this.renderDetails(f, panels, second)}</div>
</details>
</aside>
${f.stage === 'paused' ? html`<p class="paused" part="paused" role="status">Paused</p>` : nothing}
</section>`;
}
}
function courseLine(f: BeMusicDOMGameplayFrame): string {
return f.course
? `${f.course.title} · Stage ${(f.course.stageIndex ?? 0) + 1}/${f.course.stages.length}`
: 'Single chart';
}
|