refactor: 收口 Bark Battle work cache 规则
This commit is contained in:
@@ -381,10 +381,14 @@ import {
|
||||
} from '../visual-novel-creation/visualNovelEntryGeneration';
|
||||
import { createMockVisualNovelRunFromDraft } from '../visual-novel-runtime/visualNovelMockData';
|
||||
import {
|
||||
type BarkBattleGenerationStatus,
|
||||
buildBarkBattlePublishedConfigFromDraft,
|
||||
buildBarkBattlePublishedConfigFromWork,
|
||||
buildBarkBattlePublishSnapshot,
|
||||
buildBarkBattleWorkSummaryFromDraft,
|
||||
mergeBarkBattlePublishedConfigAssets,
|
||||
mergeBarkBattleWorksByWorkId,
|
||||
mergeBarkBattleWorkSummary,
|
||||
resolveBarkBattleDraftGenerationStatus,
|
||||
shouldPreserveLocalBarkBattleWorkOnRefresh,
|
||||
} from './barkBattleWorkCache';
|
||||
import {
|
||||
@@ -712,30 +716,6 @@ const PUZZLE_DRAFT_GENERATION_POINT_COST = 2;
|
||||
const MATCH3D_DRAFT_GENERATION_POINT_COST = 10;
|
||||
const BARK_BATTLE_DRAFT_GENERATION_POINT_COST = 3;
|
||||
|
||||
function mapBarkBattleWorkToPublishedConfig(
|
||||
work: BarkBattleWorkSummary,
|
||||
): BarkBattlePublishedConfig {
|
||||
return {
|
||||
workId: work.workId,
|
||||
draftId: work.draftId ?? null,
|
||||
configVersion: 1,
|
||||
rulesetVersion: 'bark-battle-ruleset-v1',
|
||||
playTypeId: 'bark-battle',
|
||||
title: work.title,
|
||||
description: work.summary,
|
||||
themeDescription: work.themeDescription,
|
||||
playerImageDescription: work.playerImageDescription,
|
||||
opponentImageDescription: work.opponentImageDescription,
|
||||
onomatopoeia: work.onomatopoeia,
|
||||
playerCharacterImageSrc: work.playerCharacterImageSrc ?? undefined,
|
||||
opponentCharacterImageSrc: work.opponentCharacterImageSrc ?? undefined,
|
||||
uiBackgroundImageSrc: work.uiBackgroundImageSrc ?? undefined,
|
||||
difficultyPreset: work.difficultyPreset,
|
||||
updatedAt: work.updatedAt,
|
||||
publishedAt: work.publishedAt ?? work.updatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
function mapVisualNovelWorkDetailToSession(
|
||||
work: VisualNovelWorkDetail,
|
||||
): VisualNovelAgentSessionSnapshot {
|
||||
@@ -1004,24 +984,6 @@ function mergeBigFishWorkSummary(
|
||||
: current;
|
||||
}
|
||||
|
||||
function hasBarkBattleDraftRequiredImages(draft: BarkBattleDraftConfig) {
|
||||
return Boolean(
|
||||
draft.playerCharacterImageSrc?.trim() &&
|
||||
draft.opponentCharacterImageSrc?.trim() &&
|
||||
draft.uiBackgroundImageSrc?.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
function resolveBarkBattleDraftGenerationStatus(
|
||||
draft: BarkBattleDraftConfig,
|
||||
partialFailed: boolean,
|
||||
): BarkBattleGenerationStatus {
|
||||
if (hasBarkBattleDraftRequiredImages(draft)) {
|
||||
return 'ready';
|
||||
}
|
||||
return partialFailed ? 'partial_failed' : 'pending_assets';
|
||||
}
|
||||
|
||||
async function resolvePublicWorkAuthorSummary(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
): Promise<PublicUserSummary | null> {
|
||||
@@ -6190,39 +6152,18 @@ export function PlatformEntryFlowShellImpl({
|
||||
],
|
||||
);
|
||||
|
||||
const buildBarkBattleDraftRuntimeConfig = useCallback(
|
||||
(draft: BarkBattleDraftConfig): BarkBattlePublishedConfig => ({
|
||||
workId: draft.workId ?? draft.draftId,
|
||||
draftId: draft.draftId,
|
||||
configVersion: draft.configVersion ?? 1,
|
||||
rulesetVersion: draft.rulesetVersion ?? 'bark-battle-ruleset-v1',
|
||||
playTypeId: 'bark-battle',
|
||||
title: draft.title,
|
||||
description: draft.description,
|
||||
themeDescription: draft.themeDescription,
|
||||
playerImageDescription: draft.playerImageDescription,
|
||||
opponentImageDescription: draft.opponentImageDescription,
|
||||
onomatopoeia: draft.onomatopoeia,
|
||||
playerCharacterImageSrc: draft.playerCharacterImageSrc,
|
||||
opponentCharacterImageSrc: draft.opponentCharacterImageSrc,
|
||||
uiBackgroundImageSrc: draft.uiBackgroundImageSrc,
|
||||
difficultyPreset: draft.difficultyPreset,
|
||||
updatedAt: draft.updatedAt,
|
||||
publishedAt: draft.updatedAt,
|
||||
}),
|
||||
[],
|
||||
);
|
||||
|
||||
const testBarkBattleDraft = useCallback(
|
||||
(draft: BarkBattleDraftConfig) => {
|
||||
setBarkBattleError(null);
|
||||
setBarkBattleRuntimeMode('draft');
|
||||
setBarkBattleRuntimeReturnStage('bark-battle-result');
|
||||
setBarkBattlePublishedConfig(buildBarkBattleDraftRuntimeConfig(draft));
|
||||
setBarkBattlePublishedConfig(
|
||||
buildBarkBattlePublishedConfigFromDraft(draft),
|
||||
);
|
||||
selectionStageRef.current = 'bark-battle-runtime';
|
||||
setSelectionStage('bark-battle-runtime');
|
||||
},
|
||||
[buildBarkBattleDraftRuntimeConfig, setSelectionStage],
|
||||
[setSelectionStage],
|
||||
);
|
||||
|
||||
const publishBarkBattleDraft = useCallback(
|
||||
@@ -6237,39 +6178,15 @@ export function PlatformEntryFlowShellImpl({
|
||||
}
|
||||
setIsBarkBattleBusy(true);
|
||||
try {
|
||||
const publishedSnapshot: BarkBattleConfigEditorPayload = {
|
||||
title: draft.title,
|
||||
description: draft.description,
|
||||
themeDescription: draft.themeDescription,
|
||||
playerImageDescription: draft.playerImageDescription,
|
||||
opponentImageDescription: draft.opponentImageDescription,
|
||||
onomatopoeia: draft.onomatopoeia,
|
||||
...(draft.playerCharacterImageSrc
|
||||
? { playerCharacterImageSrc: draft.playerCharacterImageSrc }
|
||||
: {}),
|
||||
...(draft.opponentCharacterImageSrc
|
||||
? { opponentCharacterImageSrc: draft.opponentCharacterImageSrc }
|
||||
: {}),
|
||||
...(draft.uiBackgroundImageSrc
|
||||
? { uiBackgroundImageSrc: draft.uiBackgroundImageSrc }
|
||||
: {}),
|
||||
difficultyPreset: draft.difficultyPreset,
|
||||
};
|
||||
const published = await publishBarkBattleWork({
|
||||
draftId: draft.draftId,
|
||||
workId,
|
||||
publishedSnapshot,
|
||||
publishedSnapshot: buildBarkBattlePublishSnapshot(draft),
|
||||
});
|
||||
const publishedWithAssets: BarkBattlePublishedConfig = {
|
||||
...published,
|
||||
playerCharacterImageSrc:
|
||||
published.playerCharacterImageSrc ?? draft.playerCharacterImageSrc,
|
||||
opponentCharacterImageSrc:
|
||||
published.opponentCharacterImageSrc ??
|
||||
draft.opponentCharacterImageSrc,
|
||||
uiBackgroundImageSrc:
|
||||
published.uiBackgroundImageSrc ?? draft.uiBackgroundImageSrc,
|
||||
};
|
||||
const publishedWithAssets = mergeBarkBattlePublishedConfigAssets(
|
||||
published,
|
||||
draft,
|
||||
);
|
||||
const publicWorkCode = buildBarkBattlePublicWorkCode(
|
||||
publishedWithAssets.workId,
|
||||
);
|
||||
@@ -11597,7 +11514,9 @@ export function PlatformEntryFlowShellImpl({
|
||||
setBarkBattleError(null);
|
||||
setBarkBattleGenerationPartialFailed(false);
|
||||
setBarkBattleRuntimeMode('published');
|
||||
setBarkBattlePublishedConfig(mapBarkBattleWorkToPublishedConfig(item));
|
||||
setBarkBattlePublishedConfig(
|
||||
buildBarkBattlePublishedConfigFromWork(item),
|
||||
);
|
||||
setBarkBattleRuntimeReturnStage(returnStage);
|
||||
try {
|
||||
const runtimeGuestOptions = await buildRecommendRuntimeAuthOptions(
|
||||
|
||||
Reference in New Issue
Block a user