Switch to char from persona panel decision tree

76fa90ed9e69dfe1677329c9413a79d34f9ab82b

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +26 -1Showing whitespace changes
public/scripts/personas.js+26 -1
@@ -26,7 +26,7 @@ import { PAGINATION_TEMPLATE, clearInfoBlock, debounce, delay, download, ensureI
2626import { debounce_timeout } from './constants.js';
2727import { FILTER_TYPES, FilterHelper } from './filters.js';
2828import { groups, selected_group } from './group-chats.js';
2929import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js';
3030import { t } from './i18n.js';
3131import { openWorldInfoEditor, world_names } from './world-info.js';
3232import { renderTemplateAsync } from './templates.js';
@@ -1311,6 +1311,31 @@ async function loadPersonaForCurrentChat({ doRender = false } = {}) {
13111311 if (chatPersona) connectType = 'chat';
13121312 }
13131313
1314+ // If the persona panel is open when the chat changes, this is likely because a character was selected from that panel.
1315+ // In that case, we are not automatically switching persona - but need to make changes if there is any chat-bound connection
1316+ if (isPersonaPanelOpen()) {
1317+ if (chatPersona) {
1318+ // If the chat-bound persona is the currently selected one, we can simply exit out
1319+ if (chatPersona === user_avatar) {
1320+ return;
1321+ }
1322+ // Otherwise ask if we want to switch
1323+ const autoLock = power_user.persona_auto_lock;
1324+ const result = await Popup.show.confirm(t`Switch Persona?`,
1325+ t`You have a connected persona for the current chat (${power_user.personas[chatPersona]}). Do you want to stick to the current persona (${power_user.personas[user_avatar]}) ${(autoLock ? t`and lock that to the chat` : '')}, or switch to ${power_user.personas[chatPersona]} instead?`,
1326+ { okButton: autoLock ? t`Keep and Lock` : t`Keep`, cancelButton: t`Switch` });
1327+ if (result === POPUP_RESULT.AFFIRMATIVE) {
1328+ if (autoLock) {
1329+ lockPersona('chat');
1330+ }
1331+ return;
1332+ }
1333+ } else {
1334+ // If we don't have a chat-bound persona, we simply return and keep the current one we have
1335+ return;
1336+ }
1337+ }
1338+
13141339 // Check if we have any persona connected to the current character
13151340 if (!chatPersona) {
13161341 const connectedPersonas = getConnectedPersonas();