Fix world info binding and alt.greetings editor for first char in the list Possibly fixes #3579
| @@ -7791,8 +7791,8 @@ function select_rm_create() { | |||
| 7791 | $('#renameCharButton').css('display', 'none'); | 7791 | $('#renameCharButton').css('display', 'none'); |
| 7792 | $('#name_div').removeClass('displayNone'); | 7792 | $('#name_div').removeClass('displayNone'); |
| 7793 | $('#name_div').addClass('displayBlock'); | 7793 | $('#name_div').addClass('displayBlock'); |
| 7794 | $('.open_alternate_greetings').data('chid', undefined); | 7794 | $('.open_alternate_greetings').data('chid', -1); |
| 7795 | $('#set_character_world').data('chid', undefined); | 7795 | $('#set_character_world').data('chid', -1); |
| 7796 | setWorldInfoButtonClass(undefined, !!create_save.world); | 7796 | setWorldInfoButtonClass(undefined, !!create_save.world); |
| 7797 | updateFavButtonState(false); | 7797 | updateFavButtonState(false); |
| 7798 | checkEmbeddedWorld(); | 7798 | checkEmbeddedWorld(); |
| @@ -8248,7 +8248,7 @@ function updateAlternateGreetingsHintVisibility(root) { | |||
| 8248 | function openCharacterWorldPopup() { | 8248 | function openCharacterWorldPopup() { |
| 8249 | const chid = $('#set_character_world').data('chid'); | 8249 | const chid = $('#set_character_world').data('chid'); |
| 8250 | 8250 | ||
| 8251 | if (menu_type != 'create' && chid == undefined) { | 8251 | if (menu_type != 'create' && chid === undefined) { |
| 8252 | toastr.error('Does not have an Id for this character in world select menu.'); | 8252 | toastr.error('Does not have an Id for this character in world select menu.'); |
| 8253 | return; | 8253 | return; |
| 8254 | } | 8254 | } |
| @@ -8380,7 +8380,7 @@ function openAlternateGreetings() { | |||
| 8380 | return; | 8380 | return; |
| 8381 | } else { | 8381 | } else { |
| 8382 | // If the character does not have alternate greetings, create an empty array | 8382 | // If the character does not have alternate greetings, create an empty array |
| 8383 | if (chid && Array.isArray(characters[chid].data.alternate_greetings) == false) { | 8383 | if (characters[chid] && !Array.isArray(characters[chid].data.alternate_greetings)) { |
| 8384 | characters[chid].data.alternate_greetings = []; | 8384 | characters[chid].data.alternate_greetings = []; |
| 8385 | } | 8385 | } |
| 8386 | } | 8386 | } |
| @@ -8567,7 +8567,7 @@ async function createOrEditCharacter(e) { | |||
| 8567 | 8567 | ||
| 8568 | formData.delete('alternate_greetings'); | 8568 | formData.delete('alternate_greetings'); |
| 8569 | const chid = $('.open_alternate_greetings').data('chid'); | 8569 | const chid = $('.open_alternate_greetings').data('chid'); |
| 8570 | if (chid && Array.isArray(characters[chid]?.data?.alternate_greetings)) { | 8570 | if (characters[chid] && Array.isArray(characters[chid]?.data?.alternate_greetings)) { |
| 8571 | for (const value of characters[chid].data.alternate_greetings) { | 8571 | for (const value of characters[chid].data.alternate_greetings) { |
| 8572 | formData.append('alternate_greetings', value); | 8572 | formData.append('alternate_greetings', value); |
| 8573 | } | 8573 | } |
| @@ -4732,7 +4732,7 @@ export function setWorldInfoButtonClass(chid, forceValue = undefined) { | |||
| 4732 | return; | 4732 | return; |
| 4733 | } | 4733 | } |
| 4734 | 4734 | ||
| 4735 | if (!chid) { | 4735 | if (chid === undefined) { |
| 4736 | return; | 4736 | return; |
| 4737 | } | 4737 | } |
| 4738 | 4738 | ||
| @@ -4749,7 +4749,7 @@ export function checkEmbeddedWorld(chid) { | |||
| 4749 | } | 4749 | } |
| 4750 | 4750 | ||
| 4751 | if (characters[chid]?.data?.character_book) { | 4751 | if (characters[chid]?.data?.character_book) { |
| 4752 | $('#import_character_info').data('data-chid', chid).show(); | 4752 | $('#import_character_info').data('chid', chid).show(); |
| 4753 | 4753 | ||
| 4754 | // Only show the alert once per character | 4754 | // Only show the alert once per character |
| 4755 | const checkKey = `AlertWI_${characters[chid].avatar}`; | 4755 | const checkKey = `AlertWI_${characters[chid].avatar}`; |
| @@ -4783,9 +4783,15 @@ export function checkEmbeddedWorld(chid) { | |||
| 4783 | } | 4783 | } |
| 4784 | 4784 | ||
| 4785 | export async function importEmbeddedWorldInfo(skipPopup = false) { | 4785 | export async function importEmbeddedWorldInfo(skipPopup = false) { |
| 4786 | const chid = $('#import_character_info').data('data-chid'); | 4786 | const chid = $('#import_character_info').data('chid'); |
| 4787 | 4787 | ||
| 4788 | if (chid === undefined) { | 4788 | if (chid === undefined || chid === -1) { |
| 4789 | return; | ||
| 4790 | } | ||
| 4791 | |||
| 4792 | const hasEmbed = checkEmbeddedWorld(chid); | ||
| 4793 | |||
| 4794 | if (!hasEmbed) { | ||
| 4789 | return; | 4795 | return; |
| 4790 | } | 4796 | } |
| 4791 | 4797 | ||
| @@ -5167,20 +5173,24 @@ jQuery(() => { | |||
| 5167 | }); | 5173 | }); |
| 5168 | 5174 | ||
| 5169 | $('#world_button').on('click', async function (event) { | 5175 | $('#world_button').on('click', async function (event) { |
| 5176 | const openSetWorldMenu = () => $('#char-management-dropdown').val($('#set_character_world').val()).trigger('change'); | ||
| 5170 | const chid = $('#set_character_world').data('chid'); | 5177 | const chid = $('#set_character_world').data('chid'); |
| 5171 | 5178 | ||
| 5172 | if (chid) { | 5179 | if (chid === -1) { |
| 5173 | const worldName = characters[chid]?.data?.extensions?.world; | 5180 | openSetWorldMenu(); |
| 5174 | const hasEmbed = checkEmbeddedWorld(chid); | 5181 | return; |
| 5175 | if (worldName && world_names.includes(worldName) && !event.shiftKey) { | 5182 | } |
| 5176 | openWorldInfoEditor(worldName); | 5183 | |
| 5177 | } else if (hasEmbed && !event.shiftKey) { | 5184 | const worldName = characters[chid]?.data?.extensions?.world; |
| 5178 | await importEmbeddedWorldInfo(); | 5185 | const hasEmbed = checkEmbeddedWorld(chid); |
| 5179 | saveCharacterDebounced(); | 5186 | if (worldName && world_names.includes(worldName) && !event.shiftKey) { |
| 5180 | } | 5187 | openWorldInfoEditor(worldName); |
| 5181 | else { | 5188 | } else if (hasEmbed && !event.shiftKey) { |
| 5182 | $('#char-management-dropdown').val($('#set_character_world').val()).trigger('change'); | 5189 | await importEmbeddedWorldInfo(); |
| 5183 | } | 5190 | saveCharacterDebounced(); |
| 5191 | } | ||
| 5192 | else { | ||
| 5193 | openSetWorldMenu(); | ||
| 5184 | } | 5194 | } |
| 5185 | }); | 5195 | }); |
| 5186 | 5196 | ||