From 2df140a6a9ef0cab65db3c7f8a2390a0b56345e0 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 28 Feb 2025 10:16:42 +0200 Subject: [PATCH] Fix world info binding and alt.greetings editor for first char in the list Possibly fixes #3579 --- public/script.js | 10 ++++----- public/scripts/world-info.js | 42 ++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/public/script.js b/public/script.js index 1029b53b6..16ee49336 100644 --- a/public/script.js +++ b/public/script.js @@ -7791,8 +7791,8 @@ function select_rm_create() { $('#renameCharButton').css('display', 'none'); $('#name_div').removeClass('displayNone'); $('#name_div').addClass('displayBlock'); - $('.open_alternate_greetings').data('chid', undefined); - $('#set_character_world').data('chid', undefined); + $('.open_alternate_greetings').data('chid', -1); + $('#set_character_world').data('chid', -1); setWorldInfoButtonClass(undefined, !!create_save.world); updateFavButtonState(false); checkEmbeddedWorld(); @@ -8248,7 +8248,7 @@ function updateAlternateGreetingsHintVisibility(root) { function openCharacterWorldPopup() { const chid = $('#set_character_world').data('chid'); - if (menu_type != 'create' && chid == undefined) { + if (menu_type != 'create' && chid === undefined) { toastr.error('Does not have an Id for this character in world select menu.'); return; } @@ -8380,7 +8380,7 @@ function openAlternateGreetings() { return; } else { // If the character does not have alternate greetings, create an empty array - if (chid && Array.isArray(characters[chid].data.alternate_greetings) == false) { + if (characters[chid] && !Array.isArray(characters[chid].data.alternate_greetings)) { characters[chid].data.alternate_greetings = []; } } @@ -8567,7 +8567,7 @@ async function createOrEditCharacter(e) { formData.delete('alternate_greetings'); const chid = $('.open_alternate_greetings').data('chid'); - if (chid && Array.isArray(characters[chid]?.data?.alternate_greetings)) { + if (characters[chid] && Array.isArray(characters[chid]?.data?.alternate_greetings)) { for (const value of characters[chid].data.alternate_greetings) { formData.append('alternate_greetings', value); } diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index a188b9ac4..ed558ff1d 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -4732,7 +4732,7 @@ export function setWorldInfoButtonClass(chid, forceValue = undefined) { return; } - if (!chid) { + if (chid === undefined) { return; } @@ -4749,7 +4749,7 @@ export function checkEmbeddedWorld(chid) { } if (characters[chid]?.data?.character_book) { - $('#import_character_info').data('data-chid', chid).show(); + $('#import_character_info').data('chid', chid).show(); // Only show the alert once per character const checkKey = `AlertWI_${characters[chid].avatar}`; @@ -4783,9 +4783,15 @@ export function checkEmbeddedWorld(chid) { } export async function importEmbeddedWorldInfo(skipPopup = false) { - const chid = $('#import_character_info').data('data-chid'); + const chid = $('#import_character_info').data('chid'); - if (chid === undefined) { + if (chid === undefined || chid === -1) { + return; + } + + const hasEmbed = checkEmbeddedWorld(chid); + + if (!hasEmbed) { return; } @@ -5167,20 +5173,24 @@ jQuery(() => { }); $('#world_button').on('click', async function (event) { + const openSetWorldMenu = () => $('#char-management-dropdown').val($('#set_character_world').val()).trigger('change'); const chid = $('#set_character_world').data('chid'); - if (chid) { - const worldName = characters[chid]?.data?.extensions?.world; - const hasEmbed = checkEmbeddedWorld(chid); - if (worldName && world_names.includes(worldName) && !event.shiftKey) { - openWorldInfoEditor(worldName); - } else if (hasEmbed && !event.shiftKey) { - await importEmbeddedWorldInfo(); - saveCharacterDebounced(); - } - else { - $('#char-management-dropdown').val($('#set_character_world').val()).trigger('change'); - } + if (chid === -1) { + openSetWorldMenu(); + return; + } + + const worldName = characters[chid]?.data?.extensions?.world; + const hasEmbed = checkEmbeddedWorld(chid); + if (worldName && world_names.includes(worldName) && !event.shiftKey) { + openWorldInfoEditor(worldName); + } else if (hasEmbed && !event.shiftKey) { + await importEmbeddedWorldInfo(); + saveCharacterDebounced(); + } + else { + openSetWorldMenu(); } });