diff --git a/public/script.js b/public/script.js index 975f12065..753e6b7d3 100644 --- a/public/script.js +++ b/public/script.js @@ -1028,12 +1028,22 @@ export function setAnimationDuration(ms = null) { document.documentElement.style.setProperty('--animation-duration', `${animation_duration}ms`); } +/** + * Sets the currently active character + * @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`. + */ export function setActiveCharacter(entityOrKey) { - active_character = getTagKeyForEntity(entityOrKey); + active_character = entityOrKey ? getTagKeyForEntity(entityOrKey) : null; + if (active_character) active_group = null; } +/** + * Sets the currently active group. + * @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`. + */ export function setActiveGroup(entityOrKey) { - active_group = getTagKeyForEntity(entityOrKey); + active_group = entityOrKey ? getTagKeyForEntity(entityOrKey) : null; + if (active_group) active_character = null; } /** @@ -7597,7 +7607,7 @@ export function select_selected_character(chid) { // Hide the chat scenario button if we're peeking the group member defs $('#set_chat_scenario').toggle(!selected_group); - // Don't update the navbar name if we're peeking the group member defs + // Don't update the navbar name if we're peekinFg the group member defs if (!selected_group) { $('#rm_button_selected_ch').children('h2').text(display_name); } diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 236955596..9d64b9cb2 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -287,10 +287,21 @@ async function RA_autoloadchat() { const selectedCharElement = $(`#rm_print_characters_block .character_select[chid="${active_character_id}"]`); applyTagsOnCharacterSelect.call(selectedCharElement); } + if (!active_character_id) { + setActiveCharacter(null); + saveSettingsDebounced(); + console.warn(`Currently active character with ID ${active_character} not found. Resetting to no active character.`); + } } if (active_group !== null && active_group !== undefined) { - await openGroupById(String(active_group)); + if (active_character) { + console.warn('Active character and active group are both set. Only active character will be loaded. Resetting active group.'); + setActiveGroup(null); + saveSettingsDebounced(); + } else { + const result = await openGroupById(String(active_group)); + } } // if the character list hadn't been loaded yet, try again. diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index 54f19e90e..0d0af4a3f 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -1664,12 +1664,12 @@ function updateFavButtonState(state) { export async function openGroupById(groupId) { if (isChatSaving) { toastr.info(t`Please wait until the chat is saved before switching characters.`, t`Your chat is still saving...`); - return; + return false; } if (!groups.find(x => x.id === groupId)) { console.log('Group not found', groupId); - return; + return false; } if (!is_send_press && !is_group_generating) { @@ -1686,8 +1686,11 @@ export async function openGroupById(groupId) { updateChatMetadata({}, true); chat.length = 0; await getGroupChat(groupId); + return true; } } + + return false; } function openCharacterDefinition(characterSelect) {