mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Auto-load char/group resets if target is not found
This commit is contained in:
@@ -1028,12 +1028,22 @@ export function setAnimationDuration(ms = null) {
|
|||||||
document.documentElement.style.setProperty('--animation-duration', `${animation_duration}ms`);
|
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) {
|
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) {
|
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
|
// Hide the chat scenario button if we're peeking the group member defs
|
||||||
$('#set_chat_scenario').toggle(!selected_group);
|
$('#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) {
|
if (!selected_group) {
|
||||||
$('#rm_button_selected_ch').children('h2').text(display_name);
|
$('#rm_button_selected_ch').children('h2').text(display_name);
|
||||||
}
|
}
|
||||||
|
@@ -287,10 +287,21 @@ async function RA_autoloadchat() {
|
|||||||
const selectedCharElement = $(`#rm_print_characters_block .character_select[chid="${active_character_id}"]`);
|
const selectedCharElement = $(`#rm_print_characters_block .character_select[chid="${active_character_id}"]`);
|
||||||
applyTagsOnCharacterSelect.call(selectedCharElement);
|
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) {
|
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.
|
// if the character list hadn't been loaded yet, try again.
|
||||||
|
@@ -1664,12 +1664,12 @@ function updateFavButtonState(state) {
|
|||||||
export async function openGroupById(groupId) {
|
export async function openGroupById(groupId) {
|
||||||
if (isChatSaving) {
|
if (isChatSaving) {
|
||||||
toastr.info(t`Please wait until the chat is saved before switching characters.`, t`Your chat is still saving...`);
|
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)) {
|
if (!groups.find(x => x.id === groupId)) {
|
||||||
console.log('Group not found', groupId);
|
console.log('Group not found', groupId);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_send_press && !is_group_generating) {
|
if (!is_send_press && !is_group_generating) {
|
||||||
@@ -1686,8 +1686,11 @@ export async function openGroupById(groupId) {
|
|||||||
updateChatMetadata({}, true);
|
updateChatMetadata({}, true);
|
||||||
chat.length = 0;
|
chat.length = 0;
|
||||||
await getGroupChat(groupId);
|
await getGroupChat(groupId);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function openCharacterDefinition(characterSelect) {
|
function openCharacterDefinition(characterSelect) {
|
||||||
|
Reference in New Issue
Block a user