mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Refactor: move showCharConnections
This commit is contained in:
@ -236,9 +236,6 @@ import {
|
|||||||
setPersonaDescription,
|
setPersonaDescription,
|
||||||
initUserAvatar,
|
initUserAvatar,
|
||||||
updatePersonaConnectionsAvatarList,
|
updatePersonaConnectionsAvatarList,
|
||||||
getConnectedPersonas,
|
|
||||||
askForPersonaSelection,
|
|
||||||
getCurrentConnectionObj,
|
|
||||||
isPersonaPanelOpen,
|
isPersonaPanelOpen,
|
||||||
} from './scripts/personas.js';
|
} from './scripts/personas.js';
|
||||||
import { getBackgrounds, initBackgrounds, loadBackgroundSettings, background_settings } from './scripts/backgrounds.js';
|
import { getBackgrounds, initBackgrounds, loadBackgroundSettings, background_settings } from './scripts/backgrounds.js';
|
||||||
@ -10130,49 +10127,6 @@ jQuery(async function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#char_connections_button').on('click', async () => {
|
|
||||||
let isRemoving = false;
|
|
||||||
|
|
||||||
const connections = getConnectedPersonas();
|
|
||||||
const message = t`The following personas are connected to the current character.\n\nClick on a persona to select it for the current character.\nShift + Click to unlink the persona from the character.`;
|
|
||||||
const selectedPersona = await askForPersonaSelection(t`Persona Connections`, message, connections, {
|
|
||||||
okButton: t`Ok`,
|
|
||||||
highlightPersonas: true,
|
|
||||||
targetedChar: getCurrentConnectionObj(),
|
|
||||||
shiftClickHandler: (element, ev) => {
|
|
||||||
|
|
||||||
const personaId = $(element).attr('data-pid');
|
|
||||||
|
|
||||||
/** @type {import('./scripts/personas.js').PersonaConnection[]} */
|
|
||||||
const connections = power_user.persona_descriptions[personaId]?.connections;
|
|
||||||
if (connections) {
|
|
||||||
console.log(`Unlocking persona ${personaId} from current character ${name2}`);
|
|
||||||
power_user.persona_descriptions[personaId].connections = connections.filter(c => {
|
|
||||||
if (menu_type == 'group_edit' && c.type == 'group' && c.id == selected_group) return false;
|
|
||||||
else if (c.type == 'character' && c.id == characters[this_chid]?.avatar) return false;
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
saveSettingsDebounced();
|
|
||||||
updatePersonaConnectionsAvatarList();
|
|
||||||
if (power_user.persona_show_notifications) {
|
|
||||||
toastr.info(t`User persona ${power_user.personas[personaId]} is now unlocked from the current character ${name2}.`, t`Persona unlocked`);
|
|
||||||
}
|
|
||||||
|
|
||||||
isRemoving = true;
|
|
||||||
$('#char_connections_button').trigger('click');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// One of the persona was selected. So load it.
|
|
||||||
if (!isRemoving && selectedPersona) {
|
|
||||||
setUserAvatar(selectedPersona, { toastPersonaNameChange: false });
|
|
||||||
if (power_user.persona_show_notifications) {
|
|
||||||
toastr.success(t`Selected persona ${power_user.personas[selectedPersona]} for current chat.`, t`Connected Persona Selected`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#character_cross').click(function () {
|
$('#character_cross').click(function () {
|
||||||
is_advanced_char_open = false;
|
is_advanced_char_open = false;
|
||||||
$('#character_popup').transition({
|
$('#character_popup').transition({
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
getRequestHeaders,
|
getRequestHeaders,
|
||||||
getThumbnailUrl,
|
getThumbnailUrl,
|
||||||
groupToEntity,
|
groupToEntity,
|
||||||
|
menu_type,
|
||||||
name1,
|
name1,
|
||||||
name2,
|
name2,
|
||||||
reloadCurrentChat,
|
reloadCurrentChat,
|
||||||
@ -1363,6 +1364,55 @@ export function getConnectedPersonas(characterKey = undefined) {
|
|||||||
return connectedPersonas;
|
return connectedPersonas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows a popup with all personas connected to the currently selected character or group.
|
||||||
|
* In the popup, the user can select a persona to load for the current character or group, or shift-click to remove the connection.
|
||||||
|
* @return {Promise<void>}
|
||||||
|
*/
|
||||||
|
export async function showCharConnections() {
|
||||||
|
let isRemoving = false;
|
||||||
|
|
||||||
|
const connections = getConnectedPersonas();
|
||||||
|
const message = t`The following personas are connected to the current character.\n\nClick on a persona to select it for the current character.\nShift + Click to unlink the persona from the character.`;
|
||||||
|
const selectedPersona = await askForPersonaSelection(t`Persona Connections`, message, connections, {
|
||||||
|
okButton: t`Ok`,
|
||||||
|
highlightPersonas: true,
|
||||||
|
targetedChar: getCurrentConnectionObj(),
|
||||||
|
shiftClickHandler: (element, ev) => {
|
||||||
|
|
||||||
|
const personaId = $(element).attr('data-pid');
|
||||||
|
|
||||||
|
/** @type {PersonaConnection[]} */
|
||||||
|
const connections = power_user.persona_descriptions[personaId]?.connections;
|
||||||
|
if (connections) {
|
||||||
|
console.log(`Unlocking persona ${personaId} from current character ${name2}`);
|
||||||
|
power_user.persona_descriptions[personaId].connections = connections.filter(c => {
|
||||||
|
if (menu_type == 'group_edit' && c.type == 'group' && c.id == selected_group) return false;
|
||||||
|
else if (c.type == 'character' && c.id == characters[this_chid]?.avatar) return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
saveSettingsDebounced();
|
||||||
|
updatePersonaConnectionsAvatarList();
|
||||||
|
if (power_user.persona_show_notifications) {
|
||||||
|
toastr.info(t`User persona ${power_user.personas[personaId]} is now unlocked from the current character ${name2}.`, t`Persona unlocked`);
|
||||||
|
}
|
||||||
|
|
||||||
|
isRemoving = true;
|
||||||
|
$('#char_connections_button').trigger('click');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// One of the persona was selected. So load it.
|
||||||
|
if (!isRemoving && selectedPersona) {
|
||||||
|
setUserAvatar(selectedPersona, { toastPersonaNameChange: false });
|
||||||
|
if (power_user.persona_show_notifications) {
|
||||||
|
toastr.success(t`Selected persona ${power_user.personas[selectedPersona]} for current chat.`, t`Connected Persona Selected`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the current connection object based on whether the current chat is with a char or a group.
|
* Retrieves the current connection object based on whether the current chat is with a char or a group.
|
||||||
*
|
*
|
||||||
@ -1542,6 +1592,7 @@ function migrateNonPersonaUser() {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function initPersonas() {
|
export function initPersonas() {
|
||||||
migrateNonPersonaUser();
|
migrateNonPersonaUser();
|
||||||
$('#persona_delete_button').on('click', deleteUserAvatar);
|
$('#persona_delete_button').on('click', deleteUserAvatar);
|
||||||
@ -1609,6 +1660,8 @@ export function initPersonas() {
|
|||||||
$('#avatar_upload_file').trigger('click');
|
$('#avatar_upload_file').trigger('click');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#char_connections_button').on('click', showCharConnections);
|
||||||
|
|
||||||
eventSource.on('charManagementDropdown', (target) => {
|
eventSource.on('charManagementDropdown', (target) => {
|
||||||
if (target === 'convert_to_persona') {
|
if (target === 'convert_to_persona') {
|
||||||
convertCharacterToPersona();
|
convertCharacterToPersona();
|
||||||
@ -1617,3 +1670,4 @@ export function initPersonas() {
|
|||||||
eventSource.on(event_types.CHAT_CHANGED, loadPersonaForCurrentChat);
|
eventSource.on(event_types.CHAT_CHANGED, loadPersonaForCurrentChat);
|
||||||
switchPersonaGridView();
|
switchPersonaGridView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user