80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
import type {
|
|
MiniGameDraftGenerationKind,
|
|
MiniGameDraftGenerationState,
|
|
} from '../../services/miniGameDraftGenerationProgress';
|
|
import type { SelectionStage } from './platformEntryTypes';
|
|
|
|
export type PlatformVisualNovelGenerationPhase =
|
|
| 'generating'
|
|
| 'ready'
|
|
| 'failed';
|
|
|
|
export type PlatformGenerationProgressTickKind =
|
|
| MiniGameDraftGenerationKind
|
|
| 'visual-novel';
|
|
|
|
export type PlatformGenerationProgressTickInput = {
|
|
selectionStage: SelectionStage;
|
|
miniGameStates: Partial<
|
|
Record<MiniGameDraftGenerationKind, MiniGameDraftGenerationState | null>
|
|
>;
|
|
visualNovel: {
|
|
startedAtMs: number | null;
|
|
phase: PlatformVisualNovelGenerationPhase;
|
|
};
|
|
};
|
|
|
|
export type PlatformGenerationProgressTickDecision = {
|
|
activeKind: PlatformGenerationProgressTickKind | null;
|
|
shouldTick: boolean;
|
|
};
|
|
|
|
const MINI_GAME_GENERATION_STAGE_TO_KIND: Partial<
|
|
Record<SelectionStage, MiniGameDraftGenerationKind>
|
|
> = {
|
|
'puzzle-generating': 'puzzle',
|
|
'match3d-generating': 'match3d',
|
|
'big-fish-generating': 'big-fish',
|
|
'square-hole-generating': 'square-hole',
|
|
'jump-hop-generating': 'jump-hop',
|
|
'wooden-fish-generating': 'wooden-fish',
|
|
'baby-object-match-generating': 'baby-object-match',
|
|
};
|
|
|
|
function shouldTickMiniGameGenerationState(
|
|
state: MiniGameDraftGenerationState | null | undefined,
|
|
) {
|
|
return state != null && state.phase !== 'ready' && state.phase !== 'failed';
|
|
}
|
|
|
|
/** 收口生成页进度 tick 判定,壳层只保留 interval 副作用。 */
|
|
export function resolvePlatformGenerationProgressTickDecision(
|
|
input: PlatformGenerationProgressTickInput,
|
|
): PlatformGenerationProgressTickDecision {
|
|
if (input.selectionStage === 'visual-novel-generating') {
|
|
return {
|
|
activeKind: 'visual-novel',
|
|
shouldTick:
|
|
input.visualNovel.startedAtMs != null &&
|
|
input.visualNovel.phase !== 'ready' &&
|
|
input.visualNovel.phase !== 'failed',
|
|
};
|
|
}
|
|
|
|
const activeKind =
|
|
MINI_GAME_GENERATION_STAGE_TO_KIND[input.selectionStage] ?? null;
|
|
if (!activeKind) {
|
|
return {
|
|
activeKind: null,
|
|
shouldTick: false,
|
|
};
|
|
}
|
|
|
|
return {
|
|
activeKind,
|
|
shouldTick: shouldTickMiniGameGenerationState(
|
|
input.miniGameStates[activeKind],
|
|
),
|
|
};
|
|
}
|