fix db issue
Browse files
src/lib/components/Pages/Encounters.svelte
CHANGED
@@ -346,39 +346,50 @@
|
|
346 |
nextPosition = 5;
|
347 |
}
|
348 |
|
349 |
-
console.log('About to
|
350 |
id: capturedPiclet.id,
|
351 |
nickname: capturedPiclet.nickname,
|
352 |
-
|
353 |
-
|
354 |
});
|
355 |
|
356 |
-
//
|
357 |
-
const
|
|
|
|
|
|
|
358 |
caught: true,
|
359 |
caughtAt: new Date(),
|
360 |
isInRoster: true,
|
361 |
-
rosterPosition: nextPosition
|
362 |
-
|
|
|
|
|
363 |
|
364 |
-
|
365 |
-
|
|
|
366 |
|
367 |
-
// Get the
|
368 |
-
|
369 |
-
|
370 |
-
console.log('Retrieved piclet from database:', updatedPiclet);
|
371 |
|
372 |
-
if (
|
373 |
-
console.log('Setting newlyCaughtPiclet and showing detail page:',
|
374 |
-
newlyCaughtPiclet =
|
375 |
showNewlyCaught = true;
|
376 |
console.log('showNewlyCaught is now:', showNewlyCaught);
|
|
|
377 |
} else {
|
378 |
-
console.error('Could not retrieve
|
379 |
-
//
|
380 |
-
|
381 |
-
|
|
|
|
|
|
|
|
|
|
|
382 |
showNewlyCaught = true;
|
383 |
}
|
384 |
} catch (error) {
|
|
|
346 |
nextPosition = 5;
|
347 |
}
|
348 |
|
349 |
+
console.log('About to create captured Piclet in database:', {
|
350 |
id: capturedPiclet.id,
|
351 |
nickname: capturedPiclet.nickname,
|
352 |
+
typeId: capturedPiclet.typeId,
|
353 |
+
level: capturedPiclet.level
|
354 |
});
|
355 |
|
356 |
+
// Create a new database record for the captured Piclet (enemy has temporary ID -1)
|
357 |
+
const newPicletData = {
|
358 |
+
...capturedPiclet,
|
359 |
+
// Remove the temporary ID so database auto-generates a real one
|
360 |
+
id: undefined as any,
|
361 |
caught: true,
|
362 |
caughtAt: new Date(),
|
363 |
isInRoster: true,
|
364 |
+
rosterPosition: nextPosition,
|
365 |
+
// Ensure level is valid (battle enemies might have invalid levels)
|
366 |
+
level: Math.max(1, Math.min(100, capturedPiclet.level || 5))
|
367 |
+
};
|
368 |
|
369 |
+
// Add the captured piclet to the database
|
370 |
+
const newPicletId = await db.picletInstances.add(newPicletData);
|
371 |
+
console.log('Created new database record with ID:', newPicletId);
|
372 |
|
373 |
+
// Get the newly created piclet instance and show detail page
|
374 |
+
const createdPiclet = await db.picletInstances.get(newPicletId);
|
375 |
+
console.log('Retrieved newly created piclet from database:', createdPiclet);
|
|
|
376 |
|
377 |
+
if (createdPiclet) {
|
378 |
+
console.log('Setting newlyCaughtPiclet and showing detail page:', createdPiclet.nickname);
|
379 |
+
newlyCaughtPiclet = createdPiclet;
|
380 |
showNewlyCaught = true;
|
381 |
console.log('showNewlyCaught is now:', showNewlyCaught);
|
382 |
+
console.log(`Added captured Piclet ${createdPiclet.nickname} to roster position ${nextPosition}`);
|
383 |
} else {
|
384 |
+
console.error('Could not retrieve newly created piclet from database');
|
385 |
+
// Fix the level issue and use fallback data
|
386 |
+
const fallbackPiclet = {
|
387 |
+
...capturedPiclet,
|
388 |
+
level: Math.max(1, Math.min(100, capturedPiclet.level || 5)),
|
389 |
+
id: newPicletId
|
390 |
+
};
|
391 |
+
console.log('Using fallback with fixed level:', fallbackPiclet.level);
|
392 |
+
newlyCaughtPiclet = fallbackPiclet;
|
393 |
showNewlyCaught = true;
|
394 |
}
|
395 |
} catch (error) {
|