完善文创展示控制与结果层基础
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import { type GameDefinition, type GameControl, type PunchPolicyType } from '../core/gameDefinition'
|
||||
import {
|
||||
type GameDefinition,
|
||||
type GameControl,
|
||||
type GameControlDisplayContent,
|
||||
type GameControlDisplayContentOverride,
|
||||
type PunchPolicyType,
|
||||
} from '../core/gameDefinition'
|
||||
import { type OrienteeringCourseData } from '../../utils/orienteeringCourse'
|
||||
|
||||
function sortBySequence<T extends { sequence: number | null }>(items: T[]): T[] {
|
||||
@@ -13,6 +19,23 @@ function buildDisplayBody(label: string, sequence: number | null): string {
|
||||
return label
|
||||
}
|
||||
|
||||
function applyDisplayContentOverride(
|
||||
baseContent: GameControlDisplayContent,
|
||||
override: GameControlDisplayContentOverride | undefined,
|
||||
): GameControlDisplayContent {
|
||||
if (!override) {
|
||||
return baseContent
|
||||
}
|
||||
|
||||
return {
|
||||
title: override.title || baseContent.title,
|
||||
body: override.body || baseContent.body,
|
||||
autoPopup: override.autoPopup !== undefined ? override.autoPopup : baseContent.autoPopup,
|
||||
once: override.once !== undefined ? override.once : baseContent.once,
|
||||
priority: override.priority !== undefined ? override.priority : baseContent.priority,
|
||||
}
|
||||
}
|
||||
|
||||
export function buildGameDefinitionFromCourse(
|
||||
course: OrienteeringCourseData,
|
||||
controlRadiusMeters: number,
|
||||
@@ -25,20 +48,29 @@ export function buildGameDefinitionFromCourse(
|
||||
skipRadiusMeters = 30,
|
||||
skipRequiresConfirm = true,
|
||||
controlScoreOverrides: Record<string, number> = {},
|
||||
controlContentOverrides: Record<string, GameControlDisplayContentOverride> = {},
|
||||
defaultControlScore: number | null = null,
|
||||
): GameDefinition {
|
||||
const controls: GameControl[] = []
|
||||
|
||||
for (const start of course.layers.starts) {
|
||||
for (let startIndex = 0; startIndex < course.layers.starts.length; startIndex += 1) {
|
||||
const start = course.layers.starts[startIndex]
|
||||
const startId = `start-${startIndex + 1}`
|
||||
controls.push({
|
||||
id: `start-${controls.length + 1}`,
|
||||
id: startId,
|
||||
code: start.label || 'S',
|
||||
label: start.label || 'Start',
|
||||
kind: 'start',
|
||||
point: start.point,
|
||||
sequence: null,
|
||||
score: null,
|
||||
displayContent: null,
|
||||
displayContent: applyDisplayContentOverride({
|
||||
title: '比赛开始',
|
||||
body: `${start.label || '开始点'}已激活,按提示前往下一个目标点。`,
|
||||
autoPopup: true,
|
||||
once: false,
|
||||
priority: 1,
|
||||
}, controlContentOverrides[startId]),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -56,23 +88,35 @@ export function buildGameDefinitionFromCourse(
|
||||
point: control.point,
|
||||
sequence: control.sequence,
|
||||
score,
|
||||
displayContent: {
|
||||
displayContent: applyDisplayContentOverride({
|
||||
title: score !== null ? `收集 ${label} (+${score}分)` : `收集 ${label}`,
|
||||
body: score !== null ? `${buildDisplayBody(label, control.sequence)} · ${score}分` : buildDisplayBody(label, control.sequence),
|
||||
},
|
||||
autoPopup: true,
|
||||
once: false,
|
||||
priority: 1,
|
||||
}, controlContentOverrides[controlId]),
|
||||
})
|
||||
}
|
||||
|
||||
for (const finish of course.layers.finishes) {
|
||||
for (let finishIndex = 0; finishIndex < course.layers.finishes.length; finishIndex += 1) {
|
||||
const finish = course.layers.finishes[finishIndex]
|
||||
const finishId = `finish-${finishIndex + 1}`
|
||||
const legacyFinishId = `finish-${controls.length + 1}`
|
||||
controls.push({
|
||||
id: `finish-${controls.length + 1}`,
|
||||
id: finishId,
|
||||
code: finish.label || 'F',
|
||||
label: finish.label || 'Finish',
|
||||
kind: 'finish',
|
||||
point: finish.point,
|
||||
sequence: null,
|
||||
score: null,
|
||||
displayContent: null,
|
||||
displayContent: applyDisplayContentOverride({
|
||||
title: '完成路线',
|
||||
body: `${finish.label || '结束点'}已完成,准备查看本局结果。`,
|
||||
autoPopup: true,
|
||||
once: false,
|
||||
priority: 2,
|
||||
}, controlContentOverrides[finishId] || controlContentOverrides[legacyFinishId]),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,17 @@ export type PunchPolicyType = 'enter' | 'enter-confirm'
|
||||
export interface GameControlDisplayContent {
|
||||
title: string
|
||||
body: string
|
||||
autoPopup: boolean
|
||||
once: boolean
|
||||
priority: number
|
||||
}
|
||||
|
||||
export interface GameControlDisplayContentOverride {
|
||||
title?: string
|
||||
body?: string
|
||||
autoPopup?: boolean
|
||||
once?: boolean
|
||||
priority?: number
|
||||
}
|
||||
|
||||
export interface GameControl {
|
||||
|
||||
@@ -5,7 +5,7 @@ export type GameEffect =
|
||||
| { type: 'session_started' }
|
||||
| { type: 'session_cancelled' }
|
||||
| { type: 'punch_feedback'; text: string; tone: 'neutral' | 'success' | 'warning' }
|
||||
| { type: 'control_completed'; controlId: string; controlKind: 'start' | 'control' | 'finish'; sequence: number | null; label: string; displayTitle: string; displayBody: string }
|
||||
| { type: 'control_completed'; controlId: string; controlKind: 'start' | 'control' | 'finish'; sequence: number | null; label: string; displayTitle: string; displayBody: string; displayAutoPopup: boolean; displayOnce: boolean; displayPriority: number }
|
||||
| { type: 'guidance_state_changed'; guidanceState: GuidanceState; controlId: string | null }
|
||||
| { type: 'session_finished' }
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
|
||||
export interface UiEffectHost {
|
||||
showPunchFeedback: (text: string, tone: 'neutral' | 'success' | 'warning', motionClass?: string) => void
|
||||
showContentCard: (title: string, body: string, motionClass?: string) => void
|
||||
showContentCard: (title: string, body: string, motionClass?: string, options?: { contentKey?: string; autoPopup?: boolean; once?: boolean; priority?: number }) => void
|
||||
setPunchButtonFxClass: (className: string) => void
|
||||
setHudProgressFxClass: (className: string) => void
|
||||
setHudDistanceFxClass: (className: string) => void
|
||||
@@ -262,6 +262,12 @@ export class UiEffectDirector {
|
||||
effect.displayTitle,
|
||||
effect.displayBody,
|
||||
cue ? this.getContentCardMotionClass(cue.contentCardMotion) : '',
|
||||
{
|
||||
contentKey: effect.controlId,
|
||||
autoPopup: effect.displayAutoPopup,
|
||||
once: effect.displayOnce,
|
||||
priority: effect.displayPriority,
|
||||
},
|
||||
)
|
||||
if (cue && cue.mapPulseMotion !== 'none') {
|
||||
this.host.showMapPulse(effect.controlId, this.getMapPulseMotionClass(cue.mapPulseMotion))
|
||||
|
||||
91
miniprogram/game/result/resultSummary.ts
Normal file
91
miniprogram/game/result/resultSummary.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
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 },
|
||||
],
|
||||
}
|
||||
}
|
||||
@@ -287,8 +287,11 @@ function buildCompletedEffect(control: GameControl): GameEffect {
|
||||
controlKind: 'start',
|
||||
sequence: null,
|
||||
label: control.label,
|
||||
displayTitle: '比赛开始',
|
||||
displayBody: '已完成开始点打卡,前往 1 号点。',
|
||||
displayTitle: control.displayContent ? control.displayContent.title : '比赛开始',
|
||||
displayBody: control.displayContent ? control.displayContent.body : '已完成开始点打卡,前往 1 号点。',
|
||||
displayAutoPopup: control.displayContent ? control.displayContent.autoPopup : true,
|
||||
displayOnce: control.displayContent ? control.displayContent.once : false,
|
||||
displayPriority: control.displayContent ? control.displayContent.priority : 1,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,8 +302,11 @@ function buildCompletedEffect(control: GameControl): GameEffect {
|
||||
controlKind: 'finish',
|
||||
sequence: null,
|
||||
label: control.label,
|
||||
displayTitle: '比赛结束',
|
||||
displayBody: '已完成终点打卡,本局结束。',
|
||||
displayTitle: control.displayContent ? control.displayContent.title : '比赛结束',
|
||||
displayBody: control.displayContent ? control.displayContent.body : '已完成终点打卡,本局结束。',
|
||||
displayAutoPopup: control.displayContent ? control.displayContent.autoPopup : true,
|
||||
displayOnce: control.displayContent ? control.displayContent.once : false,
|
||||
displayPriority: control.displayContent ? control.displayContent.priority : 2,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,6 +322,9 @@ function buildCompletedEffect(control: GameControl): GameEffect {
|
||||
label: control.label,
|
||||
displayTitle,
|
||||
displayBody,
|
||||
displayAutoPopup: control.displayContent ? control.displayContent.autoPopup : true,
|
||||
displayOnce: control.displayContent ? control.displayContent.once : false,
|
||||
displayPriority: control.displayContent ? control.displayContent.priority : 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -249,8 +249,11 @@ function buildCompletedEffect(control: GameControl): GameEffect {
|
||||
controlKind: 'start',
|
||||
sequence: null,
|
||||
label: control.label,
|
||||
displayTitle: '比赛开始',
|
||||
displayBody: '已完成开始点打卡,开始自由打点。',
|
||||
displayTitle: control.displayContent ? control.displayContent.title : '比赛开始',
|
||||
displayBody: control.displayContent ? control.displayContent.body : '已完成开始点打卡,开始自由打点。',
|
||||
displayAutoPopup: control.displayContent ? control.displayContent.autoPopup : true,
|
||||
displayOnce: control.displayContent ? control.displayContent.once : false,
|
||||
displayPriority: control.displayContent ? control.displayContent.priority : 1,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,8 +264,11 @@ function buildCompletedEffect(control: GameControl): GameEffect {
|
||||
controlKind: 'finish',
|
||||
sequence: null,
|
||||
label: control.label,
|
||||
displayTitle: '比赛结束',
|
||||
displayBody: '已完成终点打卡,本局结束。',
|
||||
displayTitle: control.displayContent ? control.displayContent.title : '比赛结束',
|
||||
displayBody: control.displayContent ? control.displayContent.body : '已完成终点打卡,本局结束。',
|
||||
displayAutoPopup: control.displayContent ? control.displayContent.autoPopup : true,
|
||||
displayOnce: control.displayContent ? control.displayContent.once : false,
|
||||
displayPriority: control.displayContent ? control.displayContent.priority : 2,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,6 +281,9 @@ function buildCompletedEffect(control: GameControl): GameEffect {
|
||||
label: control.label,
|
||||
displayTitle: control.displayContent ? control.displayContent.title : `收集 ${sequenceText}`,
|
||||
displayBody: control.displayContent ? control.displayContent.body : control.label,
|
||||
displayAutoPopup: control.displayContent ? control.displayContent.autoPopup : true,
|
||||
displayOnce: control.displayContent ? control.displayContent.once : false,
|
||||
displayPriority: control.displayContent ? control.displayContent.priority : 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user