feat: add puzzle clear template runtime

This commit is contained in:
2026-06-03 22:11:46 +08:00
parent 6e74cf5add
commit 1b5e098225
148 changed files with 19588 additions and 241 deletions

View File

@@ -0,0 +1,223 @@
import { ArrowLeft, Loader2, Play, RefreshCcw, Send } from 'lucide-react';
import { useState } from 'react';
import type {
PuzzleClearDraftResponse,
PuzzleClearWorkProfileResponse,
} from '../../../packages/shared/src/contracts/puzzleClear';
import { ResolvedAssetImage } from '../ResolvedAssetImage';
type PuzzleClearResultViewProps = {
profile: PuzzleClearDraftResponse | PuzzleClearWorkProfileResponse;
isBusy?: boolean;
error?: string | null;
onBack: () => void;
onEdit: () => void;
onStartTestRun: () => void;
onPublish: () => void;
onRegenerateAtlas: () => void;
};
function isPuzzleClearWorkProfile(
profile: PuzzleClearResultViewProps['profile'],
): profile is PuzzleClearWorkProfileResponse {
return 'summary' in profile;
}
function getDraft(profile: PuzzleClearResultViewProps['profile']) {
return isPuzzleClearWorkProfile(profile) ? profile.draft : profile;
}
export function PuzzleClearResultView({
profile,
isBusy = false,
error = null,
onBack,
onEdit,
onStartTestRun,
onPublish,
onRegenerateAtlas,
}: PuzzleClearResultViewProps) {
const [isPublishing, setIsPublishing] = useState(false);
const isWorkProfile = isPuzzleClearWorkProfile(profile);
const draft = getDraft(profile);
const summary = isWorkProfile ? profile.summary : null;
const title = summary?.workTitle?.trim() || draft.workTitle.trim() || '拼消消';
const description =
summary?.workDescription?.trim() || draft.workDescription.trim();
const boardBackgroundAsset = isWorkProfile
? profile.boardBackgroundAsset ?? draft.boardBackgroundAsset
: draft.boardBackgroundAsset;
const atlasAsset = isWorkProfile ? profile.atlasAsset : draft.atlasAsset;
const patternGroups = isWorkProfile ? profile.patternGroups : draft.patternGroups;
const cardAssets = isWorkProfile ? profile.cardAssets : draft.cardAssets;
const previewCards = cardAssets.slice(0, 24);
const canPublish = Boolean(isWorkProfile && summary?.publishReady);
const handlePublish = async () => {
setIsPublishing(true);
try {
await Promise.resolve(onPublish());
} finally {
setIsPublishing(false);
}
};
return (
<div className="platform-remap-surface mx-auto flex h-full min-h-0 w-full max-w-6xl flex-col px-3 pb-3 pt-3 sm:px-4 sm:pt-4">
<div className="mb-3 flex items-center justify-between gap-3">
<button
type="button"
onClick={onBack}
className="platform-button platform-button--ghost min-h-0 px-3 py-2 text-sm"
>
<ArrowLeft className="h-4 w-4" />
</button>
<button
type="button"
onClick={onRegenerateAtlas}
disabled={isBusy}
className="platform-button platform-button--ghost min-h-0 px-3 py-2 text-sm"
>
<RefreshCcw className="h-4 w-4" />
</button>
</div>
<div className="grid min-h-0 flex-1 gap-3 lg:grid-cols-[minmax(0,1.05fr)_minmax(19rem,0.95fr)]">
<section className="platform-subpanel flex min-h-0 flex-col rounded-[1.25rem] p-4">
<div className="text-2xl font-black text-[var(--platform-text-strong)]">
{title}
</div>
{description ? (
<div className="mt-2 text-sm leading-6 text-[var(--platform-text-base)]">
{description}
</div>
) : null}
<div className="mt-4 grid min-h-0 flex-1 gap-3 sm:grid-cols-[minmax(0,0.92fr)_minmax(0,1.08fr)]">
<div className="overflow-hidden rounded-[1rem] border border-[var(--platform-subpanel-border)] bg-white/80">
{boardBackgroundAsset?.imageSrc ? (
<ResolvedAssetImage
src={boardBackgroundAsset.imageSrc}
alt="场地底图"
className="aspect-[9/16] h-full w-full object-cover"
/>
) : (
<div className="grid aspect-[9/16] place-items-center text-sm text-[var(--platform-text-soft)]">
</div>
)}
</div>
<div className="flex min-h-0 flex-col gap-3">
<div className="overflow-hidden rounded-[1rem] border border-[var(--platform-subpanel-border)] bg-white/80">
{atlasAsset?.imageSrc ? (
<ResolvedAssetImage
src={atlasAsset.imageSrc}
alt="素材图集"
className="aspect-square w-full object-cover"
/>
) : (
<div className="grid aspect-square place-items-center text-sm text-[var(--platform-text-soft)]">
</div>
)}
</div>
<div className="grid grid-cols-6 gap-1.5">
{previewCards.map((card) => (
<div
key={card.cardId}
className="aspect-square overflow-hidden rounded-[0.45rem] border border-white/80 bg-white shadow-sm"
>
<ResolvedAssetImage
src={card.imageSrc}
alt=""
className="h-full w-full object-cover"
/>
</div>
))}
</div>
</div>
</div>
</section>
<aside className="flex min-h-0 flex-col gap-3 overflow-y-auto">
<section className="platform-subpanel rounded-[1.25rem] p-4">
<div className="grid grid-cols-3 gap-2 text-center">
<div className="rounded-[0.9rem] bg-white/76 px-2 py-3">
<div className="text-xl font-black text-[var(--platform-text-strong)]">
{patternGroups.length}
</div>
<div className="mt-1 text-[0.68rem] font-bold tracking-[0.14em] text-[var(--platform-text-soft)]">
</div>
</div>
<div className="rounded-[0.9rem] bg-white/76 px-2 py-3">
<div className="text-xl font-black text-[var(--platform-text-strong)]">
{cardAssets.length}
</div>
<div className="mt-1 text-[0.68rem] font-bold tracking-[0.14em] text-[var(--platform-text-soft)]">
</div>
</div>
<div className="rounded-[0.9rem] bg-white/76 px-2 py-3">
<div className="text-xl font-black text-[var(--platform-text-strong)]">
{draft.generationStatus}
</div>
<div className="mt-1 text-[0.68rem] font-bold tracking-[0.14em] text-[var(--platform-text-soft)]">
</div>
</div>
</div>
</section>
{error ? (
<div className="platform-banner platform-banner--danger rounded-2xl text-sm leading-6">
{error}
</div>
) : null}
<section className="platform-subpanel mt-auto rounded-[1.25rem] p-4">
<div className="grid gap-2">
<button
type="button"
onClick={onStartTestRun}
disabled={isBusy || !isWorkProfile}
className="platform-button platform-button--primary min-h-11 justify-center gap-2 px-4 py-3"
>
<Play className="h-4 w-4" />
</button>
<button
type="button"
onClick={handlePublish}
disabled={isBusy || isPublishing || !canPublish}
className="platform-button platform-button--secondary min-h-11 justify-center gap-2 px-4 py-3"
>
{isPublishing ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<Send className="h-4 w-4" />
)}
</button>
<button
type="button"
onClick={onEdit}
disabled={isBusy}
className="platform-button platform-button--ghost min-h-11 justify-center px-4 py-3"
>
</button>
</div>
</section>
</aside>
</div>
</div>
);
}
export default PuzzleClearResultView;