parse
Browse files
src/lib/components/PicletGenerator/PicletGenerator.svelte
CHANGED
|
@@ -362,12 +362,13 @@ CRITICAL RULES:
|
|
| 362 |
workflowState.picletConcept = responseText;
|
| 363 |
|
| 364 |
// Extract and store canonical name and variation immediately for use in other steps
|
| 365 |
-
|
| 366 |
-
const
|
|
|
|
| 367 |
|
| 368 |
workflowState.objectName = canonicalMatch ? canonicalMatch[1].trim().toLowerCase() : 'unknown';
|
| 369 |
const variationText = variationMatch ? variationMatch[1].trim() : '';
|
| 370 |
-
workflowState.objectAttributes = variationText && variationText !== 'NONE' ? [variationText.toLowerCase()] : [];
|
| 371 |
|
| 372 |
console.log('Parsed specific object:', workflowState.objectName);
|
| 373 |
console.log('Parsed variation:', workflowState.objectAttributes);
|
|
@@ -417,8 +418,8 @@ CRITICAL RULES:
|
|
| 417 |
throw new Error('Text generation service not available or no concept/caption available for prompt generation');
|
| 418 |
}
|
| 419 |
|
| 420 |
-
// Extract the Monster Image Prompt from the structured concept
|
| 421 |
-
const imagePromptMatch = workflowState.picletConcept.match(
|
| 422 |
|
| 423 |
if (imagePromptMatch && imagePromptMatch[1]) {
|
| 424 |
workflowState.imagePrompt = imagePromptMatch[1].trim();
|
|
@@ -522,8 +523,8 @@ Create a concise visual description (1-3 sentences, max 100 words). Focus only o
|
|
| 522 |
}
|
| 523 |
|
| 524 |
try {
|
| 525 |
-
// Extract monster name
|
| 526 |
-
const monsterNameMatch = workflowState.picletConcept.match(
|
| 527 |
let monsterName = monsterNameMatch ? monsterNameMatch[1].trim() : 'Unknown Monster';
|
| 528 |
|
| 529 |
// Clean and truncate name
|
|
@@ -535,8 +536,8 @@ Create a concise visual description (1-3 sentences, max 100 words). Focus only o
|
|
| 535 |
}
|
| 536 |
monsterName = monsterName.replace(/\*/g, ''); // Remove markdown asterisks
|
| 537 |
|
| 538 |
-
// Extract rarity and convert to tier
|
| 539 |
-
const rarityMatch = workflowState.picletConcept.match(
|
| 540 |
const objectRarity = rarityMatch ? rarityMatch[1].trim().toLowerCase() : 'common';
|
| 541 |
|
| 542 |
let tier: 'low' | 'medium' | 'high' | 'legendary' = 'medium';
|
|
@@ -545,20 +546,20 @@ Create a concise visual description (1-3 sentences, max 100 words). Focus only o
|
|
| 545 |
else if (objectRarity.includes('rare')) tier = 'high';
|
| 546 |
else if (objectRarity.includes('legendary') || objectRarity.includes('mythical')) tier = 'legendary';
|
| 547 |
|
| 548 |
-
// Extract primary type
|
| 549 |
-
const primaryTypeMatch = workflowState.picletConcept.match(
|
| 550 |
let primaryType: any = primaryTypeMatch ? primaryTypeMatch[1].trim().toLowerCase() : 'beast';
|
| 551 |
|
| 552 |
-
// Extract description
|
| 553 |
-
const descriptionMatch = workflowState.picletConcept.match(
|
| 554 |
if (!descriptionMatch) {
|
| 555 |
console.error('Monster description not found in concept:', workflowState.picletConcept);
|
| 556 |
throw new Error('Failed to extract monster description from AI response');
|
| 557 |
}
|
| 558 |
let description = descriptionMatch[1].trim();
|
| 559 |
|
| 560 |
-
// Extract physical stats
|
| 561 |
-
const physicalStatsMatch = workflowState.picletConcept.match(
|
| 562 |
let height: string | undefined;
|
| 563 |
let weight: string | undefined;
|
| 564 |
|
|
@@ -571,8 +572,8 @@ Create a concise visual description (1-3 sentences, max 100 words). Focus only o
|
|
| 571 |
weight = weightMatch ? weightMatch[1].trim() : undefined;
|
| 572 |
}
|
| 573 |
|
| 574 |
-
// Extract personality
|
| 575 |
-
const personalityMatch = workflowState.picletConcept.match(
|
| 576 |
let personality = personalityMatch ? personalityMatch[1].trim() : undefined;
|
| 577 |
|
| 578 |
// Create stats with physical characteristics
|
|
@@ -634,15 +635,11 @@ Create a concise visual description (1-3 sentences, max 100 words). Focus only o
|
|
| 634 |
|
| 635 |
const picletInstance = await generatedDataToPicletInstance(
|
| 636 |
picletData,
|
| 637 |
-
workflowState.objectName,
|
| 638 |
variation,
|
| 639 |
workflowState.objectAttributes
|
| 640 |
);
|
| 641 |
-
|
| 642 |
-
// Override the caught status to auto-capture scanned Piclets
|
| 643 |
-
picletInstance.caught = true;
|
| 644 |
-
picletInstance.caughtAt = new Date();
|
| 645 |
-
|
| 646 |
const picletId = await savePicletInstance(picletInstance);
|
| 647 |
console.log('Piclet auto-saved as caught with ID:', picletId);
|
| 648 |
} catch (err) {
|
|
@@ -668,20 +665,14 @@ Create a concise visual description (1-3 sentences, max 100 words). Focus only o
|
|
| 668 |
imagePrompt: null,
|
| 669 |
picletImage: null,
|
| 670 |
error: null,
|
| 671 |
-
isProcessing: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 672 |
};
|
| 673 |
}
|
| 674 |
-
|
| 675 |
-
// Public method for trainer scanner to queue trainer images
|
| 676 |
-
export function queueTrainerImage(imageFile: File, imagePath: string) {
|
| 677 |
-
imageQueue.push(imageFile);
|
| 678 |
-
trainerImagePaths.push(imagePath);
|
| 679 |
-
|
| 680 |
-
// If this is the first image and we're not processing, start processing
|
| 681 |
-
if (imageQueue.length === 1 && !workflowState.isProcessing) {
|
| 682 |
-
processCurrentImage();
|
| 683 |
-
}
|
| 684 |
-
}
|
| 685 |
</script>
|
| 686 |
|
| 687 |
<div class="piclet-generator">
|
|
|
|
| 362 |
workflowState.picletConcept = responseText;
|
| 363 |
|
| 364 |
// Extract and store canonical name and variation immediately for use in other steps
|
| 365 |
+
// Handle both plain and bold markdown headers
|
| 366 |
+
const canonicalMatch = responseText.match(/\*{0,2}#\s*Canonical Object\s*\*{0,2}\s*\n([\s\S]*?)(?=^\*{0,2}#)/m);
|
| 367 |
+
const variationMatch = responseText.match(/\*{0,2}#\s*Variation\s*\*{0,2}\s*\n([\s\S]*?)(?=^\*{0,2}#)/m);
|
| 368 |
|
| 369 |
workflowState.objectName = canonicalMatch ? canonicalMatch[1].trim().toLowerCase() : 'unknown';
|
| 370 |
const variationText = variationMatch ? variationMatch[1].trim() : '';
|
| 371 |
+
workflowState.objectAttributes = variationText && variationText !== 'NONE' && variationText !== 'canonical' ? [variationText.toLowerCase()] : [];
|
| 372 |
|
| 373 |
console.log('Parsed specific object:', workflowState.objectName);
|
| 374 |
console.log('Parsed variation:', workflowState.objectAttributes);
|
|
|
|
| 418 |
throw new Error('Text generation service not available or no concept/caption available for prompt generation');
|
| 419 |
}
|
| 420 |
|
| 421 |
+
// Extract the Monster Image Prompt from the structured concept (handle both plain and bold markdown headers)
|
| 422 |
+
const imagePromptMatch = workflowState.picletConcept.match(/\*{0,2}#\s*Monster Image Prompt\s*\*{0,2}\s*\n([\s\S]*?)(?=^\*{0,2}#|$)/m);
|
| 423 |
|
| 424 |
if (imagePromptMatch && imagePromptMatch[1]) {
|
| 425 |
workflowState.imagePrompt = imagePromptMatch[1].trim();
|
|
|
|
| 523 |
}
|
| 524 |
|
| 525 |
try {
|
| 526 |
+
// Extract monster name (handle both plain and bold markdown headers)
|
| 527 |
+
const monsterNameMatch = workflowState.picletConcept.match(/\*{0,2}#\s*Monster Name\s*\*{0,2}\s*\n([\s\S]*?)(?=^\*{0,2}#|$)/m);
|
| 528 |
let monsterName = monsterNameMatch ? monsterNameMatch[1].trim() : 'Unknown Monster';
|
| 529 |
|
| 530 |
// Clean and truncate name
|
|
|
|
| 536 |
}
|
| 537 |
monsterName = monsterName.replace(/\*/g, ''); // Remove markdown asterisks
|
| 538 |
|
| 539 |
+
// Extract rarity and convert to tier (handle both plain and bold markdown headers)
|
| 540 |
+
const rarityMatch = workflowState.picletConcept.match(/\*{0,2}#\s*Object Rarity\s*\*{0,2}\s*\n([\s\S]*?)(?=^\*{0,2}#)/m);
|
| 541 |
const objectRarity = rarityMatch ? rarityMatch[1].trim().toLowerCase() : 'common';
|
| 542 |
|
| 543 |
let tier: 'low' | 'medium' | 'high' | 'legendary' = 'medium';
|
|
|
|
| 546 |
else if (objectRarity.includes('rare')) tier = 'high';
|
| 547 |
else if (objectRarity.includes('legendary') || objectRarity.includes('mythical')) tier = 'legendary';
|
| 548 |
|
| 549 |
+
// Extract primary type (handle both plain and bold markdown headers)
|
| 550 |
+
const primaryTypeMatch = workflowState.picletConcept.match(/\*{0,2}#\s*Primary Type\s*\*{0,2}\s*\n([\s\S]*?)(?=^\*{0,2}#|$)/m);
|
| 551 |
let primaryType: any = primaryTypeMatch ? primaryTypeMatch[1].trim().toLowerCase() : 'beast';
|
| 552 |
|
| 553 |
+
// Extract description (handle both plain and bold markdown headers)
|
| 554 |
+
const descriptionMatch = workflowState.picletConcept.match(/\*{0,2}#\s*Monster Description\s*\*{0,2}\s*\n([\s\S]*?)(?=^\*{0,2}#|$)/m);
|
| 555 |
if (!descriptionMatch) {
|
| 556 |
console.error('Monster description not found in concept:', workflowState.picletConcept);
|
| 557 |
throw new Error('Failed to extract monster description from AI response');
|
| 558 |
}
|
| 559 |
let description = descriptionMatch[1].trim();
|
| 560 |
|
| 561 |
+
// Extract physical stats (handle both plain and bold markdown headers)
|
| 562 |
+
const physicalStatsMatch = workflowState.picletConcept.match(/\*{0,2}#\s*Physical Stats\s*\*{0,2}\s*\n([\s\S]*?)(?=^\*{0,2}#|$)/m);
|
| 563 |
let height: string | undefined;
|
| 564 |
let weight: string | undefined;
|
| 565 |
|
|
|
|
| 572 |
weight = weightMatch ? weightMatch[1].trim() : undefined;
|
| 573 |
}
|
| 574 |
|
| 575 |
+
// Extract personality (handle both plain and bold markdown headers)
|
| 576 |
+
const personalityMatch = workflowState.picletConcept.match(/\*{0,2}#\s*Personality\s*\*{0,2}\s*\n([\s\S]*?)(?=^\*{0,2}#|$)/m);
|
| 577 |
let personality = personalityMatch ? personalityMatch[1].trim() : undefined;
|
| 578 |
|
| 579 |
// Create stats with physical characteristics
|
|
|
|
| 635 |
|
| 636 |
const picletInstance = await generatedDataToPicletInstance(
|
| 637 |
picletData,
|
| 638 |
+
workflowState.objectName || undefined,
|
| 639 |
variation,
|
| 640 |
workflowState.objectAttributes
|
| 641 |
);
|
| 642 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 643 |
const picletId = await savePicletInstance(picletInstance);
|
| 644 |
console.log('Piclet auto-saved as caught with ID:', picletId);
|
| 645 |
} catch (err) {
|
|
|
|
| 665 |
imagePrompt: null,
|
| 666 |
picletImage: null,
|
| 667 |
error: null,
|
| 668 |
+
isProcessing: false,
|
| 669 |
+
objectName: null,
|
| 670 |
+
objectAttributes: [],
|
| 671 |
+
visualDetails: null,
|
| 672 |
+
discoveryStatus: null,
|
| 673 |
+
canonicalPiclet: null
|
| 674 |
};
|
| 675 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 676 |
</script>
|
| 677 |
|
| 678 |
<div class="piclet-generator">
|