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