refactor: 收口 Bark Battle 草稿恢复映射

This commit is contained in:
2026-06-04 05:14:23 +08:00
parent 20a21ee78b
commit 9c96535073
6 changed files with 64 additions and 24 deletions

View File

@@ -380,6 +380,7 @@ import {
} from '../visual-novel-creation/visualNovelEntryGeneration';
import { createMockVisualNovelRunFromDraft } from '../visual-novel-runtime/visualNovelMockData';
import {
buildBarkBattleDraftConfigFromWorkSummary,
buildBarkBattlePublishedConfigFromDraft,
buildBarkBattlePublishedConfigFromWork,
buildBarkBattlePublishSnapshot,
@@ -11006,23 +11007,7 @@ export function PlatformEntryFlowShellImpl({
return;
}
const nextDraft: BarkBattleDraftConfig = {
draftId: item.draftId ?? item.workId,
workId: item.workId,
title: item.title,
description: item.summary,
themeDescription: item.themeDescription,
playerImageDescription: item.playerImageDescription,
opponentImageDescription: item.opponentImageDescription,
onomatopoeia: item.onomatopoeia,
playerCharacterImageSrc: item.playerCharacterImageSrc ?? undefined,
opponentCharacterImageSrc: item.opponentCharacterImageSrc ?? undefined,
uiBackgroundImageSrc: item.uiBackgroundImageSrc ?? undefined,
difficultyPreset: item.difficultyPreset,
configVersion: 1,
rulesetVersion: 'bark-battle-ruleset-v1',
updatedAt: item.updatedAt,
};
const nextDraft = buildBarkBattleDraftConfigFromWorkSummary(item);
setBarkBattleDraftConfig(nextDraft);
enterCreateTab();
selectionStageRef.current = isPersistedBarkBattleDraftGenerating(item)

View File

@@ -6,6 +6,7 @@ import type {
BarkBattleWorkSummary,
} from '../../../packages/shared/src/contracts/barkBattle';
import {
buildBarkBattleDraftConfigFromWorkSummary,
buildBarkBattlePublishedConfigFromDraft,
buildBarkBattlePublishedConfigFromWork,
buildBarkBattlePublishSnapshot,
@@ -29,6 +30,7 @@ function buildBarkBattleWork(
themeDescription: '阳光草坪声浪竞技场',
playerImageDescription: '戴红色围巾的柯基选手',
opponentImageDescription: '蓝色护目镜哈士奇对手',
onomatopoeia: ['汪', '破阵'],
playerCharacterImageSrc: '/generated-bark-battle/player.png',
opponentCharacterImageSrc: '/generated-bark-battle/opponent.png',
uiBackgroundImageSrc: '/generated-bark-battle/background.png',
@@ -184,6 +186,35 @@ test('builds work runtime config with publishedAt fallback', () => {
expect(config.playerCharacterImageSrc).toBe('/generated-bark-battle/player.png');
});
test('builds draft config from work summary with stable defaults', () => {
const config = buildBarkBattleDraftConfigFromWorkSummary(
buildBarkBattleWork({
draftId: null,
playerCharacterImageSrc: null,
opponentCharacterImageSrc: null,
uiBackgroundImageSrc: null,
}),
);
expect(config).toMatchObject({
draftId: 'BB-cache-race-12345678',
workId: 'BB-cache-race-12345678',
title: '汪汪测试杯',
description: '测试声浪赛',
themeDescription: '阳光草坪声浪竞技场',
playerImageDescription: '戴红色围巾的柯基选手',
opponentImageDescription: '蓝色护目镜哈士奇对手',
onomatopoeia: ['汪', '破阵'],
difficultyPreset: 'normal',
configVersion: 1,
rulesetVersion: 'bark-battle-ruleset-v1',
updatedAt: '2026-05-21T10:00:00.000Z',
});
expect(config.playerCharacterImageSrc).toBeUndefined();
expect(config.opponentCharacterImageSrc).toBeUndefined();
expect(config.uiBackgroundImageSrc).toBeUndefined();
});
test('builds publish snapshot without empty asset fields', () => {
const snapshot = buildBarkBattlePublishSnapshot(
buildBarkBattleDraft({

View File

@@ -142,6 +142,28 @@ export function buildBarkBattlePublishedConfigFromWork(
};
}
export function buildBarkBattleDraftConfigFromWorkSummary(
work: BarkBattleWorkSummary,
): BarkBattleDraftConfig {
return {
draftId: work.draftId ?? work.workId,
workId: work.workId,
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,
configVersion: 1,
rulesetVersion: 'bark-battle-ruleset-v1',
updatedAt: work.updatedAt,
};
}
export function shouldPreserveLocalBarkBattleWorkOnRefresh(
item: BarkBattleWorkSummary,
refreshed: readonly BarkBattleWorkSummary[],