All files / player-ui/src/components result-screen.ts

6.66% Statements 1/15
0% Branches 0/18
0% Functions 0/8
8.33% Lines 1/12

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                                48x                                                                                                              
import { html, nothing, type CSSResultGroup, type TemplateResult } from 'lit';
import { resolveResultPlayTag, type BeMusicDOMResultFrame } from '@be-music/player-skin-sdk';
import { FrameElement } from '../base.ts';
import { screenStyles } from '../styles/screen.ts';
import { formatEnumLabel } from '../labels.ts';
import { stats } from '../templates.ts';
 
/** The AUTO PLAY / ASSIST tag of a player's result (`resolveResultPlayTag`), under its verdict; nothing for a plain play. */
function playTag(result: BeMusicDOMResultFrame['result']): TemplateResult | typeof nothing {
  const tag = resolveResultPlayTag(result);
  return tag === undefined
    ? nothing
    : html`<p class="result-play-tag" part="play-tag" data-tag=${tag === 'AUTO PLAY' ? 'auto' : 'assist'}>${tag}</p>`;
}
 
export class BeMusicResultScreenElement extends FrameElement<BeMusicDOMResultFrame> {
  static override styles: CSSResultGroup = screenStyles;
  protected override render(): TemplateResult | typeof nothing {
    const f = this.frame;
    if (!f) return nothing;
    const r = f.result;
    // A two-player play (LR2 BATTLE) shows both players' results side by side.
    const players = r.secondPlayer
      ? ([
          ['1P', r],
          ['2P', r.secondPlayer],
        ] as const)
      : ([['', r]] as const);
    return html`<section class="screen" part="screen">
      <div class="center">
        <div class="heading" part="header">
          <p class="eyebrow" part="eyebrow"><slot name="eyebrow">Play result</slot></p>
          <h1 part="title">${r.chart.title}</h1>
        </div>
        <div class="players" part="players" data-count=${players.length}>
          ${players.map(
            ([label, p]) =>
              html`<div class="panel player" part=${label ? `panel player-${label}` : 'panel'}>
                <div class="verdict">
                  <p class="result-verdict">
                    ${label ? `${label} ` : ''}${formatEnumLabel(p.lamp ?? (p.cleared ? 'CLEARED' : 'FAILED'))}
                  </p>
                  ${playTag(p)}
                  <p class="stat" part="stat">${p.score.exScore} / ${p.score.total * 2}</p>
                  <p class="muted">EX SCORE</p>
                </div>
                ${stats([['Max combo', p.maxCombo], ['Gauge', `${p.gauge.toFixed(1)}%`], ...(['perfect', 'great', 'good', 'bad', 'poor', 'emptyPoor'] as const).map((key) => [formatEnumLabel(key), p.score[key]] as const)])}
                <be-music-gauge-panel
                  exportparts="panel:gauge-panel,graph:gauge-graph"
                  .data=${{ value: p.gauge, label: p.score.total > 0 ? 'Gauge' : '', cleared: p.cleared, history: p.gaugeHistory }}
                ></be-music-gauge-panel>
              </div>`,
          )}
        </div>
        <div class="actions" part="actions">
          <button class="btn" ?disabled=${!f.inputReady} @click=${() => this.emit('continue-request', undefined)}>
            Continue</button
          ><button
            class="btn"
            data-variant="outline"
            ?disabled=${!f.inputReady}
            @click=${() => this.emit('retry-request', undefined)}
          >
            Retry
          </button>
        </div>
        <slot></slot>
      </div>
    </section>`;
  }
}