refactor: 收口创作入口启动意图

This commit is contained in:
2026-06-04 02:20:48 +08:00
parent 5ba5ca6bf8
commit 83ae363670
7 changed files with 243 additions and 62 deletions

View File

@@ -394,6 +394,10 @@ import {
mergeBarkBattleWorkSummary,
shouldPreserveLocalBarkBattleWorkOnRefresh,
} from './barkBattleWorkCache';
import {
type PlatformCreationLaunchTarget,
resolvePlatformCreationLaunchIntent,
} from './platformCreationLaunchModel';
import {
buildBabyObjectMatchCreationUrlState,
buildBarkBattleCreationUrlState,
@@ -6701,7 +6705,12 @@ export function PlatformEntryFlowShellImpl({
const handleCreationHubCreateType = useCallback(
(type: PlatformCreationTypeId) => {
if (type === 'airp') {
const intent = resolvePlatformCreationLaunchIntent({
type,
isBabyObjectMatchVisible,
});
if (!intent.shouldPrepare) {
return;
}
@@ -6709,79 +6718,49 @@ export function PlatformEntryFlowShellImpl({
return;
}
if (type === 'baby-object-match' && !isBabyObjectMatchVisible) {
sessionController.setCreationTypeError(EDUTAINMENT_HIDDEN_MESSAGE);
if (intent.type === 'blocked') {
sessionController.setCreationTypeError(intent.message);
return;
}
if (type === 'rpg') {
runProtectedAction(() => {
if (intent.type !== 'launch') {
return;
}
const launchers = {
rpg: () => {
void sessionController.openRpgAgentWorkspace();
});
return;
}
if (type === 'big-fish') {
runProtectedAction(() => {
},
'big-fish': () => {
void openBigFishAgentWorkspace();
});
return;
}
if (type === 'match3d') {
runProtectedAction(() => {
},
match3d: () => {
void openMatch3DWorkspace();
});
return;
}
if (type === 'square-hole') {
runProtectedAction(() => {
},
'square-hole': () => {
void openSquareHoleAgentWorkspace();
});
return;
}
if (type === 'jump-hop') {
runProtectedAction(() => {
},
'jump-hop': () => {
void openJumpHopWorkspace();
});
return;
}
if (type === 'wooden-fish') {
runProtectedAction(() => {
},
'wooden-fish': () => {
void openWoodenFishWorkspace();
});
return;
}
if (type === 'puzzle') {
runProtectedAction(() => {
},
puzzle: () => {
void openPuzzleWorkspace();
});
return;
}
if (type === 'bark-battle') {
runProtectedAction(() => {
},
'bark-battle': () => {
void openBarkBattleWorkspace();
});
return;
}
if (type === 'visual-novel') {
runProtectedAction(() => {
},
'visual-novel': () => {
void openVisualNovelWorkspace();
});
return;
}
if (type === 'baby-object-match') {
runProtectedAction(() => {
},
'baby-object-match': () => {
void openBabyObjectMatchWorkspace();
});
}
},
} satisfies Record<PlatformCreationLaunchTarget, () => void>;
runProtectedAction(launchers[intent.target]);
},
[
isBabyObjectMatchVisible,

View File

@@ -0,0 +1,76 @@
import { describe, expect, test } from 'vitest';
import {
type PlatformCreationLaunchTarget,
resolvePlatformCreationLaunchIntent,
} from './platformCreationLaunchModel';
import { EDUTAINMENT_HIDDEN_MESSAGE } from './platformEdutainmentVisibility';
describe('platformCreationLaunchModel', () => {
test('keeps airp as a placeholder noop before prepare', () => {
expect(
resolvePlatformCreationLaunchIntent({
type: 'airp',
isBabyObjectMatchVisible: true,
}),
).toEqual({
type: 'noop',
shouldPrepare: false,
reason: 'placeholder',
});
});
test('blocks hidden baby object match after prepare', () => {
expect(
resolvePlatformCreationLaunchIntent({
type: 'baby-object-match',
isBabyObjectMatchVisible: false,
}),
).toEqual({
type: 'blocked',
shouldPrepare: true,
message: EDUTAINMENT_HIDDEN_MESSAGE,
});
});
test('resolves known creation launch targets', () => {
const targets: PlatformCreationLaunchTarget[] = [
'rpg',
'big-fish',
'match3d',
'square-hole',
'jump-hop',
'wooden-fish',
'puzzle',
'bark-battle',
'visual-novel',
'baby-object-match',
];
targets.forEach((target) => {
expect(
resolvePlatformCreationLaunchIntent({
type: target,
isBabyObjectMatchVisible: true,
}),
).toEqual({
type: 'launch',
shouldPrepare: true,
target,
});
});
});
test('keeps unknown creation type as a prepared noop', () => {
expect(
resolvePlatformCreationLaunchIntent({
type: 'unknown-template',
isBabyObjectMatchVisible: true,
}),
).toEqual({
type: 'noop',
shouldPrepare: true,
reason: 'unknown',
});
});
});

View File

@@ -0,0 +1,87 @@
import { EDUTAINMENT_HIDDEN_MESSAGE } from './platformEdutainmentVisibility';
import type { PlatformCreationTypeId } from './platformEntryCreationTypes';
export type PlatformCreationLaunchTarget =
| 'rpg'
| 'big-fish'
| 'match3d'
| 'square-hole'
| 'jump-hop'
| 'wooden-fish'
| 'puzzle'
| 'bark-battle'
| 'visual-novel'
| 'baby-object-match';
export type PlatformCreationLaunchIntent =
| {
type: 'noop';
shouldPrepare: false;
reason: 'placeholder';
}
| {
type: 'noop';
shouldPrepare: true;
reason: 'unknown';
}
| {
type: 'blocked';
shouldPrepare: true;
message: string;
}
| {
type: 'launch';
shouldPrepare: true;
target: PlatformCreationLaunchTarget;
};
const PLATFORM_CREATION_LAUNCH_TARGETS = new Set<PlatformCreationTypeId>([
'rpg',
'big-fish',
'match3d',
'square-hole',
'jump-hop',
'wooden-fish',
'puzzle',
'bark-battle',
'visual-novel',
'baby-object-match',
]);
export function resolvePlatformCreationLaunchIntent(params: {
type: PlatformCreationTypeId;
isBabyObjectMatchVisible: boolean;
}): PlatformCreationLaunchIntent {
if (params.type === 'airp') {
return {
type: 'noop',
shouldPrepare: false,
reason: 'placeholder',
};
}
if (
params.type === 'baby-object-match' &&
!params.isBabyObjectMatchVisible
) {
return {
type: 'blocked',
shouldPrepare: true,
message: EDUTAINMENT_HIDDEN_MESSAGE,
};
}
if (!PLATFORM_CREATION_LAUNCH_TARGETS.has(params.type)) {
return {
type: 'noop',
shouldPrepare: true,
reason: 'unknown',
};
}
return {
type: 'launch',
shouldPrepare: true,
target: params.type as PlatformCreationLaunchTarget,
};
}