Auto-load char/group resets if target is not found
| @@ -1028,12 +1028,22 @@ export function setAnimationDuration(ms = null) { | |||
| 1028 | document.documentElement.style.setProperty('--animation-duration', `${animation_duration}ms`); | 1028 | document.documentElement.style.setProperty('--animation-duration', `${animation_duration}ms`); |
| 1029 | } | 1029 | } |
| 1030 | 1030 | ||
| 1031 | /** | ||
| 1032 | * Sets the currently active character | ||
| 1033 | * @param {object|number|string} [entityOrKey] - An entity with id property (character, group, tag), or directly an id or tag key. If not provided, the active character is reset to `null`. | ||
| 1034 | */ | ||
| 1031 | export function setActiveCharacter(entityOrKey) { | 1035 | export function setActiveCharacter(entityOrKey) { |
| 1032 | active_character = getTagKeyForEntity(entityOrKey); | 1036 | active_character = entityOrKey ? getTagKeyForEntity(entityOrKey) : null; |
| 1037 | if (active_character) active_group = null; | ||
| 1033 | } | 1038 | } |
| 1034 | 1039 | ||
| 1040 | /** | ||
| 1041 | * Sets the currently active group. | ||
| 1042 | * @param {object|number|string} [entityOrKey] - An entity with id property (character, group, tag), or directly an id or tag key. If not provided, the active group is reset to `null`. | ||
| 1043 | */ | ||
| 1035 | export function setActiveGroup(entityOrKey) { | 1044 | export function setActiveGroup(entityOrKey) { |
| 1036 | active_group = getTagKeyForEntity(entityOrKey); | 1045 | active_group = entityOrKey ? getTagKeyForEntity(entityOrKey) : null; |
| 1046 | if (active_group) active_character = null; | ||
| 1037 | } | 1047 | } |
| 1038 | 1048 | ||
| 1039 | /** | 1049 | /** |
| @@ -7597,7 +7607,7 @@ export function select_selected_character(chid) { | |||
| 7597 | // Hide the chat scenario button if we're peeking the group member defs | 7607 | // Hide the chat scenario button if we're peeking the group member defs |
| 7598 | $('#set_chat_scenario').toggle(!selected_group); | 7608 | $('#set_chat_scenario').toggle(!selected_group); |
| 7599 | 7609 | ||
| 7600 | // Don't update the navbar name if we're peeking the group member defs | 7610 | // Don't update the navbar name if we're peekinFg the group member defs |
| 7601 | if (!selected_group) { | 7611 | if (!selected_group) { |
| 7602 | $('#rm_button_selected_ch').children('h2').text(display_name); | 7612 | $('#rm_button_selected_ch').children('h2').text(display_name); |
| 7603 | } | 7613 | } |
| @@ -287,10 +287,21 @@ async function RA_autoloadchat() { | |||
| 287 | const selectedCharElement = $(`#rm_print_characters_block .character_select[chid="${active_character_id}"]`); | 287 | const selectedCharElement = $(`#rm_print_characters_block .character_select[chid="${active_character_id}"]`); |
| 288 | applyTagsOnCharacterSelect.call(selectedCharElement); | 288 | applyTagsOnCharacterSelect.call(selectedCharElement); |
| 289 | } | 289 | } |
| 290 | if (!active_character_id) { | ||
| 291 | setActiveCharacter(null); | ||
| 292 | saveSettingsDebounced(); | ||
| 293 | console.warn(`Currently active character with ID ${active_character} not found. Resetting to no active character.`); | ||
| 294 | } | ||
| 290 | } | 295 | } |
| 291 | 296 | ||
| 292 | if (active_group !== null && active_group !== undefined) { | 297 | if (active_group !== null && active_group !== undefined) { |
| 293 | await openGroupById(String(active_group)); | 298 | if (active_character) { |
| 299 | console.warn('Active character and active group are both set. Only active character will be loaded. Resetting active group.'); | ||
| 300 | setActiveGroup(null); | ||
| 301 | saveSettingsDebounced(); | ||
| 302 | } else { | ||
| 303 | const result = await openGroupById(String(active_group)); | ||
| 304 | } | ||
| 294 | } | 305 | } |
| 295 | 306 | ||
| 296 | // if the character list hadn't been loaded yet, try again. | 307 | // if the character list hadn't been loaded yet, try again. |
| @@ -1664,12 +1664,12 @@ function updateFavButtonState(state) { | |||
| 1664 | export async function openGroupById(groupId) { | 1664 | export async function openGroupById(groupId) { |
| 1665 | if (isChatSaving) { | 1665 | if (isChatSaving) { |
| 1666 | toastr.info(t`Please wait until the chat is saved before switching characters.`, t`Your chat is still saving...`); | 1666 | toastr.info(t`Please wait until the chat is saved before switching characters.`, t`Your chat is still saving...`); |
| 1667 | return; | 1667 | return false; |
| 1668 | } | 1668 | } |
| 1669 | 1669 | ||
| 1670 | if (!groups.find(x => x.id === groupId)) { | 1670 | if (!groups.find(x => x.id === groupId)) { |
| 1671 | console.log('Group not found', groupId); | 1671 | console.log('Group not found', groupId); |
| 1672 | return; | 1672 | return false; |
| 1673 | } | 1673 | } |
| 1674 | 1674 | ||
| 1675 | if (!is_send_press && !is_group_generating) { | 1675 | if (!is_send_press && !is_group_generating) { |
| @@ -1686,8 +1686,11 @@ export async function openGroupById(groupId) { | |||
| 1686 | updateChatMetadata({}, true); | 1686 | updateChatMetadata({}, true); |
| 1687 | chat.length = 0; | 1687 | chat.length = 0; |
| 1688 | await getGroupChat(groupId); | 1688 | await getGroupChat(groupId); |
| 1689 | return true; | ||
| 1689 | } | 1690 | } |
| 1690 | } | 1691 | } |
| 1692 | |||
| 1693 | return false; | ||
| 1691 | } | 1694 | } |
| 1692 | 1695 | ||
| 1693 | function openCharacterDefinition(characterSelect) { | 1696 | function openCharacterDefinition(characterSelect) { |