diff --git a/public/scripts/CharacterGroupOverlay.js b/public/scripts/CharacterGroupOverlay.js index 2606e7478..edd7f0ae9 100644 --- a/public/scripts/CharacterGroupOverlay.js +++ b/public/scripts/CharacterGroupOverlay.js @@ -9,6 +9,7 @@ import { getRequestHeaders, handleDeleteCharacter, this_chid } from "../script.js"; import {favsToHotswap} from "./RossAscends-mods.js"; +import {convertCharacterToPersona} from "./personas.js"; const popupMessage = { deleteChat(characterCount) { @@ -18,6 +19,9 @@ const popupMessage = { Also delete the chat files
`; + }, + exportCharacters(characterCount) { + return `

Export ${characterCount} characters?

`; } } @@ -85,6 +89,8 @@ class CharacterContextMenu { }); } + static persona = async (characterId) => convertCharacterToPersona(characterId); + static delete = async (characterId, deleteChats = false) => { const character = CharacterContextMenu.getCharacter(characterId); @@ -134,7 +140,8 @@ class CharacterContextMenu { const contextMenuItems = [ {id: 'character_context_menu_favorite', callback: characterGroupOverlay.handleContextMenuFavorite}, {id: 'character_context_menu_duplicate', callback: characterGroupOverlay.handleContextMenuDuplicate}, - {id: 'character_context_menu_delete', callback: characterGroupOverlay.handleContextMenuDelete} + {id: 'character_context_menu_delete', callback: characterGroupOverlay.handleContextMenuDelete}, + {id: 'character_context_menu_persona', callback: characterGroupOverlay.handleContextMenuPersona} ]; contextMenuItems.forEach(contextMenuItem => document.getElementById(contextMenuItem.id).addEventListener('click', contextMenuItem.callback)) @@ -328,15 +335,18 @@ class CharacterGroupOverlay { .then(() => getCharacters()) .then(() => this.browseState()) + handleContextMenuPersona = () => { Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.persona(characterId))) + .then(() => this.browseState()); + } + handleContextMenuDelete = () => { callPopup( - popupMessage.deleteChat(this.selectedCharacters.length), - null - ).then(deleteChats => - Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.delete(characterId, deleteChats))) - .then(() => getCharacters()) - .then(() => this.browseState()) - ); + popupMessage.deleteChat(this.selectedCharacters.length), null) + .then(deleteChats => + Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.delete(characterId, deleteChats))) + .then(() => getCharacters()) + .then(() => this.browseState()) + ); } addStateChangeCallback = callback => this.stateChangeCallbacks.push(callback); diff --git a/public/scripts/personas.js b/public/scripts/personas.js index c3113b3db..fc91e8008 100644 --- a/public/scripts/personas.js +++ b/public/scripts/personas.js @@ -42,16 +42,18 @@ async function createDummyPersona() { await uploadUserAvatar(default_avatar); } -async function convertCharacterToPersona() { - const avatarUrl = characters[this_chid]?.avatar; +export async function convertCharacterToPersona(characterId = null) { + if (null === characterId) characterId = this_chid; + + const avatarUrl = characters[characterId]?.avatar; if (!avatarUrl) { console.log("No avatar found for this character"); return; } - const name = characters[this_chid]?.name; - let description = characters[this_chid]?.description; + const name = characters[characterId]?.name; + let description = characters[characterId]?.description; const overwriteName = `${name} (Persona).png`; if (overwriteName in power_user.personas) {