Merge branch 'staging' of https://github.com/Cohee1207/SillyTavern into staging

This commit is contained in:
RossAscends
2023-08-03 21:17:36 +09:00
8 changed files with 83 additions and 60 deletions

View File

@@ -45,7 +45,6 @@ let lastCharacter = undefined;
let lastMessage = null;
let spriteCache = {};
let inApiCall = false;
let live2d_var = false;
let previousSrc = null;
@@ -448,8 +447,7 @@ async function loadLiveChar() {
}
}
function handleImageChange(isChecked) {
function handleImageChange() {
const imgElement = document.querySelector('img#expression-image.expression');
if (!imgElement) {
@@ -457,31 +455,32 @@ function handleImageChange(isChecked) {
return;
}
if (isChecked) {
if (extension_settings.expressions.live2d) {
previousSrc = imgElement.src;
// Method get IP of endpoint
if (imgElement.src !== getApiUrl() + '/api/live2d/result_feed') {
const expressionListItemElement = document.querySelector('#live2d');
const expressionImageElement = expressionListItemElement.querySelector('.expression_list_image');
const newSrc = expressionImageElement.src;
const live2dResultFeedSrc = `${getApiUrl()}/api/live2d/result_feed`;
$('#expression-holder').css({ display: '' });
if (imgElement.src !== live2dResultFeedSrc) {
const expressionImageElement = document.querySelector('.expression_list_image');
doExtrasFetch(newSrc, {
method: 'HEAD',
})
.then(response => {
if (response.ok) {
imgElement.src = getApiUrl() + '/api/live2d/result_feed';
}
if (expressionImageElement) {
doExtrasFetch(expressionImageElement.src, {
method: 'HEAD',
})
.catch(error => {
console.error(error); // Log the error if necessary
});
} else if (previousSrc) {
imgElement.src = previousSrc; // Revert the src to its previous value
.then(response => {
if (response.ok) {
imgElement.src = live2dResultFeedSrc;
}
})
.catch(error => {
console.error(error); // Log the error if necessary
});
}
}
} else if (previousSrc !== null) {
imgElement.src = previousSrc; // Revert the src to its previous value
} else {
imgElement.src = ""; //remove incase char doesnt have expressions
setExpression(getContext().name2, FALLBACK_EXPRESSION, true);
}
live2d_var = isChecked;
}
async function moduleWorker() {
@@ -497,22 +496,16 @@ async function moduleWorker() {
if (context.groupId !== lastCharacter && context.characterId !== lastCharacter) {
removeExpression();
spriteCache = {};
previousSrc = null;
//uncheck live image
let checkbox = document.getElementById('image_type_toggle');
if (checkbox.checked) {
checkbox.click();
}
//clear expression
let imgElement = document.getElementById('expression-image');
imgElement.src = "";
//Load new char
if (live2d_var) {
loadLiveChar();
//set checkbox to global var
$('#image_type_toggle').prop('checked', extension_settings.expressions.live2d);
if(extension_settings.expressions.live2d == true){
setLive2dState(extension_settings.expressions.live2d);
}
}
@@ -618,6 +611,14 @@ async function moduleWorker() {
}
}
function setLive2dState(switch_var){
extension_settings.expressions.live2d = switch_var; // Store setting
saveSettingsDebounced();
if (extension_settings.expressions.live2d) { loadLiveChar(); } // load char as needed
handleImageChange(switch_var); // Change image as needed
}
function getSpriteFolderName(message) {
const context = getContext();
let avatarPath = '';
@@ -805,7 +806,7 @@ async function getExpressionsList() {
}
async function setExpression(character, expression, force) {
if (live2d_var == false) {
if (extension_settings.expressions.live2d == false) {
console.debug('entered setExpressions');
await validateImages(character);
@@ -915,7 +916,7 @@ async function setExpression(character, expression, force) {
}
document.getElementById("expression-holder").style.display = '';
if (live2d_var == true) {
} else {
// Find the <img> element with id="expression-image" and class="expression"
const imgElement = document.querySelector('img#expression-image.expression');
//console.log("searching");
@@ -923,7 +924,6 @@ async function setExpression(character, expression, force) {
console.log("setting value");
imgElement.src = getApiUrl() + '/api/live2d/result_feed';
}
}
}
}
@@ -1234,13 +1234,8 @@ function setExpressionOverrideHtml(forceClear = false) {
$(window).on("resize", updateVisualNovelModeDebounced);
$('.expression_settings').hide();
$('#image_type_toggle').on('change', function () {
const isChecked = this.checked;
if (isChecked) {
loadLiveChar();
}
handleImageChange(isChecked);
$('#image_type_toggle').on('click', function () {
setLive2dState(this.checked);
});
}
@@ -1253,7 +1248,6 @@ function setExpressionOverrideHtml(forceClear = false) {
moduleWorker();
dragElement($("#expression-holder"))
eventSource.on(event_types.CHAT_CHANGED, () => {
//console.log("checked: " + live2d_var);
setExpressionOverrideHtml();
if (isVisualNovelMode()) {

View File

@@ -27,7 +27,7 @@ import {
import { registerSlashCommand } from "./slash-commands.js";
import { delay, debounce } from "./utils.js";
import { delay } from "./utils.js";
export {
loadPowerUserSettings,
@@ -184,6 +184,7 @@ let power_user = {
persona_description: '',
persona_description_position: persona_description_positions.BEFORE_CHAR,
persona_show_notifications: true,
custom_stopping_strings: '',
fuzzy_search: false,
@@ -678,6 +679,7 @@ function loadPowerUserSettings(settings, data) {
$('#auto_swipe_blacklist_threshold').val(power_user.auto_swipe_blacklist_threshold);
$('#custom_stopping_strings').val(power_user.custom_stopping_strings);
$('#fuzzy_search_checkbox').prop("checked", power_user.fuzzy_search);
$('#persona_show_notifications').prop("checked", power_user.persona_show_notifications);
$("#console_log_prompts").prop("checked", power_user.console_log_prompts);
$('#auto_fix_generated_markdown').prop("checked", power_user.auto_fix_generated_markdown);
@@ -1998,6 +2000,11 @@ $(document).ready(() => {
saveSettingsDebounced();
});
$('#persona_show_notifications').on('input', function () {
power_user.persona_show_notifications = !!$(this).prop('checked');
saveSettingsDebounced();
});
$(window).on('focus', function () {
browser_has_focus = true;
});