mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
/world to set/unset active world
This commit is contained in:
@@ -2,6 +2,7 @@ import { saveSettings, callPopup, substituteParams, getTokenCount, getRequestHea
|
|||||||
import { download, debounce, initScrollHeight, resetScrollHeight } from "./utils.js";
|
import { download, debounce, initScrollHeight, resetScrollHeight } from "./utils.js";
|
||||||
import { getContext } from "./extensions.js";
|
import { getContext } from "./extensions.js";
|
||||||
import { metadata_keys, shouldWIAddPrompt } from "./extensions/floating-prompt/index.js";
|
import { metadata_keys, shouldWIAddPrompt } from "./extensions/floating-prompt/index.js";
|
||||||
|
import { registerSlashCommand } from "./slash-commands.js";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
world_info,
|
world_info,
|
||||||
@@ -874,18 +875,38 @@ export async function importEmbeddedWorldInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery(() => {
|
function onWorldInfoChange(_, text) {
|
||||||
$("#world_info").on('change', async function () {
|
let selectedWorld;
|
||||||
const selectedWorld = $("#world_info").find(":selected").val();
|
if (_ !== '__notSlashCommand__') { //if it's a slash command
|
||||||
world_info = null;
|
if (text !== undefined) { //and args are provided
|
||||||
|
let slashInputWorld = text.toLowerCase();
|
||||||
if (selectedWorld !== "") {
|
$("#world_info").find(`option`).filter(function () {
|
||||||
const worldIndex = Number(selectedWorld);
|
return $(this).text().toLowerCase() === slashInputWorld;
|
||||||
world_info = !isNaN(worldIndex) ? world_names[worldIndex] : null;
|
}).prop('selected', true); //matches arg with worldnames and selects; if none found, unsets world
|
||||||
|
let setWorldName = $("#world_info").find(":selected").text(); //only for toastr display
|
||||||
|
toastr.success(`Active world: ${setWorldName}`);
|
||||||
|
selectedWorld = $("#world_info").find(":selected").val();
|
||||||
|
} else { //if no args, unset world
|
||||||
|
toastr.success('Deselected World')
|
||||||
|
$("#world_info").val("");
|
||||||
}
|
}
|
||||||
|
} else { //if it's a pointer selection
|
||||||
|
selectedWorld = $("#world_info").find(":selected").val();
|
||||||
|
}
|
||||||
|
world_info = null;
|
||||||
|
if (selectedWorld !== "") {
|
||||||
|
const worldIndex = Number(selectedWorld);
|
||||||
|
world_info = !isNaN(worldIndex) ? world_names[worldIndex] : null;
|
||||||
|
}
|
||||||
|
saveSettingsDebounced();
|
||||||
|
}
|
||||||
|
|
||||||
saveSettingsDebounced();
|
jQuery(() => {
|
||||||
});
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
registerSlashCommand('world', onWorldInfoChange, [], "– sets active World, or unsets if no args provided", true, true);
|
||||||
|
})
|
||||||
|
$("#world_info").on('change', async function () { onWorldInfoChange('__notSlashCommand__') });
|
||||||
|
|
||||||
//**************************WORLD INFO IMPORT EXPORT*************************//
|
//**************************WORLD INFO IMPORT EXPORT*************************//
|
||||||
$("#world_import_button").on('click', function () {
|
$("#world_import_button").on('click', function () {
|
||||||
|
Reference in New Issue
Block a user