mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
fixed mistake with function locations, working now.
This commit is contained in:
@@ -1,2 +0,0 @@
|
|||||||
{"user_name":"You","character_name":"Aqua","create_date":1674559896839}
|
|
||||||
{"name":"Aqua","is_user":false,"is_name":true,"send_date":1674563371558,"mes":"*I am in the town square at a city named \"Axel\". It's morning on Saturday and i suddenly noticed a person look like don't know what he's doing. I approached to him and speak* Are you new here? Do you need help? Don't worry, I, aqua the goddess of water, shall help you! Do i look beautiful? *strikes a pose and look at him with puppy eyes*"}
|
|
@@ -1,2 +0,0 @@
|
|||||||
{"user_name":"You","character_name":"Darkness","create_date":1674559899431}
|
|
||||||
{"name":"Darkness","is_user":false,"is_name":true,"send_date":1674564914912,"mes":"*It's a sunny day, in a big park on which there are many people, some walking and others lying in the sun. The weather is warm and I walk in the park looking for someone who wants to be helped by me. Suddenly realise that someone is looking at me.* Hello, I am Darkness, a Crusader, and would you like some help?"}
|
|
@@ -1,2 +0,0 @@
|
|||||||
{"user_name":"You","character_name":"Megumin","create_date":1674559900991}
|
|
||||||
{"name":"Megumin","is_user":false,"is_name":true,"send_date":1674563153854,"mes":"*It was day, the weather was sunny and windless. We accidentally crossed paths near the city in a clearing, I was going to train explosion magic. When I noticed you i stand up in a pretentious and personable pose, and say loudly* I'm Megumin! The Arch Wizard of the Crimson Magic Clan! And i the best at explosion magic!! What are you doing here?"}
|
|
754
public/script.js
754
public/script.js
@@ -1,4 +1,5 @@
|
|||||||
import { humanizedDateTime } from "./scripts/RossAscends-mods.js";
|
import { humanizedDateTime } from "./scripts/RossAscends-mods.js";
|
||||||
|
import { encode, decode } from "../scripts/gpt-2-3-tokenizer/mod.js";
|
||||||
|
|
||||||
//RossAscends: exporting functions and vars for RA mods.
|
//RossAscends: exporting functions and vars for RA mods.
|
||||||
export {
|
export {
|
||||||
@@ -648,7 +649,23 @@ var token;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function setBackground(bg) {
|
async function setBackground(bg) {
|
||||||
|
/*
|
||||||
|
const response = await fetch("/setbackground", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
"bg": bg
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
||||||
|
if (response.ok === true) {
|
||||||
|
//const getData = await response.json();
|
||||||
|
//background = getData;
|
||||||
|
|
||||||
|
//var aa = JSON.parse(getData[0]);
|
||||||
|
//const load_ch_coint = Object.getOwnPropertyNames(getData);
|
||||||
|
}*/
|
||||||
|
//console.log(bg);
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
type: 'POST', //
|
type: 'POST', //
|
||||||
url: '/setbackground', //
|
url: '/setbackground', //
|
||||||
@@ -663,6 +680,9 @@ var token;
|
|||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
//processData: false,
|
//processData: false,
|
||||||
success: function (html) {
|
success: function (html) {
|
||||||
|
//setBackground(html);
|
||||||
|
//$('body').css('background-image', 'linear-gradient(rgba(19,21,44,0.75), rgba(19,21,44,0.75)), url('+e.target.result+')');
|
||||||
|
//$("#form_bg_download").after("<div class=bg_example><img bgfile='"+html+"' class=bg_example_img src='backgrounds/"+html+"'><img bgfile='"+html+"' class=bg_example_cross src=img/cross.png></div>");
|
||||||
},
|
},
|
||||||
error: function (jqXHR, exception) {
|
error: function (jqXHR, exception) {
|
||||||
console.log(exception);
|
console.log(exception);
|
||||||
@@ -683,10 +703,20 @@ var token;
|
|||||||
|
|
||||||
});
|
});
|
||||||
if (response.ok === true) {
|
if (response.ok === true) {
|
||||||
|
//const getData = await response.json();
|
||||||
|
//background = getData;
|
||||||
|
|
||||||
|
//var aa = JSON.parse(getData[0]);
|
||||||
|
//const load_ch_coint = Object.getOwnPropertyNames(getData);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function printMessages() {
|
function printMessages() {
|
||||||
|
//console.log(chat);
|
||||||
|
//console.log('printMessages() -- printing messages for -- '+this_chid+' '+active_character+' '+characters[this_chid]);
|
||||||
chat.forEach(function (item, i, arr) {
|
chat.forEach(function (item, i, arr) {
|
||||||
|
//console.log('printMessage calls addOneMessage');
|
||||||
addOneMessage(item);
|
addOneMessage(item);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -797,31 +827,58 @@ var token;
|
|||||||
if (isSystem) {
|
if (isSystem) {
|
||||||
newMessage.find('.mes_edit').hide();
|
newMessage.find('.mes_edit').hide();
|
||||||
}
|
}
|
||||||
|
//////// swipecode inside addOneMessage - to keep swipes displayed while
|
||||||
if (type === "swipe") {
|
// SWIPE BUTTON DISPLAY SHOULD BE HANDLED IN showSwipeButtons/hideSwipeButtons, not here. Commented out duplicate code.
|
||||||
$("#chat")
|
|
||||||
.children()
|
|
||||||
.filter('[mesid="' + (count_view_mes - 1) + '"]')
|
|
||||||
.children(".mes_block")
|
|
||||||
.children(".mes_text")
|
|
||||||
.html("");
|
|
||||||
$("#chat")
|
|
||||||
.children()
|
|
||||||
.filter('[mesid="' + (count_view_mes - 1) + '"]')
|
|
||||||
.children(".mes_block")
|
|
||||||
.children(".mes_text")
|
|
||||||
.append(messageText);
|
|
||||||
|
|
||||||
count_view_mes++;
|
//console.log('addOneMessage -- type = '+type);
|
||||||
|
if(type === 'swipe'){
|
||||||
|
//console.log('addOneMessage -- detected adding one swipe message')
|
||||||
|
$("#chat").children().filter('[mesid="'+(count_view_mes-1)+'"]').children('.mes_block').children('.mes_text').html('');
|
||||||
|
$("#chat").children().filter('[mesid="'+(count_view_mes-1)+'"]').children('.mes_block').children('.mes_text').append(messageText);
|
||||||
|
|
||||||
|
/* if(mes['swipe_id'] !== 0 && swipes){
|
||||||
|
console.log('addOneMessage -- swipe_id is not 0, adding both buttons');
|
||||||
|
$("#chat").children().filter('[mesid="'+(count_view_mes-1)+'"]').children('.swipe_right').css('display', 'flex');
|
||||||
|
$("#chat").children().filter('[mesid="'+(count_view_mes-1)+'"]').children('.swipe_left').css('display', 'flex');
|
||||||
|
} */
|
||||||
|
}else{ //if this is not a display of a new swipe message..
|
||||||
|
//console.log('addOneMessage -- adding message');
|
||||||
|
$("#chat").children().filter('[mesid="'+count_view_mes+'"]').children('.mes_block').children('.mes_text').append(messageText);
|
||||||
|
//console.log('addOneMessage - hiding swipe buttons');
|
||||||
|
hideSwipeButtons(); //disabling this leaves buttons visibile on all messages, breaks swipes
|
||||||
|
//console.log('addOneMessage -- checking for swipes');
|
||||||
|
/* if(parseInt(chat.length-1) === parseInt(count_view_mes) && !mes['is_user'] && swipes){
|
||||||
|
|
||||||
|
console.log('chat length - 1 = '+(chat[chat.length-1]['mesid']));
|
||||||
|
if(chat[chat.length-1]['mesid'] !==undefined){
|
||||||
|
if(mes['swipe_id'] === undefined && count_view_mes !== 0){
|
||||||
|
console.log('addOneMessage -- no swipes here, showing right button for possible generation');
|
||||||
|
$("#chat").children().filter('[mesid="'+(count_view_mes)+'"]').children('.swipe_right').css('display', 'flex');
|
||||||
|
}else if(mes['swipe_id'] !== undefined){ // if swipes aren't undefined == swipes exist at this node
|
||||||
|
console.log('addOneMessage -- found swipes')
|
||||||
|
if(mes['swipe_id'] === 0){ //if we are viewing the first swipe message, display right
|
||||||
|
console.log('addOneMessage -- found lone swipe, displaying right button');
|
||||||
|
$("#chat").children().filter('[mesid="'+(count_view_mes)+'"]').children('.swipe_right').css('display', 'flex');
|
||||||
|
}else { // if swipe_id is more than 0, than means we must have multiple swipes, so show both items
|
||||||
|
console.log('addOneMessage -- found multiple swipes, showing both buttons');
|
||||||
|
$("#chat").children().filter('[mesid="'+(count_view_mes)+'"]').children('.swipe_right').css('display', 'flex');
|
||||||
|
$("#chat").children().filter('[mesid="'+(count_view_mes)+'"]').children('.swipe_left').css('display', 'flex');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{console.log('apparently no swipes found, and not a valid mesage to add hideSwipeButtons, so skipping');} */
|
||||||
|
count_view_mes++;
|
||||||
}
|
}
|
||||||
|
/* } */
|
||||||
|
// if(type !== 'swipe'){count_view_mes++;}
|
||||||
|
|
||||||
var $textchat = $("#chat");
|
var $textchat = $('#chat');
|
||||||
$("#chat .mes").last().addClass("last_mes");
|
$('#chat .mes').last().addClass('last_mes');
|
||||||
$("#chat .mes").eq(-2).removeClass("last_mes");
|
$('#chat .mes').eq(-2).removeClass('last_mes');
|
||||||
$textchat.scrollTop($textchat[0].scrollHeight);
|
$textchat.scrollTop($textchat[0].scrollHeight);
|
||||||
|
|
||||||
hideSwipeButtons();
|
hideSwipeButtons(); //disabling this prevents left button from correctly removing on last message without swipe to the left...
|
||||||
showSwipeButtons();
|
showSwipeButtons();
|
||||||
|
|
||||||
}
|
}
|
||||||
function substituteParams(content) {
|
function substituteParams(content) {
|
||||||
@@ -3039,358 +3096,359 @@ console.log('getGroupChat calls addOneMessage');
|
|||||||
a.download = fileName;
|
a.download = fileName;
|
||||||
a.click();
|
a.click();
|
||||||
}
|
}
|
||||||
// World Info Editor
|
|
||||||
async function showWorldEditor() {
|
// World Info Editor
|
||||||
if (!world_info) {
|
async function showWorldEditor() {
|
||||||
popup_type = 'default';
|
if (!world_info) {
|
||||||
callPopup('<h3>Select a world info first!</h3>');
|
popup_type = 'default';
|
||||||
return;
|
callPopup('<h3>Select a world info first!</h3>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
is_world_edit_open = true;
|
||||||
|
$('#world_popup_name').val(world_info);
|
||||||
|
$('#world_popup').css('display', 'flex');
|
||||||
|
await loadWorldInfoData();
|
||||||
|
displayWorldEntries(world_info_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
is_world_edit_open = true;
|
async function loadWorldInfoData() {
|
||||||
$('#world_popup_name').val(world_info);
|
if (!world_info) {
|
||||||
$('#world_popup').css('display', 'flex');
|
return;
|
||||||
await loadWorldInfoData();
|
}
|
||||||
displayWorldEntries(world_info_data);
|
|
||||||
}
|
const response = await fetch("/getworldinfo", {
|
||||||
|
|
||||||
async function loadWorldInfoData() {
|
|
||||||
if (!world_info) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch("/getworldinfo", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"X-CSRF-Token": token,
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ name: world_info })
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
world_info_data = await response.json();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function hideWorldEditor() {
|
|
||||||
is_world_edit_open = false;
|
|
||||||
$('#world_popup').css('display', 'none');
|
|
||||||
}
|
|
||||||
|
|
||||||
function displayWorldEntries(data) {
|
|
||||||
$('#world_popup_entries_list').empty();
|
|
||||||
|
|
||||||
if (!data || !('entries' in data)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const entryUid in data.entries) {
|
|
||||||
const entry = data.entries[entryUid];
|
|
||||||
appendWorldEntry(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function appendWorldEntry(entry) {
|
|
||||||
const template = $('#entry_edit_template .world_entry').clone();
|
|
||||||
template.data('uid', entry.uid);
|
|
||||||
|
|
||||||
// key
|
|
||||||
const keyInput = template.find('textarea[name="key"]');
|
|
||||||
keyInput.data('uid', entry.uid);
|
|
||||||
keyInput.on('input', function () {
|
|
||||||
const uid = $(this).data('uid');
|
|
||||||
const value = $(this).val();
|
|
||||||
$(this).css("height", ""); //reset the height
|
|
||||||
$(this).css("height", $(this).prop('scrollHeight') + "px");
|
|
||||||
world_info_data.entries[uid].key = value.split(',').map(x => x.trim()).filter(x => x);
|
|
||||||
saveWorldInfo();
|
|
||||||
});
|
|
||||||
keyInput.val(entry.key.join(',')).trigger('input');
|
|
||||||
keyInput.css("height", ""); //reset the height
|
|
||||||
keyInput.css("height", $(this).prop('scrollHeight') + "px");
|
|
||||||
|
|
||||||
// keysecondary
|
|
||||||
const keySecondaryInput = template.find('textarea[name="keysecondary"]');
|
|
||||||
keySecondaryInput.data('uid', entry.uid);
|
|
||||||
keySecondaryInput.on('input', function () {
|
|
||||||
const uid = $(this).data('uid');
|
|
||||||
const value = $(this).val();
|
|
||||||
$(this).css("height", ""); //reset the height
|
|
||||||
$(this).css("height", $(this).prop('scrollHeight') + "px");
|
|
||||||
world_info_data.entries[uid].keysecondary = value.split(',').map(x => x.trim()).filter(x => x);
|
|
||||||
saveWorldInfo();
|
|
||||||
});
|
|
||||||
keySecondaryInput.val(entry.keysecondary.join(',')).trigger('input');
|
|
||||||
keySecondaryInput.css("height", ""); //reset the height
|
|
||||||
keySecondaryInput.css("height", $(this).prop('scrollHeight') + "px");
|
|
||||||
|
|
||||||
// comment
|
|
||||||
const commentInput = template.find('textarea[name="comment"]');
|
|
||||||
commentInput.data('uid', entry.uid);
|
|
||||||
commentInput.on('input', function () {
|
|
||||||
const uid = $(this).data('uid');
|
|
||||||
const value = $(this).val();
|
|
||||||
$(this).css("height", ""); //reset the height
|
|
||||||
$(this).css("height", $(this).prop('scrollHeight') + "px");
|
|
||||||
world_info_data.entries[uid].comment = value;
|
|
||||||
saveWorldInfo();
|
|
||||||
});
|
|
||||||
commentInput.val(entry.comment).trigger('input');
|
|
||||||
commentInput.css("height", ""); //reset the height
|
|
||||||
commentInput.css("height", $(this).prop('scrollHeight') + "px");
|
|
||||||
|
|
||||||
// content
|
|
||||||
const contentInput = template.find('textarea[name="content"]');
|
|
||||||
contentInput.data('uid', entry.uid);
|
|
||||||
contentInput.on('input', function () {
|
|
||||||
const uid = $(this).data('uid');
|
|
||||||
const value = $(this).val();
|
|
||||||
world_info_data.entries[uid].content = value;
|
|
||||||
$(this).css("height", ""); //reset the height
|
|
||||||
$(this).css("height", $(this).prop('scrollHeight') + "px");
|
|
||||||
saveWorldInfo();
|
|
||||||
|
|
||||||
// count tokens
|
|
||||||
const numberOfTokens = encode(value).length;
|
|
||||||
$(this).closest('.world_entry').find('.world_entry_form_token_counter').html(numberOfTokens);
|
|
||||||
});
|
|
||||||
contentInput.val(entry.content).trigger('input');
|
|
||||||
contentInput.css("height", ""); //reset the height
|
|
||||||
contentInput.css("height", $(this).prop('scrollHeight') + "px");
|
|
||||||
|
|
||||||
// selective
|
|
||||||
const selectiveInput = template.find('input[name="selective"]');
|
|
||||||
selectiveInput.data('uid', entry.uid);
|
|
||||||
selectiveInput.on('input', function () {
|
|
||||||
const uid = $(this).data('uid');
|
|
||||||
const value = $(this).prop('checked');
|
|
||||||
world_info_data.entries[uid].selective = value;
|
|
||||||
saveWorldInfo();
|
|
||||||
|
|
||||||
const keysecondary = $(this).closest('.world_entry').find('.keysecondary');
|
|
||||||
value ? keysecondary.show() : keysecondary.hide();
|
|
||||||
});
|
|
||||||
selectiveInput.prop('checked', entry.selective).trigger('input');
|
|
||||||
selectiveInput.siblings('.checkbox_fancy').click(function () {
|
|
||||||
$(this).siblings('input').click();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// constant
|
|
||||||
const constantInput = template.find('input[name="constant"]');
|
|
||||||
constantInput.data('uid', entry.uid);
|
|
||||||
constantInput.on('input', function () {
|
|
||||||
const uid = $(this).data('uid');
|
|
||||||
const value = $(this).prop('checked');
|
|
||||||
world_info_data.entries[uid].constant = value;
|
|
||||||
saveWorldInfo();
|
|
||||||
});
|
|
||||||
constantInput.prop('checked', entry.constant).trigger('input');
|
|
||||||
constantInput.siblings('.checkbox_fancy').click(function () {
|
|
||||||
$(this).siblings('input').click();
|
|
||||||
});
|
|
||||||
|
|
||||||
// order
|
|
||||||
const orderInput = template.find('input[name="order"]');
|
|
||||||
orderInput.data('uid', entry.uid);
|
|
||||||
orderInput.on('input', function () {
|
|
||||||
const uid = $(this).data('uid');
|
|
||||||
const value = Number($(this).val());
|
|
||||||
|
|
||||||
world_info_data.entries[uid].order = !isNaN(value) ? value : 0;
|
|
||||||
saveWorldInfo();
|
|
||||||
});
|
|
||||||
orderInput.val(entry.order).trigger('input');
|
|
||||||
|
|
||||||
// position
|
|
||||||
if (entry.position === undefined) {
|
|
||||||
entry.position = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const positionInput = template.find('input[name="position"]');
|
|
||||||
positionInput.data('uid', entry.uid);
|
|
||||||
positionInput.on('input', function () {
|
|
||||||
const uid = $(this).data('uid');
|
|
||||||
const value = Number($(this).val());
|
|
||||||
world_info_data.entries[uid].position = !isNaN(value) ? value : 0;
|
|
||||||
saveWorldInfo();
|
|
||||||
})
|
|
||||||
template.find(`input[name="position"][value=${entry.position}]`).prop('checked', true).trigger('input');
|
|
||||||
|
|
||||||
// display uid
|
|
||||||
template.find('.world_entry_form_uid_value').html(entry.uid);
|
|
||||||
|
|
||||||
// delete button
|
|
||||||
const deleteButton = template.find('input.delete_entry_button');
|
|
||||||
deleteButton.data('uid', entry.uid);
|
|
||||||
deleteButton.on('click', function () {
|
|
||||||
const uid = $(this).data('uid');
|
|
||||||
deleteWorldInfoEntry(uid);
|
|
||||||
$(this).closest('.world_entry').remove();
|
|
||||||
saveWorldInfo();
|
|
||||||
});
|
|
||||||
|
|
||||||
template.appendTo('#world_popup_entries_list');
|
|
||||||
return template;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteWorldInfoEntry(uid) {
|
|
||||||
if (!world_info_data || !('entries' in world_info_data)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete world_info_data.entries[uid];
|
|
||||||
}
|
|
||||||
|
|
||||||
function createWorldInfoEntry() {
|
|
||||||
const newEntryTemplate = {
|
|
||||||
key: [],
|
|
||||||
keysecondary: [],
|
|
||||||
comment: '',
|
|
||||||
content: '',
|
|
||||||
constant: false,
|
|
||||||
selective: false,
|
|
||||||
order: 100,
|
|
||||||
position: 0,
|
|
||||||
};
|
|
||||||
const newUid = getFreeWorldEntryUid();
|
|
||||||
|
|
||||||
if (!Number.isInteger(newUid)) {
|
|
||||||
console.error("Couldn't assign UID to a new entry");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const newEntry = { uid: newUid, ...newEntryTemplate };
|
|
||||||
world_info_data.entries[newUid] = newEntry;
|
|
||||||
|
|
||||||
const entryTemplate = appendWorldEntry(newEntry);
|
|
||||||
entryTemplate.get(0).scrollIntoView({ behavior: 'smooth' });
|
|
||||||
}
|
|
||||||
|
|
||||||
async function saveWorldInfo(immediately) {
|
|
||||||
if (!world_info || !world_info_data) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function _save() {
|
|
||||||
const response = await fetch("/editworldinfo", {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-CSRF-Token": token,
|
"X-CSRF-Token": token,
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ name: world_info, data: world_info_data })
|
body: JSON.stringify({ name: world_info })
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
world_info_data = await response.json();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (immediately) {
|
function hideWorldEditor() {
|
||||||
return await _save();
|
is_world_edit_open = false;
|
||||||
|
$('#world_popup').css('display', 'none');
|
||||||
}
|
}
|
||||||
|
|
||||||
clearTimeout(timerWorldSave);
|
function displayWorldEntries(data) {
|
||||||
timerWorldSave = setTimeout(async () => await _save(), durationSaveEdit);
|
$('#world_popup_entries_list').empty();
|
||||||
}
|
|
||||||
|
if (!data || !('entries' in data)) {
|
||||||
async function renameWorldInfo() {
|
return;
|
||||||
const oldName = world_info;
|
}
|
||||||
const newName = $('#world_popup_name').val();
|
|
||||||
|
for (const entryUid in data.entries) {
|
||||||
if (oldName === newName) {
|
const entry = data.entries[entryUid];
|
||||||
return;
|
appendWorldEntry(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
world_info = newName;
|
function appendWorldEntry(entry) {
|
||||||
await saveWorldInfo(true);
|
const template = $('#entry_edit_template .world_entry').clone();
|
||||||
await deleteWorldInfo(oldName, newName);
|
template.data('uid', entry.uid);
|
||||||
}
|
|
||||||
|
// key
|
||||||
async function deleteWorldInfo(worldInfoName, selectWorldName) {
|
const keyInput = template.find('textarea[name="key"]');
|
||||||
if (!world_names.includes(worldInfoName)) {
|
keyInput.data('uid', entry.uid);
|
||||||
return;
|
keyInput.on('input', function () {
|
||||||
|
const uid = $(this).data('uid');
|
||||||
|
const value = $(this).val();
|
||||||
|
$(this).css("height", ""); //reset the height
|
||||||
|
$(this).css("height", $(this).prop('scrollHeight') + "px");
|
||||||
|
world_info_data.entries[uid].key = value.split(',').map(x => x.trim()).filter(x => x);
|
||||||
|
saveWorldInfo();
|
||||||
|
});
|
||||||
|
keyInput.val(entry.key.join(',')).trigger('input');
|
||||||
|
keyInput.css("height", ""); //reset the height
|
||||||
|
keyInput.css("height", $(this).prop('scrollHeight') + "px");
|
||||||
|
|
||||||
|
// keysecondary
|
||||||
|
const keySecondaryInput = template.find('textarea[name="keysecondary"]');
|
||||||
|
keySecondaryInput.data('uid', entry.uid);
|
||||||
|
keySecondaryInput.on('input', function () {
|
||||||
|
const uid = $(this).data('uid');
|
||||||
|
const value = $(this).val();
|
||||||
|
$(this).css("height", ""); //reset the height
|
||||||
|
$(this).css("height", $(this).prop('scrollHeight') + "px");
|
||||||
|
world_info_data.entries[uid].keysecondary = value.split(',').map(x => x.trim()).filter(x => x);
|
||||||
|
saveWorldInfo();
|
||||||
|
});
|
||||||
|
keySecondaryInput.val(entry.keysecondary.join(',')).trigger('input');
|
||||||
|
keySecondaryInput.css("height", ""); //reset the height
|
||||||
|
keySecondaryInput.css("height", $(this).prop('scrollHeight') + "px");
|
||||||
|
|
||||||
|
// comment
|
||||||
|
const commentInput = template.find('textarea[name="comment"]');
|
||||||
|
commentInput.data('uid', entry.uid);
|
||||||
|
commentInput.on('input', function () {
|
||||||
|
const uid = $(this).data('uid');
|
||||||
|
const value = $(this).val();
|
||||||
|
$(this).css("height", ""); //reset the height
|
||||||
|
$(this).css("height", $(this).prop('scrollHeight') + "px");
|
||||||
|
world_info_data.entries[uid].comment = value;
|
||||||
|
saveWorldInfo();
|
||||||
|
});
|
||||||
|
commentInput.val(entry.comment).trigger('input');
|
||||||
|
commentInput.css("height", ""); //reset the height
|
||||||
|
commentInput.css("height", $(this).prop('scrollHeight') + "px");
|
||||||
|
|
||||||
|
// content
|
||||||
|
const contentInput = template.find('textarea[name="content"]');
|
||||||
|
contentInput.data('uid', entry.uid);
|
||||||
|
contentInput.on('input', function () {
|
||||||
|
const uid = $(this).data('uid');
|
||||||
|
const value = $(this).val();
|
||||||
|
world_info_data.entries[uid].content = value;
|
||||||
|
$(this).css("height", ""); //reset the height
|
||||||
|
$(this).css("height", $(this).prop('scrollHeight') + "px");
|
||||||
|
saveWorldInfo();
|
||||||
|
|
||||||
|
// count tokens
|
||||||
|
const numberOfTokens = encode(value).length;
|
||||||
|
$(this).closest('.world_entry').find('.world_entry_form_token_counter').html(numberOfTokens);
|
||||||
|
});
|
||||||
|
contentInput.val(entry.content).trigger('input');
|
||||||
|
contentInput.css("height", ""); //reset the height
|
||||||
|
contentInput.css("height", $(this).prop('scrollHeight') + "px");
|
||||||
|
|
||||||
|
// selective
|
||||||
|
const selectiveInput = template.find('input[name="selective"]');
|
||||||
|
selectiveInput.data('uid', entry.uid);
|
||||||
|
selectiveInput.on('input', function () {
|
||||||
|
const uid = $(this).data('uid');
|
||||||
|
const value = $(this).prop('checked');
|
||||||
|
world_info_data.entries[uid].selective = value;
|
||||||
|
saveWorldInfo();
|
||||||
|
|
||||||
|
const keysecondary = $(this).closest('.world_entry').find('.keysecondary');
|
||||||
|
value ? keysecondary.show() : keysecondary.hide();
|
||||||
|
});
|
||||||
|
selectiveInput.prop('checked', entry.selective).trigger('input');
|
||||||
|
selectiveInput.siblings('.checkbox_fancy').click(function () {
|
||||||
|
$(this).siblings('input').click();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// constant
|
||||||
|
const constantInput = template.find('input[name="constant"]');
|
||||||
|
constantInput.data('uid', entry.uid);
|
||||||
|
constantInput.on('input', function () {
|
||||||
|
const uid = $(this).data('uid');
|
||||||
|
const value = $(this).prop('checked');
|
||||||
|
world_info_data.entries[uid].constant = value;
|
||||||
|
saveWorldInfo();
|
||||||
|
});
|
||||||
|
constantInput.prop('checked', entry.constant).trigger('input');
|
||||||
|
constantInput.siblings('.checkbox_fancy').click(function () {
|
||||||
|
$(this).siblings('input').click();
|
||||||
|
});
|
||||||
|
|
||||||
|
// order
|
||||||
|
const orderInput = template.find('input[name="order"]');
|
||||||
|
orderInput.data('uid', entry.uid);
|
||||||
|
orderInput.on('input', function () {
|
||||||
|
const uid = $(this).data('uid');
|
||||||
|
const value = Number($(this).val());
|
||||||
|
|
||||||
|
world_info_data.entries[uid].order = !isNaN(value) ? value : 0;
|
||||||
|
saveWorldInfo();
|
||||||
|
});
|
||||||
|
orderInput.val(entry.order).trigger('input');
|
||||||
|
|
||||||
|
// position
|
||||||
|
if (entry.position === undefined) {
|
||||||
|
entry.position = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const positionInput = template.find('input[name="position"]');
|
||||||
|
positionInput.data('uid', entry.uid);
|
||||||
|
positionInput.on('input', function () {
|
||||||
|
const uid = $(this).data('uid');
|
||||||
|
const value = Number($(this).val());
|
||||||
|
world_info_data.entries[uid].position = !isNaN(value) ? value : 0;
|
||||||
|
saveWorldInfo();
|
||||||
|
})
|
||||||
|
template.find(`input[name="position"][value=${entry.position}]`).prop('checked', true).trigger('input');
|
||||||
|
|
||||||
|
// display uid
|
||||||
|
template.find('.world_entry_form_uid_value').html(entry.uid);
|
||||||
|
|
||||||
|
// delete button
|
||||||
|
const deleteButton = template.find('input.delete_entry_button');
|
||||||
|
deleteButton.data('uid', entry.uid);
|
||||||
|
deleteButton.on('click', function () {
|
||||||
|
const uid = $(this).data('uid');
|
||||||
|
deleteWorldInfoEntry(uid);
|
||||||
|
$(this).closest('.world_entry').remove();
|
||||||
|
saveWorldInfo();
|
||||||
|
});
|
||||||
|
|
||||||
|
template.appendTo('#world_popup_entries_list');
|
||||||
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch("/deleteworldinfo", {
|
async function deleteWorldInfoEntry(uid) {
|
||||||
method: "POST",
|
if (!world_info_data || !('entries' in world_info_data)) {
|
||||||
headers: {
|
return;
|
||||||
"Content-Type": "application/json",
|
}
|
||||||
"X-CSRF-Token": token,
|
|
||||||
},
|
delete world_info_data.entries[uid];
|
||||||
body: JSON.stringify({ name: worldInfoName })
|
}
|
||||||
});
|
|
||||||
|
function createWorldInfoEntry() {
|
||||||
if (response.ok) {
|
const newEntryTemplate = {
|
||||||
|
key: [],
|
||||||
|
keysecondary: [],
|
||||||
|
comment: '',
|
||||||
|
content: '',
|
||||||
|
constant: false,
|
||||||
|
selective: false,
|
||||||
|
order: 100,
|
||||||
|
position: 0,
|
||||||
|
};
|
||||||
|
const newUid = getFreeWorldEntryUid();
|
||||||
|
|
||||||
|
if (!Number.isInteger(newUid)) {
|
||||||
|
console.error("Couldn't assign UID to a new entry");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newEntry = { uid: newUid, ...newEntryTemplate };
|
||||||
|
world_info_data.entries[newUid] = newEntry;
|
||||||
|
|
||||||
|
const entryTemplate = appendWorldEntry(newEntry);
|
||||||
|
entryTemplate.get(0).scrollIntoView({ behavior: 'smooth' });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveWorldInfo(immediately) {
|
||||||
|
if (!world_info || !world_info_data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function _save() {
|
||||||
|
const response = await fetch("/editworldinfo", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"X-CSRF-Token": token,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ name: world_info, data: world_info_data })
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (immediately) {
|
||||||
|
return await _save();
|
||||||
|
}
|
||||||
|
|
||||||
|
clearTimeout(timerWorldSave);
|
||||||
|
timerWorldSave = setTimeout(async () => await _save(), durationSaveEdit);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function renameWorldInfo() {
|
||||||
|
const oldName = world_info;
|
||||||
|
const newName = $('#world_popup_name').val();
|
||||||
|
|
||||||
|
if (oldName === newName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
world_info = newName;
|
||||||
|
await saveWorldInfo(true);
|
||||||
|
await deleteWorldInfo(oldName, newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteWorldInfo(worldInfoName, selectWorldName) {
|
||||||
|
if (!world_names.includes(worldInfoName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch("/deleteworldinfo", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"X-CSRF-Token": token,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ name: worldInfoName })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
await updateWorldInfoList();
|
||||||
|
|
||||||
|
const selectedIndex = world_names.indexOf(selectWorldName);
|
||||||
|
if (selectedIndex !== -1) {
|
||||||
|
$('#world_info').val(selectedIndex).change();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$('#world_info').val('None').change();
|
||||||
|
}
|
||||||
|
|
||||||
|
hideWorldEditor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFreeWorldEntryUid() {
|
||||||
|
if (!world_info_data || !('entries' in world_info_data)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAX_UID = 1_000_000; // <- should be safe enough :)
|
||||||
|
for (let uid = 0; uid < MAX_UID; uid++) {
|
||||||
|
if (uid in world_info_data.entries) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFreeWorldName() {
|
||||||
|
const MAX_FREE_NAME = 100_000;
|
||||||
|
for (let index = 1; index < MAX_FREE_NAME; index++) {
|
||||||
|
const newName = `New World (${index})`;
|
||||||
|
if (world_names.includes(newName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return newName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createNewWorldInfo() {
|
||||||
|
const worldInfoTemplate = { entries: {} };
|
||||||
|
const worldInfoName = getFreeWorldName();
|
||||||
|
|
||||||
|
if (!worldInfoName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
world_info = worldInfoName;
|
||||||
|
world_info_data = { ...worldInfoTemplate };
|
||||||
|
await saveWorldInfo(true);
|
||||||
await updateWorldInfoList();
|
await updateWorldInfoList();
|
||||||
|
|
||||||
const selectedIndex = world_names.indexOf(selectWorldName);
|
const selectedIndex = world_names.indexOf(worldInfoName);
|
||||||
if (selectedIndex !== -1) {
|
if (selectedIndex !== -1) {
|
||||||
$('#world_info').val(selectedIndex).change();
|
$('#world_info').val(selectedIndex).change();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$('#world_info').val('None').change();
|
$('#world_info').val('None').change();
|
||||||
}
|
}
|
||||||
|
|
||||||
hideWorldEditor();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function getFreeWorldEntryUid() {
|
|
||||||
if (!world_info_data || !('entries' in world_info_data)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const MAX_UID = 1_000_000; // <- should be safe enough :)
|
|
||||||
for (let uid = 0; uid < MAX_UID; uid++) {
|
|
||||||
if (uid in world_info_data.entries) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return uid;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFreeWorldName() {
|
|
||||||
const MAX_FREE_NAME = 100_000;
|
|
||||||
for (let index = 1; index < MAX_FREE_NAME; index++) {
|
|
||||||
const newName = `New World (${index})`;
|
|
||||||
if (world_names.includes(newName)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return newName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createNewWorldInfo() {
|
|
||||||
const worldInfoTemplate = { entries: {} };
|
|
||||||
const worldInfoName = getFreeWorldName();
|
|
||||||
|
|
||||||
if (!worldInfoName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
world_info = worldInfoName;
|
|
||||||
world_info_data = { ...worldInfoTemplate };
|
|
||||||
await saveWorldInfo(true);
|
|
||||||
await updateWorldInfoList();
|
|
||||||
|
|
||||||
const selectedIndex = world_names.indexOf(worldInfoName);
|
|
||||||
if (selectedIndex !== -1) {
|
|
||||||
$('#world_info').val(selectedIndex).change();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$('#world_info').val('None').change();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////
|
||||||
///////// INTERACTIVE FUNCTIONS AND LISTENERS ///////////
|
///////// INTERACTIVE FUNCTIONS AND LISTENERS ///////////
|
||||||
/////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
import { encode, decode } from "../scripts/gpt-2-3-tokenizer/mod.js";
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
$('#swipes-checkbox').change(function() {
|
$('#swipes-checkbox').change(function() {
|
||||||
|
Reference in New Issue
Block a user