All files / player-ui/src/components score-summary.ts

22.22% Statements 2/9
0% Branches 0/14
0% Functions 0/1
25% Lines 2/8

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              48x 48x                                                                                                              
import { html, nothing, css, type CSSResultGroup, type PropertyDeclarations, type TemplateResult } from 'lit';
import { DataElement } from '../base.ts';
import type { BeMusicScoreData } from '../models.ts';
import { structureStyles } from '../styles/structure.ts';
import { stats } from '../templates.ts';
 
export class BeMusicScoreSummaryElement extends DataElement<BeMusicScoreData> {
  static override properties: PropertyDeclarations = { ...DataElement.properties, compact: { type: Boolean } };
  static override styles: CSSResultGroup = [
    structureStyles,
    css`
      .summary {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: 6px;
      }
      strong {
        font-size: var(--be-music-score-size, 1.8em);
        font-variant-numeric: tabular-nums;
        margin-right: auto;
      }
      .combo {
        display: var(--be-music-compact-combo-display, block);
        margin-top: 3px;
        font-size: 0.85em;
      }
      @container be-music (max-width: 16rem) {
        .summary strong {
          flex-basis: 100%;
          margin-right: 0;
        }
      }
    `,
  ];
  declare compact: boolean;
  protected override render(): TemplateResult | typeof nothing {
    const d = this.data;
    if (!d) return nothing;
    const rate = d.maximum > 0 ? `${((d.exScore / d.maximum) * 100).toFixed(2)}%` : '—';
    if (this.compact)
      return html`<div part="summary" class="summary">
          <span class="muted">EX SCORE</span><strong part="value">${d.exScore}</strong><span>${d.rank ?? '—'}</span
          ><span class="muted">${rate}</span>
        </div>
        <p class="combo">Combo <b>${d.combo}</b> · Max ${d.maxCombo}</p>`;
    return html`<section class="panel" part="panel">
      <h3>Score &amp; progress</h3>
      ${stats([
        ['Score', d.score],
        ['EX score', `${d.exScore} / ${d.maximum}`],
        ['Score rate', rate],
        ['Rank', d.rank ?? '—'],
        ['Notes judged', `${d.judgedNotes} / ${d.totalNotes}`],
        ['Remaining', Math.max(0, d.totalNotes - d.judgedNotes)],
        ['Max combo', d.maxCombo],
        ['BP', d.missCount],
        ['EX rate (judged)', d.judgedNotes > 0 ? `${((d.exScore / (d.judgedNotes * 2)) * 100).toFixed(2)}%` : '—'],
        ['Course combo / max', d.courseCombo ? `${d.courseCombo.combo} / ${d.courseCombo.maxCombo}` : '—'],
      ])}
    </section>`;
  }
}