feat: 收敛玩法运行时配置并加入故障恢复
This commit is contained in:
@@ -54,6 +54,36 @@ export class GameRuntime {
|
||||
return result
|
||||
}
|
||||
|
||||
restoreDefinition(definition: GameDefinition, state: GameSessionState): GameResult {
|
||||
this.definition = definition
|
||||
this.plugin = this.resolvePlugin(definition)
|
||||
this.state = {
|
||||
status: state.status,
|
||||
endReason: state.endReason,
|
||||
startedAt: state.startedAt,
|
||||
endedAt: state.endedAt,
|
||||
completedControlIds: state.completedControlIds.slice(),
|
||||
skippedControlIds: state.skippedControlIds.slice(),
|
||||
currentTargetControlId: state.currentTargetControlId,
|
||||
inRangeControlId: state.inRangeControlId,
|
||||
score: state.score,
|
||||
guidanceState: state.guidanceState,
|
||||
modeState: state.modeState
|
||||
? JSON.parse(JSON.stringify(state.modeState)) as Record<string, unknown>
|
||||
: null,
|
||||
}
|
||||
const result: GameResult = {
|
||||
nextState: this.state,
|
||||
presentation: this.plugin.buildPresentation(definition, this.state),
|
||||
effects: [],
|
||||
}
|
||||
this.presentation = result.presentation
|
||||
this.mapPresentation = result.presentation.map
|
||||
this.hudPresentation = result.presentation.hud
|
||||
this.lastResult = result
|
||||
return result
|
||||
}
|
||||
|
||||
startSession(startAt = Date.now()): GameResult {
|
||||
return this.dispatch({ type: 'session_started', at: startAt })
|
||||
}
|
||||
@@ -62,6 +92,7 @@ export class GameRuntime {
|
||||
if (!this.definition || !this.plugin || !this.state) {
|
||||
const emptyState: GameSessionState = {
|
||||
status: 'idle',
|
||||
endReason: null,
|
||||
startedAt: null,
|
||||
endedAt: null,
|
||||
completedControlIds: [],
|
||||
|
||||
Reference in New Issue
Block a user