mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Bug and performance Fix's
This commit is contained in:
@ -397,23 +397,17 @@ async function unloadLiveChar() {
|
|||||||
try {
|
try {
|
||||||
const url = new URL(getApiUrl());
|
const url = new URL(getApiUrl());
|
||||||
url.pathname = '/api/live2d/unload';
|
url.pathname = '/api/live2d/unload';
|
||||||
|
|
||||||
const loadResponse = await doExtrasFetch(url);
|
const loadResponse = await doExtrasFetch(url);
|
||||||
|
|
||||||
if (!loadResponse.ok) {
|
if (!loadResponse.ok) {
|
||||||
throw new Error(loadResponse.statusText);
|
throw new Error(loadResponse.statusText);
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadResponseText = await loadResponse.text();
|
const loadResponseText = await loadResponse.text();
|
||||||
console.log(`Response: ${loadResponseText}`);
|
//console.log(`Response: ${loadResponseText}`);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error unloading - ${error}`);
|
//console.error(`Error unloading - ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function loadLiveChar() {
|
async function loadLiveChar() {
|
||||||
if (!modules.includes('live2d')) {
|
if (!modules.includes('live2d')) {
|
||||||
console.debug('live2d module is disabled');
|
console.debug('live2d module is disabled');
|
||||||
@ -628,17 +622,66 @@ async function moduleWorker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function live2dcheck() {
|
||||||
|
const context = getContext();
|
||||||
|
let spriteFolderName = context.name2;
|
||||||
|
const message = getLastCharacterMessage();
|
||||||
|
const avatarFileName = getSpriteFolderName(message);
|
||||||
|
const expressionOverride = extension_settings.expressionOverrides.find((e) =>
|
||||||
|
e.name == avatarFileName
|
||||||
|
);
|
||||||
|
|
||||||
|
if (expressionOverride && expressionOverride.path) {
|
||||||
|
spriteFolderName = expressionOverride.path;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await validateImages(spriteFolderName);
|
||||||
|
|
||||||
|
let live2dObj = spriteCache[spriteFolderName].find(obj => obj.label === 'live2d');
|
||||||
|
let live2dPath_f = live2dObj ? live2dObj.path : null;
|
||||||
|
|
||||||
|
if(live2dPath_f != null){
|
||||||
|
//console.log("live2dPath_f " + live2dPath_f);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
//console.log("live2dPath_f is null");
|
||||||
|
unloadLiveChar();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setLive2dState(switch_var){
|
function setLive2dState(switch_var){
|
||||||
extension_settings.expressions.live2d = switch_var; // Store setting
|
extension_settings.expressions.live2d = switch_var; // Store setting
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
|
|
||||||
if (extension_settings.expressions.live2d) {
|
live2dcheck().then(result => {
|
||||||
loadLiveChar();
|
//console.log(result);
|
||||||
} else {
|
});
|
||||||
unloadLiveChar();
|
|
||||||
}
|
live2dcheck().then(result => {
|
||||||
|
if (result) {
|
||||||
|
//console.log("Live2d exists!");
|
||||||
|
|
||||||
|
if (extension_settings.expressions.live2d) {
|
||||||
|
loadLiveChar();
|
||||||
|
} else {
|
||||||
|
unloadLiveChar();
|
||||||
|
}
|
||||||
|
handleImageChange(switch_var); // Change image as needed
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//console.log("Live2d does not exist.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
handleImageChange(switch_var); // Change image as needed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSpriteFolderName(message) {
|
function getSpriteFolderName(message) {
|
||||||
@ -939,13 +982,25 @@ async function setExpression(character, expression, force) {
|
|||||||
document.getElementById("expression-holder").style.display = '';
|
document.getElementById("expression-holder").style.display = '';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Find the <img> element with id="expression-image" and class="expression"
|
|
||||||
const imgElement = document.querySelector('img#expression-image.expression');
|
|
||||||
//console.log("searching");
|
live2dcheck().then(result => {
|
||||||
if (imgElement) {
|
if (result) {
|
||||||
console.log("setting value");
|
// Find the <img> element with id="expression-image" and class="expression"
|
||||||
imgElement.src = getApiUrl() + '/api/live2d/result_feed';
|
const imgElement = document.querySelector('img#expression-image.expression');
|
||||||
|
//console.log("searching");
|
||||||
|
if (imgElement) {
|
||||||
|
//console.log("setting value");
|
||||||
|
imgElement.src = getApiUrl() + '/api/live2d/result_feed';
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//console.log("The fetch failed!");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user