File size: 4,769 Bytes
415a17d 55b1a24 ec2b26e fd1786e 8db63ba ec2b26e 415a17d 55b1a24 415a17d ececfe6 ec2b26e ececfe6 ec2b26e 55b1a24 ec2b26e 55b1a24 ec2b26e 55b1a24 ec2b26e 55b1a24 ec2b26e 55b1a24 ec2b26e 55b1a24 8db63ba 55b1a24 ec2b26e 55b1a24 d9c705e ececfe6 ec2b26e ececfe6 415a17d ec2b26e 7ea1165 ec2b26e 415a17d d9c705e ec2b26e 8db63ba ec2b26e d9c705e ec2b26e 415a17d ec2b26e 415a17d ec2b26e 415a17d ec2b26e 415a17d ec2b26e 415a17d ec2b26e 415a17d ec2b26e 415a17d ec2b26e 415a17d ec2b26e 415a17d ec2b26e 415a17d ec2b26e 415a17d d9c705e ec2b26e 13cae40 ec2b26e d9c705e ec2b26e d9c705e ec2b26e 381170a ec2b26e 381170a ec2b26e 381170a ec2b26e d9c705e ec2b26e d9c705e ec2b26e 600cde8 415a17d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
<script lang="ts">
import type { PicletWorkflowState } from '$lib/types';
import type { PicletInstance } from '$lib/db/schema';
import { TYPE_DATA, PicletType } from '$lib/types/picletTypes';
import { generatedDataToPicletInstance } from '$lib/db/piclets';
import PicletCard from '../Piclets/PicletCard.svelte';
import PicletDetail from '../Piclets/PicletDetail.svelte';
interface Props {
workflowState: PicletWorkflowState;
onReset: () => void;
}
let { workflowState, onReset }: Props = $props();
let isSaving = $state(false);
let isSaved = $state(false);
let picletInstance: PicletInstance | null = $state(null);
let showDetailView = $state(false);
let saveError: string | null = $state(null);
// Create piclet instance from the generated data
$effect(() => {
if (workflowState.picletImage && workflowState.picletConcept && workflowState.picletStats) {
try {
const picletData = {
name: workflowState.picletStats.name || 'Unknown Piclet',
imageUrl: workflowState.picletImage.imageUrl,
imageData: workflowState.picletImage.imageData,
imageCaption: workflowState.imageCaption || '',
concept: workflowState.picletConcept,
imagePrompt: workflowState.imagePrompt || '',
stats: workflowState.picletStats,
createdAt: new Date()
};
// Create piclet instance asynchronously
generatedDataToPicletInstance(picletData).then(instance => {
picletInstance = { ...instance, id: 0 }; // Add temporary id for display
}).catch(error => {
console.error('Failed to create piclet instance:', error);
saveError = `Failed to create piclet: ${(error as Error).message || String(error)}`;
});
} catch (error) {
console.error('Failed to create piclet instance:', error);
saveError = `Failed to create piclet: ${(error as Error).message || String(error)}`;
}
}
});
function handleCardClick() {
if (picletInstance) {
showDetailView = true;
}
}
function handleCloseDetail() {
showDetailView = false;
}
</script>
{#if showDetailView && picletInstance}
<PicletDetail
instance={picletInstance}
onClose={handleCloseDetail}
/>
{:else}
<div class="result-container">
<div class="success-header">
<div class="success-icon">✨</div>
<h2>Success!</h2>
<p class="success-message">
{#if picletInstance?.caught}
<strong>{picletInstance?.nickname || 'This creature'}</strong> has been caught and added to your roster!
{:else}
You can now encounter <strong>{picletInstance?.nickname || 'this creature'}</strong>!
{/if}
</p>
</div>
{#if picletInstance}
<div class="piclet-preview">
<PicletCard
piclet={picletInstance}
size={140}
onClick={handleCardClick}
/>
<p class="tap-hint">Tap to view details</p>
</div>
{/if}
<div class="action-buttons">
<button class="action-button primary" onclick={onReset}>
Create Another
</button>
</div>
</div>
{/if}
<style>
.result-container {
max-width: 500px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.success-header {
margin-bottom: 2rem;
}
.success-icon {
font-size: 3rem;
margin-bottom: 1rem;
}
.success-header h2 {
color: #333;
margin: 0 0 1rem;
font-size: 1.8rem;
font-weight: 600;
}
.success-message {
color: #666;
font-size: 1.1rem;
margin: 0;
}
.success-message strong {
color: #333;
font-weight: 600;
}
.piclet-preview {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
margin: 2rem 0;
}
.tap-hint {
color: #888;
font-size: 0.9rem;
margin: 0;
font-style: italic;
}
.action-buttons {
display: flex;
justify-content: center;
margin-top: 2rem;
}
.action-button {
padding: 0.875rem 2rem;
border: none;
border-radius: 12px;
font-weight: 600;
font-size: 1rem;
cursor: pointer;
transition: all 0.2s ease;
min-width: 160px;
}
.action-button.primary {
background: linear-gradient(135deg, #3b82f6, #1d4ed8);
color: white;
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}
.action-button.primary:hover {
background: linear-gradient(135deg, #2563eb, #1e40af);
transform: translateY(-2px);
box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}
.action-button.primary:active {
transform: translateY(0);
}
@media (max-width: 768px) {
.result-container {
padding: 1rem;
}
}
</style> |