Revert "Add create deck functionality to context menu"

This reverts commit 015c83ae
This commit is contained in:
artisticMink 2023-11-02 17:54:17 +01:00
parent f1de1d4b77
commit 545d933e15
3 changed files with 11 additions and 102 deletions

View File

@ -103,7 +103,7 @@
<div id="character_context_menu" class="hidden"> <div id="character_context_menu" class="hidden">
<ul> <ul>
<li><button id="character_context_menu_favorite">Favorite</button></li> <li><button id="character_context_menu_favorite">Favorite</button></li>
<li><button id="character_context_menu_deck">Deck</button></li> <li><button id="character_context_menu_collection">Collection</button></li>
<li><button id="character_context_menu_persona">To Persona</button></li> <li><button id="character_context_menu_persona">To Persona</button></li>
<li><button id="character_context_menu_duplicate">Duplicate</button></li> <li><button id="character_context_menu_duplicate">Duplicate</button></li>
<li><button id="character_context_menu_delete">Delete</button></li> <li><button id="character_context_menu_delete">Delete</button></li>

View File

@ -1049,9 +1049,6 @@ async function printCharacters(fullRefresh = false) {
callback: function (data) { callback: function (data) {
$("#rm_print_characters_block").empty(); $("#rm_print_characters_block").empty();
for (const i of data) { for (const i of data) {
if (i.type === 'deck') {
$("#rm_print_characters_block").append(getCharacterBlock(i.item));
}
if (i.type === 'character') { if (i.type === 'character') {
$("#rm_print_characters_block").append(getCharacterBlock(i.item, i.id)); $("#rm_print_characters_block").append(getCharacterBlock(i.item, i.id));
} }
@ -1077,7 +1074,6 @@ async function printCharacters(fullRefresh = false) {
export function getEntitiesList({ doFilter } = {}) { export function getEntitiesList({ doFilter } = {}) {
let entities = []; let entities = [];
entities.push(...(settings.characterDecks?.decks ?? []).map((item) => ({ item, id: item.id, type: 'deck' })));
entities.push(...characters.map((item, index) => ({ item, id: index, type: 'character' }))); entities.push(...characters.map((item, index) => ({ item, id: index, type: 'character' })));
entities.push(...groups.map((item) => ({ item, id: item.id, type: 'group' }))); entities.push(...groups.map((item) => ({ item, id: item.id, type: 'group' })));
@ -5313,7 +5309,6 @@ async function saveSettings(type) {
horde_settings: horde_settings, horde_settings: horde_settings,
power_user: power_user, power_user: power_user,
extension_settings: extension_settings, extension_settings: extension_settings,
characterDecks: settings.characterDecks,
tags: tags, tags: tags,
tag_map: tag_map, tag_map: tag_map,
nai_settings: nai_settings, nai_settings: nai_settings,

View File

@ -2,18 +2,14 @@
import { import {
callPopup, callPopup,
characters, characters, deleteCharacter,
deleteCharacter,
event_types, event_types,
eventSource, eventSource,
getCharacters, getCharacters,
getRequestHeaders, getRequestHeaders, handleDeleteCharacter, this_chid
saveSettings,
settings
} from "../script.js"; } from "../script.js";
import {favsToHotswap} from "./RossAscends-mods.js"; import {favsToHotswap} from "./RossAscends-mods.js";
import {convertCharacterToPersona} from "./personas.js"; import {convertCharacterToPersona} from "./personas.js";
import {uuidv4} from "./utils.js";
const popupMessage = { const popupMessage = {
deleteChat(characterCount) { deleteChat(characterCount) {
@ -24,10 +20,9 @@ const popupMessage = {
<span>Also delete the chat files</span> <span>Also delete the chat files</span>
</label><br></b>`; </label><br></b>`;
}, },
newDeck() { exportCharacters(characterCount) {
return `<br/><p>Create a new character deck with the selected characters.</p> return `<h3>Export ${characterCount} characters?</h3>`;
<h3>Set a name:</h3><br/>`; }
},
} }
const toggleFavoriteHighlight = (characterId) => { const toggleFavoriteHighlight = (characterId) => {
@ -35,64 +30,6 @@ const toggleFavoriteHighlight = (characterId) => {
element.classList.toggle('is_fav'); element.classList.toggle('is_fav');
} }
/**
* Defines a visual grouping of characters
*/
class CharacterDeck {
id = '';
name = '';
/** @type {int[]} */
characters = [];
constructor(id, name, characters = []) {
this.id = id;
this.name = name;
this.characters = characters;
return this;
}
addCharacter = (characterId) => {
this.characters.push(characterId);
return this;
}
static fromObject(obj) {
return new CharacterDeck(obj.id, obj.name, obj.characters);
}
}
/**
* Represents the characterCollections setting
*/
class CharacterDeckCollection {
/** @type {CharacterDeck[]} */
decks = [];
constructor(decks = []) {
if (false === Array.isArray(decks) || decks.some(deck => !(deck instanceof CharacterDeck))) {
throw new Error('All groups must be instances of CharacterGroup');
}
this.decks = decks;
}
addDeck = (deck) => {
if (!(deck instanceof CharacterDeck)) {
throw new Error('Group must be an instance of CharacterGroup');
}
this.decks.push(deck);
return this;
}
static fromObject(object) {
const decks = object.decks.map(deck => CharacterDeck.fromObject(deck));
return new CharacterDeckCollection(decks);
}
}
/** /**
* Implement a SingletonPattern, allowing access to the group overlay instance * Implement a SingletonPattern, allowing access to the group overlay instance
* from everywhere via (new CharacterGroupOverlay()) * from everywhere via (new CharacterGroupOverlay())
@ -107,7 +44,6 @@ class CharacterGroupOverlayState {
} }
class CharacterContextMenu { class CharacterContextMenu {
/** /**
* Duplicate a character * Duplicate a character
* *
@ -155,20 +91,6 @@ class CharacterContextMenu {
static persona = async (characterId) => convertCharacterToPersona(characterId); static persona = async (characterId) => convertCharacterToPersona(characterId);
static deck = (name = 'New Deck', characterIds = []) => {
let characterDeckCollection = null;
if (settings.characterDecks && Array.isArray(settings.characterDecks.decks)) {
characterDeckCollection = CharacterDeckCollection.fromObject(settings.characterDecks);
} else {
characterDeckCollection = new CharacterDeckCollection();
}
const id = uuidv4();
characterDeckCollection.addDeck(new CharacterDeck(id, name, characterIds));
settings.characterDecks = JSON.parse(JSON.stringify(characterDeckCollection))
}
static delete = async (characterId, deleteChats = false) => { static delete = async (characterId, deleteChats = false) => {
const character = CharacterContextMenu.getCharacter(characterId); const character = CharacterContextMenu.getCharacter(characterId);
@ -198,7 +120,7 @@ class CharacterContextMenu {
} }
}) })
} }
eventSource.emit('characterDeleted', { id: characterId, character: character }); eventSource.emit('characterDeleted', { id: this_chid, character: characters[this_chid] });
}); });
} }
@ -219,8 +141,7 @@ class CharacterContextMenu {
{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}, {id: 'character_context_menu_persona', callback: characterGroupOverlay.handleContextMenuPersona}
{id: 'character_context_menu_deck', callback: characterGroupOverlay.handleContextMenuCreateDeck}
]; ];
contextMenuItems.forEach(contextMenuItem => document.getElementById(contextMenuItem.id).addEventListener('click', contextMenuItem.callback)) contextMenuItems.forEach(contextMenuItem => document.getElementById(contextMenuItem.id).addEventListener('click', contextMenuItem.callback))
@ -297,6 +218,7 @@ class BulkEditOverlay {
const elements = [...document.getElementsByClassName(BulkEditOverlay.characterClass)]; const elements = [...document.getElementsByClassName(BulkEditOverlay.characterClass)];
elements.forEach(element => element.addEventListener('touchstart', this.handleHold)); elements.forEach(element => element.addEventListener('touchstart', this.handleHold));
elements.forEach(element => element.addEventListener('mousedown', this.handleHold)); elements.forEach(element => element.addEventListener('mousedown', this.handleHold));
elements.forEach(element => element.addEventListener('touchend', this.handleLongPressEnd)); elements.forEach(element => element.addEventListener('touchend', this.handleLongPressEnd));
elements.forEach(element => element.addEventListener('mouseup', this.handleLongPressEnd)); elements.forEach(element => element.addEventListener('mouseup', this.handleLongPressEnd));
elements.forEach(element => element.addEventListener('dragend', this.handleLongPressEnd)); elements.forEach(element => element.addEventListener('dragend', this.handleLongPressEnd));
@ -413,8 +335,9 @@ class BulkEditOverlay {
.then(() => getCharacters()) .then(() => getCharacters())
.then(() => this.browseState()) .then(() => this.browseState())
handleContextMenuPersona = () => Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.persona(characterId))) handleContextMenuPersona = () => { Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.persona(characterId)))
.then(() => this.browseState()); .then(() => this.browseState());
}
handleContextMenuDelete = () => { handleContextMenuDelete = () => {
callPopup( callPopup(
@ -426,15 +349,6 @@ class BulkEditOverlay {
); );
} }
handleContextMenuCreateDeck = () => {
callPopup(popupMessage.newDeck, 'input').then(
(resolve) => {
CharacterContextMenu.deck(resolve, this.selectedCharacters);
saveSettings().then(async () => await getCharacters());
}
);
}
addStateChangeCallback = callback => this.stateChangeCallbacks.push(callback); addStateChangeCallback = callback => this.stateChangeCallbacks.push(callback);
selectCharacter = characterId => this.selectedCharacters.push(String(characterId)); selectCharacter = characterId => this.selectedCharacters.push(String(characterId));