refactor: 收口推荐运行态就绪判定

This commit is contained in:
2026-06-04 01:19:23 +08:00
parent 8d3e14020f
commit 7301043afb
6 changed files with 170 additions and 68 deletions

View File

@@ -503,6 +503,7 @@ import {
import {
getPlatformPublicGalleryEntryKey,
getPlatformRecommendRuntimeKind,
isPlatformRecommendRuntimeReadyForEntry,
isSamePlatformPublicGalleryEntry,
mergePlatformPublicGalleryEntries,
type RecommendRuntimeKind,
@@ -600,18 +601,6 @@ type WoodenFishRuntimeReturnStage =
type VisualNovelEntryGenerationPhase = 'generating' | 'ready' | 'failed';
type BabyObjectMatchGenerationPhase = 'generating' | 'ready' | 'failed';
type RecommendRuntimeState = {
activeKind: RecommendRuntimeKind | null;
babyObjectMatchDraft: BabyObjectMatchDraft | null;
bigFishRun: BigFishRuntimeSnapshotResponse | null;
jumpHopRun: JumpHopRunResponse['run'] | null;
match3dRun: Match3DRunSnapshot | null;
puzzleRun: PuzzleRunSnapshot | null;
squareHoleRun: SquareHoleRunSnapshot | null;
visualNovelRun: VisualNovelRunSnapshot | null;
woodenFishRun: WoodenFishRunResponse['run'] | null;
};
type PuzzleSaveArchiveState = {
runtimeKind?: unknown;
entryProfileId?: unknown;
@@ -682,49 +671,6 @@ const PUZZLE_DRAFT_GENERATION_POINT_COST = 2;
const MATCH3D_DRAFT_GENERATION_POINT_COST = 10;
const BARK_BATTLE_DRAFT_GENERATION_POINT_COST = 3;
function isRecommendRuntimeReadyForEntry(
entry: PlatformPublicGalleryCard,
state: RecommendRuntimeState,
) {
const expectedKind = getPlatformRecommendRuntimeKind(entry);
if (state.activeKind !== expectedKind) {
return false;
}
if (expectedKind === 'big-fish') {
return Boolean(state.bigFishRun);
}
if (expectedKind === 'jump-hop') {
return Boolean(state.jumpHopRun);
}
if (expectedKind === 'wooden-fish') {
return Boolean(state.woodenFishRun);
}
if (expectedKind === 'match3d') {
return Boolean(state.match3dRun);
}
if (expectedKind === 'puzzle') {
return (
state.puzzleRun?.entryProfileId === entry.profileId ||
state.puzzleRun?.currentLevel?.profileId === entry.profileId
);
}
if (expectedKind === 'square-hole') {
return Boolean(state.squareHoleRun);
}
if (expectedKind === 'visual-novel') {
return Boolean(state.visualNovelRun);
}
if (expectedKind === 'bark-battle') {
return true;
}
if (expectedKind === 'edutainment') {
return Boolean(state.babyObjectMatchDraft);
}
return true;
}
function mapBarkBattleWorkToPublishedConfig(
work: BarkBattleWorkSummary,
): BarkBattlePublishedConfig {
@@ -13359,16 +13305,18 @@ export function PlatformEntryFlowShellImpl({
: null;
const isActiveRecommendRuntimeReady =
activeRecommendEntry !== null &&
isRecommendRuntimeReadyForEntry(activeRecommendEntry, {
isPlatformRecommendRuntimeReadyForEntry(activeRecommendEntry, {
activeKind: activeRecommendRuntimeKind,
babyObjectMatchDraft,
bigFishRun,
jumpHopRun,
match3dRun,
puzzleRun,
squareHoleRun,
visualNovelRun,
woodenFishRun,
hasBabyObjectMatchDraft: Boolean(babyObjectMatchDraft),
hasBigFishRun: Boolean(bigFishRun),
hasJumpHopRun: Boolean(jumpHopRun),
hasMatch3DRun: Boolean(match3dRun),
hasSquareHoleRun: Boolean(squareHoleRun),
hasVisualNovelRun: Boolean(visualNovelRun),
hasWoodenFishRun: Boolean(woodenFishRun),
puzzleRunEntryProfileId: puzzleRun?.entryProfileId ?? null,
puzzleRunCurrentLevelProfileId:
puzzleRun?.currentLevel?.profileId ?? null,
});
if (
(activeRecommendEntry !== null && isActiveRecommendRuntimeReady) ||

View File

@@ -13,6 +13,7 @@ import {
getPlatformPublicGalleryEntryKey,
getPlatformPublicGalleryEntryTime,
getPlatformRecommendRuntimeKind,
isPlatformRecommendRuntimeReadyForEntry,
isSamePlatformPublicGalleryEntry,
mergePlatformPublicGalleryEntries,
type PlatformRecommendRuntimeStartIntentDeps,
@@ -439,6 +440,94 @@ test('platform public gallery flow resolves recommend runtime bark battle priori
});
});
test('platform public gallery flow resolves recommend runtime readiness', () => {
expect(
isPlatformRecommendRuntimeReadyForEntry(buildTypedEntry('big-fish'), {
activeKind: 'puzzle',
hasBigFishRun: true,
}),
).toBe(false);
expect(
isPlatformRecommendRuntimeReadyForEntry(buildTypedEntry('big-fish'), {
activeKind: 'big-fish',
hasBigFishRun: true,
}),
).toBe(true);
expect(
isPlatformRecommendRuntimeReadyForEntry(buildTypedEntry('jump-hop'), {
activeKind: 'jump-hop',
hasJumpHopRun: true,
}),
).toBe(true);
expect(
isPlatformRecommendRuntimeReadyForEntry(buildTypedEntry('wooden-fish'), {
activeKind: 'wooden-fish',
hasWoodenFishRun: true,
}),
).toBe(true);
expect(
isPlatformRecommendRuntimeReadyForEntry(buildTypedEntry('match3d'), {
activeKind: 'match3d',
hasMatch3DRun: true,
}),
).toBe(true);
expect(
isPlatformRecommendRuntimeReadyForEntry(buildTypedEntry('square-hole'), {
activeKind: 'square-hole',
hasSquareHoleRun: true,
}),
).toBe(true);
expect(
isPlatformRecommendRuntimeReadyForEntry(buildTypedEntry('visual-novel'), {
activeKind: 'visual-novel',
hasVisualNovelRun: true,
}),
).toBe(true);
expect(
isPlatformRecommendRuntimeReadyForEntry(buildTypedEntry('bark-battle'), {
activeKind: 'bark-battle',
}),
).toBe(true);
expect(
isPlatformRecommendRuntimeReadyForEntry(buildRpgEntry(), {
activeKind: 'rpg',
}),
).toBe(true);
});
test('platform public gallery flow resolves puzzle and edutainment readiness details', () => {
const puzzleEntry = buildTypedEntry('puzzle', {
profileId: 'puzzle-profile',
});
expect(
isPlatformRecommendRuntimeReadyForEntry(puzzleEntry, {
activeKind: 'puzzle',
puzzleRunEntryProfileId: 'other-profile',
puzzleRunCurrentLevelProfileId: 'puzzle-profile',
}),
).toBe(true);
expect(
isPlatformRecommendRuntimeReadyForEntry(puzzleEntry, {
activeKind: 'puzzle',
puzzleRunEntryProfileId: 'other-profile',
puzzleRunCurrentLevelProfileId: 'another-profile',
}),
).toBe(false);
expect(
isPlatformRecommendRuntimeReadyForEntry(buildTypedEntry('edutainment'), {
activeKind: 'edutainment',
hasBabyObjectMatchDraft: true,
}),
).toBe(true);
expect(
isPlatformRecommendRuntimeReadyForEntry(buildTypedEntry('edutainment'), {
activeKind: 'edutainment',
hasBabyObjectMatchDraft: false,
}),
).toBe(false);
});
test('platform public gallery flow merges duplicate identities and sorts newest first', () => {
const staleRpgEntry = buildRpgEntry({
profileId: 'shared-rpg',

View File

@@ -114,6 +114,19 @@ export type PlatformRecommendRuntimeStartIntentDeps = {
) => Match3DWorkSummary | null;
};
export type PlatformRecommendRuntimeReadyState = {
activeKind: RecommendRuntimeKind | null;
hasBabyObjectMatchDraft?: boolean;
hasBigFishRun?: boolean;
hasJumpHopRun?: boolean;
hasMatch3DRun?: boolean;
hasSquareHoleRun?: boolean;
hasVisualNovelRun?: boolean;
hasWoodenFishRun?: boolean;
puzzleRunEntryProfileId?: string | null;
puzzleRunCurrentLevelProfileId?: string | null;
};
export function getPlatformPublicGalleryEntryTime(
entry: PlatformPublicGalleryCard,
) {
@@ -332,6 +345,49 @@ export function resolvePlatformRecommendRuntimeStartIntent(
};
}
export function isPlatformRecommendRuntimeReadyForEntry(
entry: PlatformPublicGalleryCard,
state: PlatformRecommendRuntimeReadyState,
) {
const expectedKind = getPlatformRecommendRuntimeKind(entry);
if (state.activeKind !== expectedKind) {
return false;
}
if (expectedKind === 'big-fish') {
return Boolean(state.hasBigFishRun);
}
if (expectedKind === 'jump-hop') {
return Boolean(state.hasJumpHopRun);
}
if (expectedKind === 'wooden-fish') {
return Boolean(state.hasWoodenFishRun);
}
if (expectedKind === 'match3d') {
return Boolean(state.hasMatch3DRun);
}
if (expectedKind === 'puzzle') {
return (
state.puzzleRunEntryProfileId === entry.profileId ||
state.puzzleRunCurrentLevelProfileId === entry.profileId
);
}
if (expectedKind === 'square-hole') {
return Boolean(state.hasSquareHoleRun);
}
if (expectedKind === 'visual-novel') {
return Boolean(state.hasVisualNovelRun);
}
if (expectedKind === 'bark-battle') {
return true;
}
if (expectedKind === 'edutainment') {
return Boolean(state.hasBabyObjectMatchDraft);
}
return true;
}
export function isSamePlatformPublicGalleryEntry(
left: PlatformPublicGalleryCard,
right: PlatformPublicGalleryCard,