Fraser commited on
Commit
ab59033
·
1 Parent(s): 99ecf7d

first piclet

Browse files
src/lib/components/PicletGenerator/PicletGenerator.svelte CHANGED
@@ -895,13 +895,6 @@ Write your response within \`\`\`json\`\`\``;
895
  const picletInstance = await generatedDataToPicletInstance(picletData);
896
  const picletId = await savePicletInstance(picletInstance);
897
  console.log('Piclet auto-saved as uncaught with ID:', picletId);
898
-
899
- // Check if this should create a "Your First Piclet" encounter
900
- const shouldCreateFirstEncounter = await EncounterService.shouldCreateFirstPicletEncounter();
901
- if (shouldCreateFirstEncounter === picletId) {
902
- console.log('Creating first Piclet encounter for ID:', picletId);
903
- await EncounterService.createFirstPicletEncounter(picletId);
904
- }
905
  } catch (err) {
906
  console.error('Failed to auto-save piclet:', err);
907
  console.error('Piclet data that failed to save:', {
 
895
  const picletInstance = await generatedDataToPicletInstance(picletData);
896
  const picletId = await savePicletInstance(picletInstance);
897
  console.log('Piclet auto-saved as uncaught with ID:', picletId);
 
 
 
 
 
 
 
898
  } catch (err) {
899
  console.error('Failed to auto-save piclet:', err);
900
  console.error('Piclet data that failed to save:', {
src/lib/db/encounterService.ts CHANGED
@@ -82,21 +82,24 @@ export class EncounterService {
82
  const uncaughtPiclets = await getUncaughtPiclets();
83
 
84
  if (caughtPiclets.length === 0 && uncaughtPiclets.length > 0) {
85
- // Player has no caught piclets but has uncaught ones - return ONLY first piclet encounters
86
- console.log('Player has uncaught piclets but no caught ones - checking for first piclet encounters');
87
 
88
- // Check if there are already first piclet encounters
89
- const existingEncounters = await this.getCurrentEncounters();
90
- const firstPicletEncounters = existingEncounters.filter(e => e.type === EncounterType.FIRST_PICLET);
91
 
92
- if (firstPicletEncounters.length > 0) {
93
- console.log('First piclet encounters already exist:', firstPicletEncounters.length);
94
- return existingEncounters; // Return existing encounters without clearing
95
- } else {
96
- console.log('No first piclet encounters found - this should have been created during generation');
97
- // Don't generate normal encounters - return existing (should be empty)
98
- return existingEncounters;
99
  }
 
 
 
 
100
  }
101
 
102
  if (caughtPiclets.length === 0 && uncaughtPiclets.length === 0) {
 
82
  const uncaughtPiclets = await getUncaughtPiclets();
83
 
84
  if (caughtPiclets.length === 0 && uncaughtPiclets.length > 0) {
85
+ // Player has no caught piclets but has uncaught ones - create/return ONLY first piclet encounters
86
+ console.log('Player has uncaught piclets but no caught ones - creating first piclet encounters');
87
 
88
+ // Clear existing encounters first
89
+ await db.encounters.clear();
 
90
 
91
+ // Create first piclet encounters for all uncaught piclets
92
+ const newEncounters: Encounter[] = [];
93
+ for (const uncaughtPiclet of uncaughtPiclets) {
94
+ if (uncaughtPiclet.id) {
95
+ const encounter = await this.createFirstPicletEncounter(uncaughtPiclet.id);
96
+ newEncounters.push(encounter);
97
+ }
98
  }
99
+
100
+ await markEncountersRefreshed();
101
+ console.log('Created', newEncounters.length, 'first piclet encounters');
102
+ return newEncounters;
103
  }
104
 
105
  if (caughtPiclets.length === 0 && uncaughtPiclets.length === 0) {