完善文创展示控制与结果层基础
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]),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user