92 lines
3.3 KiB
TypeScript
92 lines
3.3 KiB
TypeScript
import { type GameDefinition } from '../core/gameDefinition'
|
|
import { type GameSessionState } from '../core/gameSessionState'
|
|
import { type TelemetryPresentation } from '../telemetry/telemetryPresentation'
|
|
|
|
export interface ResultSummaryRow {
|
|
label: string
|
|
value: string
|
|
}
|
|
|
|
export interface ResultSummarySnapshot {
|
|
title: string
|
|
subtitle: string
|
|
heroLabel: string
|
|
heroValue: string
|
|
rows: ResultSummaryRow[]
|
|
}
|
|
|
|
function resolveTitle(definition: GameDefinition | null, mapTitle: string): string {
|
|
if (mapTitle) {
|
|
return mapTitle
|
|
}
|
|
if (definition && definition.title) {
|
|
return definition.title
|
|
}
|
|
return '本局结果'
|
|
}
|
|
|
|
function buildHeroValue(definition: GameDefinition | null, sessionState: GameSessionState, telemetryPresentation: TelemetryPresentation): string {
|
|
if (definition && definition.mode === 'score-o') {
|
|
return `${sessionState.score}`
|
|
}
|
|
return telemetryPresentation.timerText
|
|
}
|
|
|
|
function buildHeroLabel(definition: GameDefinition | null): string {
|
|
return definition && definition.mode === 'score-o' ? '本局得分' : '本局用时'
|
|
}
|
|
|
|
function buildSubtitle(sessionState: GameSessionState): string {
|
|
if (sessionState.status === 'finished') {
|
|
return '本局已完成'
|
|
}
|
|
if (sessionState.status === 'failed') {
|
|
return '本局已结束'
|
|
}
|
|
return '对局摘要'
|
|
}
|
|
|
|
export function buildResultSummarySnapshot(
|
|
definition: GameDefinition | null,
|
|
sessionState: GameSessionState | null,
|
|
telemetryPresentation: TelemetryPresentation,
|
|
mapTitle: string,
|
|
): ResultSummarySnapshot {
|
|
const resolvedSessionState: GameSessionState = sessionState || {
|
|
status: 'idle',
|
|
startedAt: null,
|
|
endedAt: null,
|
|
completedControlIds: [],
|
|
skippedControlIds: [],
|
|
currentTargetControlId: null,
|
|
inRangeControlId: null,
|
|
score: 0,
|
|
guidanceState: 'searching',
|
|
modeState: null,
|
|
}
|
|
const skippedCount = resolvedSessionState.skippedControlIds.length
|
|
const totalControlCount = definition
|
|
? definition.controls.filter((control) => control.kind === 'control').length
|
|
: 0
|
|
const averageHeartRateText = telemetryPresentation.heartRateValueText !== '--'
|
|
? `${telemetryPresentation.heartRateValueText} ${telemetryPresentation.heartRateUnitText || 'bpm'}`
|
|
: '--'
|
|
|
|
return {
|
|
title: resolveTitle(definition, mapTitle),
|
|
subtitle: buildSubtitle(resolvedSessionState),
|
|
heroLabel: buildHeroLabel(definition),
|
|
heroValue: buildHeroValue(definition, resolvedSessionState, telemetryPresentation),
|
|
rows: [
|
|
{ label: '状态', value: resolvedSessionState.status === 'finished' ? '完成' : (resolvedSessionState.status === 'failed' ? '结束' : '进行中') },
|
|
{ label: '完成点数', value: totalControlCount > 0 ? `${resolvedSessionState.completedControlIds.length}/${totalControlCount}` : `${resolvedSessionState.completedControlIds.length}` },
|
|
{ label: '跳过点数', value: `${skippedCount}` },
|
|
{ label: '累计里程', value: telemetryPresentation.mileageText },
|
|
{ label: '平均速度', value: `${telemetryPresentation.averageSpeedValueText}${telemetryPresentation.averageSpeedUnitText}` },
|
|
{ label: '当前得分', value: `${resolvedSessionState.score}` },
|
|
{ label: '累计消耗', value: `${telemetryPresentation.caloriesValueText}${telemetryPresentation.caloriesUnitText}` },
|
|
{ label: '平均心率', value: averageHeartRateText },
|
|
],
|
|
}
|
|
}
|