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

9f21f7771c288c6a22fa217c240748bfe565cb26

Wolfsblvt <wolfsblvt@gmail.com>

3 files changed, +30 -6Showing whitespace changes
public/script.js+13 -3
@@ -1028,12 +1028,22 @@ export function setAnimationDuration(ms = null) {
10281028 document.documentElement.style.setProperty('--animation-duration', `${animation_duration}ms`);
10291029}
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+ */
10311035export function setActiveCharacter(entityOrKey) {
10321036 active_character = entityOrKey ? getTagKeyForEntity(entityOrKey) : null;
1037+ if (active_character) active_group = null;
10331038}
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+ */
10351044export function setActiveGroup(entityOrKey) {
10361045 active_group = entityOrKey ? getTagKeyForEntity(entityOrKey) : null;
1046+ if (active_group) active_character = null;
10371047}
10381048
10391049/**
@@ -7597,7 +7607,7 @@ export function select_selected_character(chid) {
75977607 // Hide the chat scenario button if we're peeking the group member defs
75987608 $('#set_chat_scenario').toggle(!selected_group);
75997609
76007610 // Don't update the navbar name if we're peekingpeekinFg the group member defs
76017611 if (!selected_group) {
76027612 $('#rm_button_selected_ch').children('h2').text(display_name);
76037613 }
public/scripts/RossAscends-mods.js+12 -1
@@ -287,10 +287,21 @@ async function RA_autoloadchat() {
287287 const selectedCharElement = $(`#rm_print_characters_block .character_select[chid="${active_character_id}"]`);
288288 applyTagsOnCharacterSelect.call(selectedCharElement);
289289 }
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+ }
290295 }
291296
292297 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+ }
294305 }
295306
296307 // 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) {
16641664export async function openGroupById(groupId) {
16651665 if (isChatSaving) {
16661666 toastr.info(t`Please wait until the chat is saved before switching characters.`, t`Your chat is still saving...`);
16671667 return false;
16681668 }
16691669
16701670 if (!groups.find(x => x.id === groupId)) {
16711671 console.log('Group not found', groupId);
16721672 return false;
16731673 }
16741674
16751675 if (!is_send_press && !is_group_generating) {
@@ -1686,8 +1686,11 @@ export async function openGroupById(groupId) {
16861686 updateChatMetadata({}, true);
16871687 chat.length = 0;
16881688 await getGroupChat(groupId);
1689+ return true;
16891690 }
16901691 }
1692+
1693+ return false;
16911694}
16921695
16931696function openCharacterDefinition(characterSelect) {