Add persona conversion functionality to context menu

This commit is contained in:
artisticMink 2023-10-26 19:47:50 +02:00
parent 7972307b69
commit 22a2a40072
2 changed files with 24 additions and 12 deletions

View File

@ -9,6 +9,7 @@ import {
getRequestHeaders, handleDeleteCharacter, this_chid getRequestHeaders, handleDeleteCharacter, this_chid
} from "../script.js"; } from "../script.js";
import {favsToHotswap} from "./RossAscends-mods.js"; import {favsToHotswap} from "./RossAscends-mods.js";
import {convertCharacterToPersona} from "./personas.js";
const popupMessage = { const popupMessage = {
deleteChat(characterCount) { deleteChat(characterCount) {
@ -18,6 +19,9 @@ const popupMessage = {
<input type="checkbox" id="del_char_checkbox" /> <input type="checkbox" id="del_char_checkbox" />
<span>Also delete the chat files</span> <span>Also delete the chat files</span>
</label><br></b>`; </label><br></b>`;
},
exportCharacters(characterCount) {
return `<h3>Export ${characterCount} characters?</h3>`;
} }
} }
@ -85,6 +89,8 @@ class CharacterContextMenu {
}); });
} }
static persona = async (characterId) => convertCharacterToPersona(characterId);
static delete = async (characterId, deleteChats = false) => { static delete = async (characterId, deleteChats = false) => {
const character = CharacterContextMenu.getCharacter(characterId); const character = CharacterContextMenu.getCharacter(characterId);
@ -134,7 +140,8 @@ class CharacterContextMenu {
const contextMenuItems = [ const contextMenuItems = [
{id: 'character_context_menu_favorite', callback: characterGroupOverlay.handleContextMenuFavorite}, {id: 'character_context_menu_favorite', callback: characterGroupOverlay.handleContextMenuFavorite},
{id: 'character_context_menu_duplicate', callback: characterGroupOverlay.handleContextMenuDuplicate}, {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)) contextMenuItems.forEach(contextMenuItem => document.getElementById(contextMenuItem.id).addEventListener('click', contextMenuItem.callback))
@ -328,15 +335,18 @@ class CharacterGroupOverlay {
.then(() => getCharacters()) .then(() => getCharacters())
.then(() => this.browseState()) .then(() => this.browseState())
handleContextMenuPersona = () => { Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.persona(characterId)))
.then(() => this.browseState());
}
handleContextMenuDelete = () => { handleContextMenuDelete = () => {
callPopup( callPopup(
popupMessage.deleteChat(this.selectedCharacters.length), popupMessage.deleteChat(this.selectedCharacters.length), null)
null .then(deleteChats =>
).then(deleteChats => Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.delete(characterId, deleteChats)))
Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.delete(characterId, deleteChats))) .then(() => getCharacters())
.then(() => getCharacters()) .then(() => this.browseState())
.then(() => this.browseState()) );
);
} }
addStateChangeCallback = callback => this.stateChangeCallbacks.push(callback); addStateChangeCallback = callback => this.stateChangeCallbacks.push(callback);

View File

@ -42,16 +42,18 @@ async function createDummyPersona() {
await uploadUserAvatar(default_avatar); await uploadUserAvatar(default_avatar);
} }
async function convertCharacterToPersona() { export async function convertCharacterToPersona(characterId = null) {
const avatarUrl = characters[this_chid]?.avatar;
if (null === characterId) characterId = this_chid;
const avatarUrl = characters[characterId]?.avatar;
if (!avatarUrl) { if (!avatarUrl) {
console.log("No avatar found for this character"); console.log("No avatar found for this character");
return; return;
} }
const name = characters[this_chid]?.name; const name = characters[characterId]?.name;
let description = characters[this_chid]?.description; let description = characters[characterId]?.description;
const overwriteName = `${name} (Persona).png`; const overwriteName = `${name} (Persona).png`;
if (overwriteName in power_user.personas) { if (overwriteName in power_user.personas) {