feat: Add remove button for characters in Present Characters panel
- Add removeCharacter() function to delete characters from panel and saved data - Remove character from both lastGeneratedData and committedTrackerData - Add X button to character card header with hover effects - Button removes character from display and prevents re-inclusion in next generation - Updates are persisted to chat metadata
This commit is contained in:
@@ -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() {
|
||||
<div class="rpg-character-header">
|
||||
<span class="rpg-character-emoji rpg-editable" contenteditable="true" data-character="${escapedName}" data-field="emoji" title="Click to edit emoji">${char.emoji}</span>
|
||||
<span class="rpg-character-name rpg-editable" contenteditable="true" data-character="${escapedName}" data-field="name" title="Click to edit name">${char.name}</span>
|
||||
<button class="rpg-character-remove" data-character="${escapedName}" title="Remove this character from the panel">×</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user