diff --git a/src/systems/rendering/thoughts.js b/src/systems/rendering/thoughts.js index fa19cea..84c5498 100644 --- a/src/systems/rendering/thoughts.js +++ b/src/systems/rendering/thoughts.js @@ -228,6 +228,62 @@ function uploadNpcAvatar(characterName) { input.click(); } +/** + * Removes a character from the Present Characters panel and saved data + * @param {string} characterName - Name of the character to remove + */ +function removeCharacter(characterName) { + console.log(`[RPG Companion] Removing character: ${characterName}`); + + // Initialize if it doesn't exist + if (!lastGeneratedData.characterThoughts) { + return; + } + + const lines = lastGeneratedData.characterThoughts.split('\n'); + const newLines = []; + let skipUntilNextCharacter = false; + let foundCharacter = false; + + for (let i = 0; i < lines.length; i++) { + const line = lines[i].trim(); + + // Check if this is the start of the character we want to remove + if (line.startsWith('- ')) { + const name = line.substring(2).trim(); + if (name.toLowerCase() === characterName.toLowerCase()) { + foundCharacter = true; + skipUntilNextCharacter = true; + continue; // Skip this line + } else { + // This is a different character, stop skipping + skipUntilNextCharacter = false; + } + } + + // If we're not skipping, add the line + if (!skipUntilNextCharacter) { + newLines.push(lines[i]); + } + } + + if (foundCharacter) { + // Update both lastGeneratedData and committedTrackerData + lastGeneratedData.characterThoughts = newLines.join('\n'); + committedTrackerData.characterThoughts = newLines.join('\n'); + + // Save to chat metadata + saveChatData(); + + console.log(`[RPG Companion] Character removed: ${characterName}`); + + // Re-render the panel + renderThoughts(); + } else { + console.warn(`[RPG Companion] Character not found: ${characterName}`); + } +} + /** * Renders character thoughts (Present Characters) panel. * Displays character cards with avatars, relationship badges, and traits. @@ -474,6 +530,7 @@ export function renderThoughts() {