refactor: 收口公开作品详情映射
This commit is contained in:
@@ -1,4 +1,17 @@
|
||||
import type { BarkBattleWorkSummary } from '../../../packages/shared/src/contracts/barkBattle';
|
||||
import type { BigFishWorkSummary } from '../../../packages/shared/src/contracts/bigFishWorkSummary';
|
||||
import type {
|
||||
JumpHopGalleryCardResponse,
|
||||
JumpHopWorkProfileResponse,
|
||||
} from '../../../packages/shared/src/contracts/jumpHop';
|
||||
import type { PuzzleWorkSummary } from '../../../packages/shared/src/contracts/puzzleWorkSummary';
|
||||
import type { CustomWorldGalleryCard } from '../../../packages/shared/src/contracts/runtime';
|
||||
import type { SquareHoleWorkSummary } from '../../../packages/shared/src/contracts/squareHoleWorks';
|
||||
import type { VisualNovelWorkSummary } from '../../../packages/shared/src/contracts/visualNovel';
|
||||
import type {
|
||||
WoodenFishGalleryCardResponse,
|
||||
WoodenFishWorkProfileResponse,
|
||||
} from '../../../packages/shared/src/contracts/woodenFish';
|
||||
import { buildPublicWorkStagePath } from '../../routing/appPageRoutes';
|
||||
import {
|
||||
isBarkBattleGalleryEntry,
|
||||
@@ -10,6 +23,13 @@ import {
|
||||
isSquareHoleGalleryEntry,
|
||||
isVisualNovelGalleryEntry,
|
||||
isWoodenFishGalleryEntry,
|
||||
mapBarkBattleWorkToPlatformGalleryCard,
|
||||
mapBigFishWorkToPlatformGalleryCard,
|
||||
mapJumpHopWorkToPlatformGalleryCard,
|
||||
mapPuzzleWorkToPlatformGalleryCard,
|
||||
mapSquareHoleWorkToPlatformGalleryCard,
|
||||
mapVisualNovelWorkToPlatformGalleryCard,
|
||||
mapWoodenFishWorkToPlatformGalleryCard,
|
||||
type PlatformPublicGalleryCard,
|
||||
} from '../rpg-entry/rpgEntryWorldPresentation';
|
||||
import {
|
||||
@@ -94,6 +114,202 @@ export function isRpgPublicWorkDetailEntry(
|
||||
return !('sourceType' in entry);
|
||||
}
|
||||
|
||||
export function mapRpgGalleryCardToPublicWorkDetail(
|
||||
entry: CustomWorldGalleryCard,
|
||||
): PlatformPublicGalleryCard {
|
||||
return entry;
|
||||
}
|
||||
|
||||
export function mapPuzzleWorkToPublicWorkDetail(
|
||||
item: PuzzleWorkSummary,
|
||||
): PlatformPublicGalleryCard {
|
||||
return mapPuzzleWorkToPlatformGalleryCard(item);
|
||||
}
|
||||
|
||||
export function mapSquareHoleWorkToPublicWorkDetail(
|
||||
item: SquareHoleWorkSummary,
|
||||
): PlatformPublicGalleryCard {
|
||||
return mapSquareHoleWorkToPlatformGalleryCard(item);
|
||||
}
|
||||
|
||||
export function mapBigFishWorkToPublicWorkDetail(
|
||||
item: BigFishWorkSummary,
|
||||
): PlatformPublicGalleryCard {
|
||||
return mapBigFishWorkToPlatformGalleryCard(item);
|
||||
}
|
||||
|
||||
export function mapVisualNovelWorkToPublicWorkDetail(
|
||||
item: VisualNovelWorkSummary,
|
||||
): PlatformPublicGalleryCard {
|
||||
return mapVisualNovelWorkToPlatformGalleryCard(item);
|
||||
}
|
||||
|
||||
export function mapJumpHopWorkToPublicWorkDetail(
|
||||
item: JumpHopGalleryCardResponse | JumpHopWorkProfileResponse,
|
||||
): PlatformPublicGalleryCard {
|
||||
return mapJumpHopWorkToPlatformGalleryCard(item);
|
||||
}
|
||||
|
||||
export function mapBarkBattleWorkToPublicWorkDetail(
|
||||
item: BarkBattleWorkSummary,
|
||||
): PlatformPublicGalleryCard {
|
||||
return mapBarkBattleWorkToPlatformGalleryCard(item);
|
||||
}
|
||||
|
||||
export function mapWoodenFishWorkToPublicWorkDetail(
|
||||
item: WoodenFishGalleryCardResponse | WoodenFishWorkProfileResponse,
|
||||
): PlatformPublicGalleryCard {
|
||||
return mapWoodenFishWorkToPlatformGalleryCard(item);
|
||||
}
|
||||
|
||||
export function mapBarkBattlePublicDetailToWorkSummary(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
): BarkBattleWorkSummary | null {
|
||||
if (!isBarkBattleGalleryEntry(entry)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
workId: entry.workId,
|
||||
draftId: entry.sourceSessionId ?? null,
|
||||
ownerUserId: entry.ownerUserId,
|
||||
authorDisplayName: entry.authorDisplayName,
|
||||
title: entry.worldName,
|
||||
summary: entry.summaryText,
|
||||
themeDescription: entry.themeTags[0] ?? entry.summaryText,
|
||||
playerImageDescription: entry.themeTags[1] ?? entry.summaryText,
|
||||
opponentImageDescription: entry.themeTags[2] ?? entry.summaryText,
|
||||
onomatopoeia: undefined,
|
||||
playerCharacterImageSrc: entry.coverCharacterImageSrcs[0] ?? null,
|
||||
opponentCharacterImageSrc: entry.coverCharacterImageSrcs[1] ?? null,
|
||||
uiBackgroundImageSrc: entry.coverImageSrc,
|
||||
difficultyPreset: 'normal',
|
||||
status: 'published',
|
||||
generationStatus: 'ready',
|
||||
publishReady: true,
|
||||
playCount: entry.playCount ?? 0,
|
||||
recentPlayCount7d: entry.recentPlayCount7d ?? 0,
|
||||
updatedAt: entry.updatedAt,
|
||||
publishedAt: entry.publishedAt,
|
||||
};
|
||||
}
|
||||
|
||||
export function mapPublicWorkDetailToPuzzleWork(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
): PuzzleWorkSummary | null {
|
||||
if (!isPuzzleGalleryEntry(entry)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
workId: entry.workId,
|
||||
profileId: entry.profileId,
|
||||
ownerUserId: entry.ownerUserId,
|
||||
sourceSessionId:
|
||||
'sourceSessionId' in entry && typeof entry.sourceSessionId === 'string'
|
||||
? entry.sourceSessionId
|
||||
: null,
|
||||
authorDisplayName: entry.authorDisplayName,
|
||||
levelName: entry.worldName,
|
||||
summary: entry.summaryText,
|
||||
themeTags: entry.themeTags,
|
||||
coverImageSrc: entry.coverImageSrc,
|
||||
publicationStatus: 'published',
|
||||
updatedAt: entry.updatedAt,
|
||||
publishedAt: entry.publishedAt,
|
||||
playCount: entry.playCount ?? 0,
|
||||
remixCount: entry.remixCount ?? 0,
|
||||
likeCount: entry.likeCount ?? 0,
|
||||
pointIncentiveTotalHalfPoints: 0,
|
||||
pointIncentiveClaimedPoints: 0,
|
||||
pointIncentiveTotalPoints: 0,
|
||||
pointIncentiveClaimablePoints: 0,
|
||||
publishReady: true,
|
||||
levels:
|
||||
entry.coverSlides?.map((slide, index) => ({
|
||||
levelId: slide.id || `puzzle-level-${index + 1}`,
|
||||
levelName: slide.label,
|
||||
pictureDescription: entry.summaryText,
|
||||
candidates: [],
|
||||
selectedCandidateId: null,
|
||||
coverImageSrc: slide.imageSrc,
|
||||
coverAssetId: null,
|
||||
generationStatus: 'ready' as const,
|
||||
})) ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
export function mapPublicWorkDetailToBigFishWork(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
): BigFishWorkSummary | null {
|
||||
if (!isBigFishGalleryEntry(entry)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const levelCount = Number.parseInt(
|
||||
entry.themeTags.find((tag) => /^\d+级$/u.test(tag))?.replace('级', '') ??
|
||||
'0',
|
||||
10,
|
||||
);
|
||||
|
||||
return {
|
||||
workId: entry.workId,
|
||||
sourceSessionId: entry.profileId,
|
||||
ownerUserId: entry.ownerUserId,
|
||||
authorDisplayName: entry.authorDisplayName,
|
||||
title: entry.worldName,
|
||||
subtitle: entry.subtitle,
|
||||
summary: entry.summaryText,
|
||||
coverImageSrc: entry.coverImageSrc,
|
||||
status: 'published',
|
||||
updatedAt: entry.updatedAt,
|
||||
publishedAt: entry.publishedAt,
|
||||
publishReady: true,
|
||||
levelCount: Number.isNaN(levelCount) ? 0 : levelCount,
|
||||
levelMainImageReadyCount: 0,
|
||||
levelMotionReadyCount: 0,
|
||||
backgroundReady: Boolean(entry.coverImageSrc),
|
||||
playCount: entry.playCount ?? 0,
|
||||
remixCount: entry.remixCount ?? 0,
|
||||
likeCount: entry.likeCount ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
export function mapPublicWorkDetailToSquareHoleWork(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
): SquareHoleWorkSummary | null {
|
||||
if (!isSquareHoleGalleryEntry(entry)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
workId: entry.workId,
|
||||
profileId: entry.profileId,
|
||||
ownerUserId: entry.ownerUserId,
|
||||
sourceSessionId:
|
||||
'sourceSessionId' in entry && typeof entry.sourceSessionId === 'string'
|
||||
? entry.sourceSessionId
|
||||
: null,
|
||||
gameName: entry.worldName,
|
||||
themeText: entry.themeTags[0] ?? '方洞挑战',
|
||||
twistRule: entry.subtitle,
|
||||
summary: entry.summaryText,
|
||||
tags: entry.themeTags,
|
||||
coverImageSrc: entry.coverImageSrc,
|
||||
backgroundPrompt: entry.backgroundPrompt ?? '方洞挑战运行背景',
|
||||
backgroundImageSrc: entry.backgroundImageSrc ?? null,
|
||||
shapeOptions: entry.shapeOptions ?? [],
|
||||
holeOptions: entry.holeOptions ?? [],
|
||||
shapeCount: entry.shapeCount ?? 8,
|
||||
difficulty: entry.difficulty ?? 4,
|
||||
publicationStatus: 'published',
|
||||
playCount: entry.playCount ?? 0,
|
||||
updatedAt: entry.updatedAt,
|
||||
publishedAt: entry.publishedAt,
|
||||
publishReady: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function getPlatformPublicWorkDetailKind(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
): PlatformPublicWorkDetailKind {
|
||||
|
||||
Reference in New Issue
Block a user