feat: 收敛玩法运行时配置并加入故障恢复
This commit is contained in:
@@ -15,6 +15,15 @@ export interface ResultSummarySnapshot {
|
||||
rows: ResultSummaryRow[]
|
||||
}
|
||||
|
||||
export interface ResultSummaryMetrics {
|
||||
totalScore?: number
|
||||
baseScore?: number
|
||||
bonusScore?: number
|
||||
quizCorrectCount?: number
|
||||
quizWrongCount?: number
|
||||
quizTimeoutCount?: number
|
||||
}
|
||||
|
||||
function resolveTitle(definition: GameDefinition | null, mapTitle: string): string {
|
||||
if (mapTitle) {
|
||||
return mapTitle
|
||||
@@ -25,11 +34,19 @@ function resolveTitle(definition: GameDefinition | null, mapTitle: string): stri
|
||||
return '本局结果'
|
||||
}
|
||||
|
||||
function buildHeroValue(definition: GameDefinition | null, sessionState: GameSessionState, telemetryPresentation: TelemetryPresentation): string {
|
||||
function buildHeroValue(
|
||||
definition: GameDefinition | null,
|
||||
sessionState: GameSessionState,
|
||||
telemetryPresentation: TelemetryPresentation,
|
||||
metrics?: ResultSummaryMetrics,
|
||||
): string {
|
||||
const totalScore = metrics && typeof metrics.totalScore === 'number'
|
||||
? metrics.totalScore
|
||||
: sessionState.score
|
||||
if (definition && definition.mode === 'score-o') {
|
||||
return `${sessionState.score}`
|
||||
return `${totalScore}`
|
||||
}
|
||||
return telemetryPresentation.timerText
|
||||
return telemetryPresentation.elapsedTimerText
|
||||
}
|
||||
|
||||
function buildHeroLabel(definition: GameDefinition | null): string {
|
||||
@@ -40,6 +57,9 @@ function buildSubtitle(sessionState: GameSessionState): string {
|
||||
if (sessionState.status === 'finished') {
|
||||
return '本局已完成'
|
||||
}
|
||||
if (sessionState.endReason === 'timed_out') {
|
||||
return '本局超时结束'
|
||||
}
|
||||
if (sessionState.status === 'failed') {
|
||||
return '本局已结束'
|
||||
}
|
||||
@@ -51,9 +71,11 @@ export function buildResultSummarySnapshot(
|
||||
sessionState: GameSessionState | null,
|
||||
telemetryPresentation: TelemetryPresentation,
|
||||
mapTitle: string,
|
||||
metrics?: ResultSummaryMetrics,
|
||||
): ResultSummarySnapshot {
|
||||
const resolvedSessionState: GameSessionState = sessionState || {
|
||||
status: 'idle',
|
||||
endReason: null,
|
||||
startedAt: null,
|
||||
endedAt: null,
|
||||
completedControlIds: [],
|
||||
@@ -71,21 +93,45 @@ export function buildResultSummarySnapshot(
|
||||
const averageHeartRateText = telemetryPresentation.heartRateValueText !== '--'
|
||||
? `${telemetryPresentation.heartRateValueText} ${telemetryPresentation.heartRateUnitText || 'bpm'}`
|
||||
: '--'
|
||||
const totalScore = metrics && typeof metrics.totalScore === 'number' ? metrics.totalScore : resolvedSessionState.score
|
||||
const baseScore = metrics && typeof metrics.baseScore === 'number' ? metrics.baseScore : resolvedSessionState.score
|
||||
const bonusScore = metrics && typeof metrics.bonusScore === 'number' ? metrics.bonusScore : 0
|
||||
const quizCorrectCount = metrics && typeof metrics.quizCorrectCount === 'number' ? metrics.quizCorrectCount : 0
|
||||
const quizWrongCount = metrics && typeof metrics.quizWrongCount === 'number' ? metrics.quizWrongCount : 0
|
||||
const quizTimeoutCount = metrics && typeof metrics.quizTimeoutCount === 'number' ? metrics.quizTimeoutCount : 0
|
||||
const includeQuizRows = bonusScore > 0 || quizCorrectCount > 0 || quizWrongCount > 0 || quizTimeoutCount > 0
|
||||
const rows: ResultSummaryRow[] = [
|
||||
{
|
||||
label: '状态',
|
||||
value: resolvedSessionState.endReason === 'timed_out'
|
||||
? '超时结束'
|
||||
: resolvedSessionState.status === 'finished'
|
||||
? '完成'
|
||||
: (resolvedSessionState.status === 'failed' ? '结束' : '进行中'),
|
||||
},
|
||||
{ label: '完成点数', value: totalControlCount > 0 ? `${resolvedSessionState.completedControlIds.length}/${totalControlCount}` : `${resolvedSessionState.completedControlIds.length}` },
|
||||
{ label: '跳过点数', value: `${skippedCount}` },
|
||||
{ label: '总分', value: `${totalScore}` },
|
||||
]
|
||||
|
||||
if (includeQuizRows) {
|
||||
rows.push({ label: '基础积分', value: `${baseScore}` })
|
||||
rows.push({ label: '答题奖励积分', value: `${bonusScore}` })
|
||||
rows.push({ label: '答题正确数', value: `${quizCorrectCount}` })
|
||||
rows.push({ label: '答题错误数', value: `${quizWrongCount}` })
|
||||
rows.push({ label: '答题超时数', value: `${quizTimeoutCount}` })
|
||||
}
|
||||
|
||||
rows.push({ label: '累计里程', value: telemetryPresentation.mileageText })
|
||||
rows.push({ label: '平均速度', value: `${telemetryPresentation.averageSpeedValueText}${telemetryPresentation.averageSpeedUnitText}` })
|
||||
rows.push({ label: '累计消耗', value: `${telemetryPresentation.caloriesValueText}${telemetryPresentation.caloriesUnitText}` })
|
||||
rows.push({ label: '平均心率', value: averageHeartRateText })
|
||||
|
||||
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 },
|
||||
],
|
||||
heroValue: buildHeroValue(definition, resolvedSessionState, telemetryPresentation, metrics),
|
||||
rows,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user