auto-image-generation

This commit is contained in:
munimunigamer
2025-12-25 19:59:25 -08:00
parent 04bd314da2
commit 7802479670
8 changed files with 254 additions and 5 deletions
+26 -4
View File
@@ -17,6 +17,7 @@ import {
import { saveChatData } from '../../core/persistence.js';
import { getSafeThumbnailUrl } from '../../utils/avatars.js';
import { saveSettings } from '../../core/persistence.js';
import { checkAndGenerateAvatar, isGenerating } from '../features/avatarGenerator.js';
/**
* Helper to log to both console and debug logs array
@@ -110,12 +111,21 @@ function namesMatch(cardName, aiName) {
function getCharacterAvatar(characterName) {
// First, check if there's a custom NPC avatar
if (extensionSettings.npcAvatars && extensionSettings.npcAvatars[characterName]) {
debugLog(`[RPG Thoughts] Found custom NPC avatar for: ${characterName}`);
return extensionSettings.npcAvatars[characterName];
const avatar = extensionSettings.npcAvatars[characterName];
// Skip if not a valid string (e.g., if it's an object from a previous bug)
if (typeof avatar === 'string' && avatar) {
debugLog(`[RPG Thoughts] Found custom NPC avatar for: ${characterName}`);
return avatar;
} else {
// Clear invalid avatar data
console.warn(`[RPG Thoughts] Invalid avatar data for ${characterName}, clearing...`);
delete extensionSettings.npcAvatars[characterName];
}
}
// Use the existing avatar lookup logic
let characterPortrait = FALLBACK_AVATAR_DATA_URI;
let hasAvatar = false;
// For group chats, search through group members first
if (selected_group) {
@@ -129,6 +139,7 @@ function getCharacterAvatar(characterName) {
if (matchingMember && matchingMember.avatar && matchingMember.avatar !== 'none') {
const thumbnailUrl = getSafeThumbnailUrl('avatar', matchingMember.avatar);
if (thumbnailUrl) {
hasAvatar = true;
return thumbnailUrl;
}
}
@@ -147,6 +158,7 @@ function getCharacterAvatar(characterName) {
if (matchingCharacter && matchingCharacter.avatar && matchingCharacter.avatar !== 'none') {
const thumbnailUrl = getSafeThumbnailUrl('avatar', matchingCharacter.avatar);
if (thumbnailUrl) {
hasAvatar = true;
return thumbnailUrl;
}
}
@@ -157,10 +169,16 @@ function getCharacterAvatar(characterName) {
characters[this_chid].name && namesMatch(characters[this_chid].name, characterName)) {
const thumbnailUrl = getSafeThumbnailUrl('avatar', characters[this_chid].avatar);
if (thumbnailUrl) {
hasAvatar = true;
return thumbnailUrl;
}
}
// Trigger auto-generation if no avatar was found
if (!hasAvatar) {
checkAndGenerateAvatar(characterName, false);
}
return characterPortrait;
}
@@ -500,7 +518,7 @@ export function renderThoughts() {
// Find character portrait using the new helper function
const characterPortrait = getCharacterAvatar(char.name);
debugLog(`[RPG Thoughts] Final avatar for ${char.name}:`, characterPortrait.substring(0, 50) + '...');
debugLog(`[RPG Thoughts] Final avatar for ${char.name}:`, typeof characterPortrait === 'string' ? characterPortrait.substring(0, 50) + '...' : characterPortrait);
// Get relationship badge - only if relationships are enabled in config
let relationshipBadge = '⚖️'; // Default
@@ -519,10 +537,14 @@ export function renderThoughts() {
// Escape character name for use in HTML attributes
const escapedName = escapeHtmlAttr(char.name);
// Check if avatar is being generated
const isCurrentlyGenerating = isGenerating(char.name);
html += `
<div class="rpg-character-card" data-character-name="${escapedName}">
<div class="rpg-character-avatar rpg-avatar-upload" data-character="${escapedName}" title="Click to upload custom avatar&#10;Right-click to remove custom avatar">
<div class="rpg-character-avatar rpg-avatar-upload ${isCurrentlyGenerating ? 'rpg-avatar-generating' : ''}" data-character="${escapedName}" title="Click to upload custom avatar&#10;Right-click to remove custom avatar">
<img src="${characterPortrait}" alt="${escapedName}" onerror="this.style.opacity='0.5';this.onerror=null;" />
${isCurrentlyGenerating ? '<div class="rpg-generating-overlay"><i class="fa-solid fa-spinner fa-spin"></i></div>' : ''}
${hasRelationshipEnabled ? `<div class="rpg-relationship-badge rpg-editable" contenteditable="true" data-character="${escapedName}" data-field="${relationshipFieldName}" title="Click to edit (use emoji: ⚔️ ⚖️ ⭐ ❤️)">${relationshipBadge}</div>` : ''}
</div>
<div class="rpg-character-content">