Auto-load char/group resets if target is not found

9f21f7771c288c6a22fa217c240748bfe565cb26

Wolfsblvt <wolfsblvt@gmail.com>

3 files changed, +30 -6Ignore whitespace
public/script.js+13 -3
@@ -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}
10301030
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 */
1031export function setActiveCharacter(entityOrKey) {1035export function setActiveCharacter(entityOrKey) {
1032 active_character = getTagKeyForEntity(entityOrKey);1036 active_character = entityOrKey ? getTagKeyForEntity(entityOrKey) : null;
1037 if (active_character) active_group = null;
1033}1038}
10341039
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 */
1035export function setActiveGroup(entityOrKey) {1044export function setActiveGroup(entityOrKey) {
1036 active_group = getTagKeyForEntity(entityOrKey);1045 active_group = entityOrKey ? getTagKeyForEntity(entityOrKey) : null;
1046 if (active_group) active_character = null;
1037}1047}
10381048
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 defs7607 // 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);
75997609
7600 // Don't update the navbar name if we're peeking the group member defs7610 // 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 }
public/scripts/RossAscends-mods.js+12 -1
@@ -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 }
291296
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 }
295306
296 // if the character list hadn't been loaded yet, try again.307 // if the character list hadn't been loaded yet, try again.
public/scripts/group-chats.js+5 -2
@@ -1664,12 +1664,12 @@ function updateFavButtonState(state) {
1664export async function openGroupById(groupId) {1664export 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 }
16691669
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 }
16741674
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}
16921695
1693function openCharacterDefinition(characterSelect) {1696function openCharacterDefinition(characterSelect) {