download piclet json
Browse files
src/lib/components/Piclets/PicletDetail.svelte
CHANGED
@@ -68,8 +68,98 @@
|
|
68 |
}
|
69 |
|
70 |
|
71 |
-
function
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
}
|
74 |
</script>
|
75 |
|
@@ -94,16 +184,14 @@
|
|
94 |
</button>
|
95 |
<h1 class="card-title">{updatedInstance.nickname || updatedInstance.typeId}</h1>
|
96 |
<button
|
97 |
-
class="
|
98 |
-
onclick={
|
99 |
-
aria-label="
|
100 |
>
|
101 |
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
102 |
-
<
|
103 |
-
<
|
104 |
-
<
|
105 |
-
<line x1="8.59" y1="13.51" x2="15.42" y2="17.49"></line>
|
106 |
-
<line x1="15.41" y1="6.51" x2="8.59" y2="10.49"></line>
|
107 |
</svg>
|
108 |
</button>
|
109 |
</div>
|
@@ -370,7 +458,7 @@
|
|
370 |
background: rgba(255, 255, 255, 0.3);
|
371 |
}
|
372 |
|
373 |
-
.
|
374 |
background: rgba(255, 255, 255, 0.2);
|
375 |
border: none;
|
376 |
color: white;
|
@@ -383,21 +471,21 @@
|
|
383 |
transition: all 0.2s;
|
384 |
}
|
385 |
|
386 |
-
.
|
387 |
background: rgba(255, 255, 255, 0.3);
|
388 |
transform: scale(1.05);
|
389 |
}
|
390 |
|
391 |
-
.
|
392 |
transform: scale(0.95);
|
393 |
}
|
394 |
|
395 |
-
.
|
396 |
opacity: 0.5;
|
397 |
cursor: not-allowed;
|
398 |
}
|
399 |
|
400 |
-
.
|
401 |
width: 20px;
|
402 |
height: 20px;
|
403 |
}
|
|
|
68 |
}
|
69 |
|
70 |
|
71 |
+
function handleDownloadJSON() {
|
72 |
+
try {
|
73 |
+
// Create comprehensive export data
|
74 |
+
const exportData = {
|
75 |
+
exportVersion: "1.0",
|
76 |
+
exportedAt: new Date().toISOString(),
|
77 |
+
piclet: {
|
78 |
+
name: updatedInstance.nickname || updatedInstance.typeId,
|
79 |
+
typeId: updatedInstance.typeId,
|
80 |
+
imageData: updatedInstance.imageData,
|
81 |
+
stats: {
|
82 |
+
// Core identification
|
83 |
+
id: updatedInstance.id,
|
84 |
+
typeId: updatedInstance.typeId,
|
85 |
+
nickname: updatedInstance.nickname,
|
86 |
+
|
87 |
+
// Type information
|
88 |
+
primaryType: updatedInstance.primaryType,
|
89 |
+
secondaryType: updatedInstance.secondaryType,
|
90 |
+
|
91 |
+
// Current stats
|
92 |
+
currentHp: updatedInstance.currentHp,
|
93 |
+
maxHp: updatedInstance.maxHp,
|
94 |
+
level: updatedInstance.level,
|
95 |
+
xp: updatedInstance.xp,
|
96 |
+
attack: updatedInstance.attack,
|
97 |
+
defense: updatedInstance.defense,
|
98 |
+
fieldAttack: updatedInstance.fieldAttack,
|
99 |
+
fieldDefense: updatedInstance.fieldDefense,
|
100 |
+
speed: updatedInstance.speed,
|
101 |
+
|
102 |
+
// Base stats
|
103 |
+
baseHp: updatedInstance.baseHp,
|
104 |
+
baseAttack: updatedInstance.baseAttack,
|
105 |
+
baseDefense: updatedInstance.baseDefense,
|
106 |
+
baseFieldAttack: updatedInstance.baseFieldAttack,
|
107 |
+
baseFieldDefense: updatedInstance.baseFieldDefense,
|
108 |
+
baseSpeed: updatedInstance.baseSpeed,
|
109 |
+
|
110 |
+
// Additional properties
|
111 |
+
nature: updatedInstance.nature,
|
112 |
+
tier: updatedInstance.tier,
|
113 |
+
bst: updatedInstance.bst,
|
114 |
+
caught: updatedInstance.caught,
|
115 |
+
caughtAt: updatedInstance.caughtAt,
|
116 |
+
isInRoster: updatedInstance.isInRoster,
|
117 |
+
rosterPosition: updatedInstance.rosterPosition
|
118 |
+
},
|
119 |
+
battleData: {
|
120 |
+
moves: updatedInstance.moves,
|
121 |
+
specialAbility: updatedInstance.specialAbility,
|
122 |
+
specialAbilityUnlockLevel: updatedInstance.specialAbilityUnlockLevel,
|
123 |
+
types: [updatedInstance.primaryType, updatedInstance.secondaryType].filter(Boolean)
|
124 |
+
},
|
125 |
+
generationData: {
|
126 |
+
imageUrl: updatedInstance.imageUrl,
|
127 |
+
imageCaption: updatedInstance.imageCaption || null,
|
128 |
+
concept: updatedInstance.concept || null,
|
129 |
+
imagePrompt: updatedInstance.imagePrompt || null
|
130 |
+
},
|
131 |
+
metadata: {
|
132 |
+
level: updatedInstance.level,
|
133 |
+
tier: updatedInstance.tier,
|
134 |
+
createdAt: updatedInstance.caughtAt || new Date().toISOString(),
|
135 |
+
exportSource: "Pictuary Game"
|
136 |
+
}
|
137 |
+
}
|
138 |
+
};
|
139 |
+
|
140 |
+
// Create and download JSON file
|
141 |
+
const jsonString = JSON.stringify(exportData, null, 2);
|
142 |
+
const blob = new Blob([jsonString], { type: 'application/json' });
|
143 |
+
const url = URL.createObjectURL(blob);
|
144 |
+
|
145 |
+
// Create temporary download link
|
146 |
+
const link = document.createElement('a');
|
147 |
+
link.href = url;
|
148 |
+
link.download = `piclet-${(updatedInstance.nickname || updatedInstance.typeId).replace(/[^a-zA-Z0-9-_]/g, '_')}-${Date.now()}.json`;
|
149 |
+
|
150 |
+
// Trigger download
|
151 |
+
document.body.appendChild(link);
|
152 |
+
link.click();
|
153 |
+
document.body.removeChild(link);
|
154 |
+
|
155 |
+
// Clean up the blob URL
|
156 |
+
URL.revokeObjectURL(url);
|
157 |
+
|
158 |
+
console.log('Piclet JSON exported successfully');
|
159 |
+
} catch (error) {
|
160 |
+
console.error('Failed to export Piclet JSON:', error);
|
161 |
+
alert('Failed to export Piclet data. Please try again.');
|
162 |
+
}
|
163 |
}
|
164 |
</script>
|
165 |
|
|
|
184 |
</button>
|
185 |
<h1 class="card-title">{updatedInstance.nickname || updatedInstance.typeId}</h1>
|
186 |
<button
|
187 |
+
class="download-button"
|
188 |
+
onclick={handleDownloadJSON}
|
189 |
+
aria-label="Download JSON"
|
190 |
>
|
191 |
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
192 |
+
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
|
193 |
+
<polyline points="7,10 12,15 17,10"></polyline>
|
194 |
+
<line x1="12" y1="15" x2="12" y2="3"></line>
|
|
|
|
|
195 |
</svg>
|
196 |
</button>
|
197 |
</div>
|
|
|
458 |
background: rgba(255, 255, 255, 0.3);
|
459 |
}
|
460 |
|
461 |
+
.download-button {
|
462 |
background: rgba(255, 255, 255, 0.2);
|
463 |
border: none;
|
464 |
color: white;
|
|
|
471 |
transition: all 0.2s;
|
472 |
}
|
473 |
|
474 |
+
.download-button:hover {
|
475 |
background: rgba(255, 255, 255, 0.3);
|
476 |
transform: scale(1.05);
|
477 |
}
|
478 |
|
479 |
+
.download-button:active {
|
480 |
transform: scale(0.95);
|
481 |
}
|
482 |
|
483 |
+
.download-button:disabled {
|
484 |
opacity: 0.5;
|
485 |
cursor: not-allowed;
|
486 |
}
|
487 |
|
488 |
+
.download-button svg {
|
489 |
width: 20px;
|
490 |
height: 20px;
|
491 |
}
|