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() {
${char.emoji} ${char.name} +
`; @@ -571,6 +628,13 @@ export function renderThoughts() { } }); + // Add event handler for character removal + $thoughtsContainer.find('.rpg-character-remove').on('click', function(e) { + e.stopPropagation(); // Prevent event bubbling + const characterName = $(this).data('character'); + removeCharacter(characterName); + }); + // Remove updating class after animation if (extensionSettings.enableAnimations) { setTimeout(() => $thoughtsContainer.removeClass('rpg-content-updating'), 600); diff --git a/style.css b/style.css index 13b2bc0..b57b4e5 100644 --- a/style.css +++ b/style.css @@ -1986,6 +1986,7 @@ body:has(.rpg-panel.rpg-position-left) #sheld { align-items: center; gap: clamp(4px, 0.5vw, 6px); flex-wrap: nowrap; /* Prevent wrapping */ + position: relative; } .rpg-character-emoji { @@ -2002,6 +2003,39 @@ body:has(.rpg-panel.rpg-position-left) #sheld { white-space: nowrap; /* Prevent name from wrapping */ overflow: hidden; text-overflow: ellipsis; + flex: 1; +} + +/* Character remove button */ +.rpg-character-remove { + background: transparent; + border: none; + color: var(--rpg-text); + font-size: clamp(14px, 2vw, 18px); + font-weight: bold; + cursor: pointer; + padding: 0; + margin-left: auto; + width: clamp(16px, 2.5vh, 20px); + height: clamp(16px, 2.5vh, 20px); + display: flex; + align-items: center; + justify-content: center; + border-radius: 50%; + opacity: 0.5; + transition: all 0.2s ease; + flex-shrink: 0; +} + +.rpg-character-remove:hover { + opacity: 1; + background: rgba(255, 0, 0, 0.2); + color: #ff4444; + transform: scale(1.1); +} + +.rpg-character-remove:active { + transform: scale(0.95); } /* Character traits/status line and custom fields */