Add configurable game flow, finish punching, and audio cues

This commit is contained in:
2026-03-23 19:35:17 +08:00
parent 3b4b3ee3ec
commit 48159be900
23 changed files with 1620 additions and 68 deletions

View File

@@ -0,0 +1,76 @@
import { type GameDefinition, type GameControl, type PunchPolicyType } from '../core/gameDefinition'
import { type OrienteeringCourseData } from '../../utils/orienteeringCourse'
function sortBySequence<T extends { sequence: number | null }>(items: T[]): T[] {
return [...items].sort((a, b) => (a.sequence || 0) - (b.sequence || 0))
}
function buildDisplayBody(label: string, sequence: number | null): string {
if (typeof sequence === 'number') {
return `检查点 ${sequence} · ${label || String(sequence)}`
}
return label
}
export function buildGameDefinitionFromCourse(
course: OrienteeringCourseData,
controlRadiusMeters: number,
mode: GameDefinition['mode'] = 'classic-sequential',
autoFinishOnLastControl = true,
punchPolicy: PunchPolicyType = 'enter-confirm',
punchRadiusMeters = 5,
): GameDefinition {
const controls: GameControl[] = []
for (const start of course.layers.starts) {
controls.push({
id: `start-${controls.length + 1}`,
code: start.label || 'S',
label: start.label || 'Start',
kind: 'start',
point: start.point,
sequence: null,
displayContent: null,
})
}
for (const control of sortBySequence(course.layers.controls)) {
const label = control.label || String(control.sequence)
controls.push({
id: `control-${control.sequence}`,
code: label,
label,
kind: 'control',
point: control.point,
sequence: control.sequence,
displayContent: {
title: `收集 ${label}`,
body: buildDisplayBody(label, control.sequence),
},
})
}
for (const finish of course.layers.finishes) {
controls.push({
id: `finish-${controls.length + 1}`,
code: finish.label || 'F',
label: finish.label || 'Finish',
kind: 'finish',
point: finish.point,
sequence: null,
displayContent: null,
})
}
return {
id: `course-${course.title || 'default'}`,
mode,
title: course.title || 'Classic Sequential',
controlRadiusMeters,
punchRadiusMeters,
punchPolicy,
controls,
autoFinishOnLastControl,
}
}