mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add contextual Character WI button
This commit is contained in:
@@ -2496,6 +2496,7 @@
|
|||||||
<div id="favorite_button" class="menu_button fa-solid fa-star" title="Add to Favorites"></div>
|
<div id="favorite_button" class="menu_button fa-solid fa-star" title="Add to Favorites"></div>
|
||||||
<input type="hidden" id="fav_checkbox" name="fav" />
|
<input type="hidden" id="fav_checkbox" name="fav" />
|
||||||
<div id="advanced_div" class="menu_button fa-solid fa-book " title="Advanced Definitions"></div>
|
<div id="advanced_div" class="menu_button fa-solid fa-book " title="Advanced Definitions"></div>
|
||||||
|
<div id="world_button" class="menu_button fa-solid fa-globe" title="Character Lore"></div>
|
||||||
<!-- <div id="export_button" class="menu_button fa-solid fa-file-export " title="Export and Download"></div> -->
|
<!-- <div id="export_button" class="menu_button fa-solid fa-file-export " title="Export and Download"></div> -->
|
||||||
<!-- <div id="set_chat_scenario" class="menu_button fa-solid fa-scroll" title="Set a chat scenario override"></div> -->
|
<!-- <div id="set_chat_scenario" class="menu_button fa-solid fa-scroll" title="Set a chat scenario override"></div> -->
|
||||||
<!-- <div id="set_character_world" class="menu_button fa-solid fa-globe" title="Set a character World Info / Lorebook"></div> -->
|
<!-- <div id="set_character_world" class="menu_button fa-solid fa-globe" title="Set a character World Info / Lorebook"></div> -->
|
||||||
|
@@ -30,6 +30,8 @@ import {
|
|||||||
world_names,
|
world_names,
|
||||||
world_info_character_strategy,
|
world_info_character_strategy,
|
||||||
importEmbeddedWorldInfo,
|
importEmbeddedWorldInfo,
|
||||||
|
checkEmbeddedWorld,
|
||||||
|
setWorldInfoButtonClass,
|
||||||
} from "./scripts/world-info.js";
|
} from "./scripts/world-info.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -293,7 +295,7 @@ let currentCroppedAvatar = '';
|
|||||||
|
|
||||||
const durationSaveEdit = 1000;
|
const durationSaveEdit = 1000;
|
||||||
const saveSettingsDebounced = debounce(() => saveSettings(), durationSaveEdit);
|
const saveSettingsDebounced = debounce(() => saveSettings(), durationSaveEdit);
|
||||||
const saveCharacterDebounced = debounce(() => $("#create_button").trigger('click'), durationSaveEdit);
|
export const saveCharacterDebounced = debounce(() => $("#create_button").trigger('click'), durationSaveEdit);
|
||||||
const getStatusDebounced = debounce(() => getStatus(), 300_000);
|
const getStatusDebounced = debounce(() => getStatus(), 300_000);
|
||||||
const saveChatDebounced = debounce(() => saveChatConditional(), durationSaveEdit);
|
const saveChatDebounced = debounce(() => saveChatConditional(), durationSaveEdit);
|
||||||
|
|
||||||
@@ -5052,39 +5054,13 @@ export function select_selected_character(chid) {
|
|||||||
$("#renameCharButton").css("display", "");
|
$("#renameCharButton").css("display", "");
|
||||||
$('.open_alternate_greetings').data('chid', chid);
|
$('.open_alternate_greetings').data('chid', chid);
|
||||||
$('#set_character_world').data('chid', chid);
|
$('#set_character_world').data('chid', chid);
|
||||||
const world = characters[chid]?.data?.extensions?.world;
|
setWorldInfoButtonClass(chid);
|
||||||
const worldSet = Boolean(world && world_names.includes(world));
|
|
||||||
$('#set_character_world').toggleClass('world_set', worldSet);
|
|
||||||
checkEmbeddedWorld(chid);
|
checkEmbeddedWorld(chid);
|
||||||
|
|
||||||
$("#form_create").attr("actiontype", "editcharacter");
|
$("#form_create").attr("actiontype", "editcharacter");
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkEmbeddedWorld(chid) {
|
|
||||||
$('#import_character_info').hide();
|
|
||||||
|
|
||||||
if (chid === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (characters[chid]?.data?.character_book) {
|
|
||||||
$('#import_character_info').data('chid', chid).show();
|
|
||||||
|
|
||||||
// Only show the alert once per character
|
|
||||||
const checkKey = `AlertWI_${characters[chid].avatar}`;
|
|
||||||
const worldName = characters[chid]?.data?.extensions?.world;
|
|
||||||
if (!localStorage.getItem(checkKey) && (!worldName || !world_names.includes(worldName))) {
|
|
||||||
toastr.info(
|
|
||||||
'To import and use it, select "Import Embedded World Info" in the Options dropdown menu on the character panel.',
|
|
||||||
`${characters[chid].name} has an embedded World/Lorebook`,
|
|
||||||
{ timeOut: 10000, extendedTimeOut: 20000, positionClass: 'toast-top-center' },
|
|
||||||
);
|
|
||||||
localStorage.setItem(checkKey, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function select_rm_create() {
|
function select_rm_create() {
|
||||||
menu_type = "create";
|
menu_type = "create";
|
||||||
|
|
||||||
@@ -5133,7 +5109,7 @@ function select_rm_create() {
|
|||||||
$("#name_div").addClass('displayBlock');
|
$("#name_div").addClass('displayBlock');
|
||||||
$('.open_alternate_greetings').data('chid', undefined);
|
$('.open_alternate_greetings').data('chid', undefined);
|
||||||
$('#set_character_world').data('chid', undefined);
|
$('#set_character_world').data('chid', undefined);
|
||||||
$('#set_character_world').toggleClass('world_set', !!create_save.world);
|
setWorldInfoButtonClass(undefined, !!create_save.world);
|
||||||
updateFavButtonState(false);
|
updateFavButtonState(false);
|
||||||
checkEmbeddedWorld();
|
checkEmbeddedWorld();
|
||||||
|
|
||||||
@@ -5530,7 +5506,7 @@ function openCharacterWorldPopup() {
|
|||||||
createOrEditCharacter();
|
createOrEditCharacter();
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#set_character_world').toggleClass('world_set', !!value);
|
setWorldInfoButtonClass(undefined, !!value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = (menu_type == 'create' ? create_save.name : characters[chid]?.data?.name) || 'Nameless';
|
const name = (menu_type == 'create' ? create_save.name : characters[chid]?.data?.name) || 'Nameless';
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { saveSettings, callPopup, substituteParams, getTokenCount, getRequestHeaders, chat_metadata, this_chid, characters } from "../script.js";
|
import { saveSettings, callPopup, substituteParams, getTokenCount, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type } from "../script.js";
|
||||||
import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, delay } from "./utils.js";
|
import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, delay } from "./utils.js";
|
||||||
import { getContext } from "./extensions.js";
|
import { getContext } from "./extensions.js";
|
||||||
import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from "./extensions/floating-prompt/index.js";
|
import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from "./extensions/floating-prompt/index.js";
|
||||||
@@ -630,6 +630,14 @@ async function deleteWorldInfo(worldInfoName) {
|
|||||||
|
|
||||||
await updateWorldInfoList();
|
await updateWorldInfoList();
|
||||||
$('#world_editor_select').trigger('change');
|
$('#world_editor_select').trigger('change');
|
||||||
|
|
||||||
|
if ($('#character_world').val() === worldInfoName) {
|
||||||
|
$('#character_world').val('').trigger('change');
|
||||||
|
setWorldInfoButtonClass(undefined, false);
|
||||||
|
if (menu_type != 'create') {
|
||||||
|
saveCharacterDebounced();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1004,6 +1012,48 @@ function convertCharacterBook(characterBook) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setWorldInfoButtonClass(chid, forceValue = undefined) {
|
||||||
|
if (forceValue !== undefined) {
|
||||||
|
$('#set_character_world, #world_button').toggleClass('world_set', forceValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const world = characters[chid]?.data?.extensions?.world;
|
||||||
|
const worldSet = Boolean(world && world_names.includes(world));
|
||||||
|
$('#set_character_world, #world_button').toggleClass('world_set', worldSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkEmbeddedWorld(chid) {
|
||||||
|
$('#import_character_info').hide();
|
||||||
|
|
||||||
|
if (chid === undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (characters[chid]?.data?.character_book) {
|
||||||
|
$('#import_character_info').data('chid', chid).show();
|
||||||
|
|
||||||
|
// Only show the alert once per character
|
||||||
|
const checkKey = `AlertWI_${characters[chid].avatar}`;
|
||||||
|
const worldName = characters[chid]?.data?.extensions?.world;
|
||||||
|
if (!localStorage.getItem(checkKey) && (!worldName || !world_names.includes(worldName))) {
|
||||||
|
toastr.info(
|
||||||
|
'To import and use it, select "Import Embedded World Info" in the Options dropdown menu on the character panel.',
|
||||||
|
`${characters[chid].name} has an embedded World/Lorebook`,
|
||||||
|
{ timeOut: 10000, extendedTimeOut: 20000, positionClass: 'toast-top-center' },
|
||||||
|
);
|
||||||
|
localStorage.setItem(checkKey, 1);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
export async function importEmbeddedWorldInfo() {
|
export async function importEmbeddedWorldInfo() {
|
||||||
const chid = $('#import_character_info').data('chid');
|
const chid = $('#import_character_info').data('chid');
|
||||||
|
|
||||||
@@ -1032,6 +1082,8 @@ export async function importEmbeddedWorldInfo() {
|
|||||||
if (newIndex >= 0) {
|
if (newIndex >= 0) {
|
||||||
$("#world_editor_select").val(newIndex).trigger('change');
|
$("#world_editor_select").val(newIndex).trigger('change');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setWorldInfoButtonClass(chid, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onWorldInfoChange(_, text) {
|
function onWorldInfoChange(_, text) {
|
||||||
@@ -1231,5 +1283,27 @@ jQuery(() => {
|
|||||||
$('#world_info_character_strategy').on('change', function () {
|
$('#world_info_character_strategy').on('change', function () {
|
||||||
world_info_character_strategy = $(this).val();
|
world_info_character_strategy = $(this).val();
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
})
|
});
|
||||||
|
|
||||||
|
$('#world_button').on('click', async function () {
|
||||||
|
const chid = $('#set_character_world').data('chid');
|
||||||
|
|
||||||
|
if (chid) {
|
||||||
|
const worldName = characters[chid]?.data?.extensions?.world;
|
||||||
|
const hasEmbed = checkEmbeddedWorld(chid);
|
||||||
|
if (worldName && world_names.includes(worldName)) {
|
||||||
|
if (!$('#WorldInfo').is(':visible')) {
|
||||||
|
$('#WIDrawerIcon').trigger('click');
|
||||||
|
}
|
||||||
|
const index = world_names.indexOf(worldName);
|
||||||
|
$("#world_editor_select").val(index).trigger('change');
|
||||||
|
} else if (hasEmbed) {
|
||||||
|
await importEmbeddedWorldInfo();
|
||||||
|
saveCharacterDebounced();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$('#char-management-dropdown').val($('#set_character_world').val()).trigger('change');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user