Auto-load char/group resets if target is not found
| @@ -1028,12 +1028,22 @@ export function setAnimationDuration(ms = null) { | ||
| 1028 | 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 | 1035 | export function setActiveCharacter(entityOrKey) { |
| 1032 | 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 | 1044 | export function setActiveGroup(entityOrKey) { |
| 1036 | 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 | 7607 | // Hide the chat scenario button if we're peeking the group member defs |
| 7598 | 7608 | $('#set_chat_scenario').toggle(!selected_group); |
| 7599 | 7609 | |
| 7600 | 7610 | // Don't update the navbar name if we're peekingpeekinFg the group member defs |
| 7601 | 7611 | if (!selected_group) { |
| 7602 | 7612 | $('#rm_button_selected_ch').children('h2').text(display_name); |
| 7603 | 7613 | } |
| @@ -287,10 +287,21 @@ async function RA_autoloadchat() { | ||
| 287 | 287 | const selectedCharElement = $(`#rm_print_characters_block .character_select[chid="${active_character_id}"]`); |
| 288 | 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 | 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 | 307 | // if the character list hadn't been loaded yet, try again. |
| @@ -1664,12 +1664,12 @@ function updateFavButtonState(state) { | ||
| 1664 | 1664 | export async function openGroupById(groupId) { |
| 1665 | 1665 | if (isChatSaving) { |
| 1666 | 1666 | toastr.info(t`Please wait until the chat is saved before switching characters.`, t`Your chat is still saving...`); |
| 1667 | 1667 | return false; |
| 1668 | 1668 | } |
| 1669 | 1669 | |
| 1670 | 1670 | if (!groups.find(x => x.id === groupId)) { |
| 1671 | 1671 | console.log('Group not found', groupId); |
| 1672 | 1672 | return false; |
| 1673 | 1673 | } |
| 1674 | 1674 | |
| 1675 | 1675 | if (!is_send_press && !is_group_generating) { |
| @@ -1686,8 +1686,11 @@ export async function openGroupById(groupId) { | ||
| 1686 | 1686 | updateChatMetadata({}, true); |
| 1687 | 1687 | chat.length = 0; |
| 1688 | 1688 | await getGroupChat(groupId); |
| 1689 | + return true; | |
| 1689 | 1690 | } |
| 1690 | 1691 | } |
| 1692 | + | |
| 1693 | + return false; | |
| 1691 | 1694 | } |
| 1692 | 1695 | |
| 1693 | 1696 | function openCharacterDefinition(characterSelect) { |