mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-10 00:50:43 +01:00
Merge pull request #873 from pyrater/staging
This commit is contained in:
commit
b34df90905
@ -45,8 +45,6 @@ let lastCharacter = undefined;
|
|||||||
let lastMessage = null;
|
let lastMessage = null;
|
||||||
let spriteCache = {};
|
let spriteCache = {};
|
||||||
let inApiCall = false;
|
let inApiCall = false;
|
||||||
let previousSrc = null;
|
|
||||||
|
|
||||||
|
|
||||||
function isVisualNovelMode() {
|
function isVisualNovelMode() {
|
||||||
return Boolean(!isMobile() && power_user.waifuMode && getContext().groupId);
|
return Boolean(!isMobile() && power_user.waifuMode && getContext().groupId);
|
||||||
@ -395,6 +393,21 @@ function onExpressionsShowDefaultInput() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function unloadLiveChar() {
|
||||||
|
try {
|
||||||
|
const url = new URL(getApiUrl());
|
||||||
|
url.pathname = '/api/live2d/unload';
|
||||||
|
const loadResponse = await doExtrasFetch(url);
|
||||||
|
if (!loadResponse.ok) {
|
||||||
|
throw new Error(loadResponse.statusText);
|
||||||
|
}
|
||||||
|
const loadResponseText = await loadResponse.text();
|
||||||
|
//console.log(`Response: ${loadResponseText}`);
|
||||||
|
} catch (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');
|
||||||
@ -456,7 +469,6 @@ function handleImageChange() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (extension_settings.expressions.live2d) {
|
if (extension_settings.expressions.live2d) {
|
||||||
previousSrc = imgElement.src;
|
|
||||||
// Method get IP of endpoint
|
// Method get IP of endpoint
|
||||||
const live2dResultFeedSrc = `${getApiUrl()}/api/live2d/result_feed`;
|
const live2dResultFeedSrc = `${getApiUrl()}/api/live2d/result_feed`;
|
||||||
$('#expression-holder').css({ display: '' });
|
$('#expression-holder').css({ display: '' });
|
||||||
@ -496,7 +508,6 @@ async function moduleWorker() {
|
|||||||
if (context.groupId !== lastCharacter && context.characterId !== lastCharacter) {
|
if (context.groupId !== lastCharacter && context.characterId !== lastCharacter) {
|
||||||
removeExpression();
|
removeExpression();
|
||||||
spriteCache = {};
|
spriteCache = {};
|
||||||
previousSrc = null;
|
|
||||||
|
|
||||||
//clear expression
|
//clear expression
|
||||||
let imgElement = document.getElementById('expression-image');
|
let imgElement = document.getElementById('expression-image');
|
||||||
@ -611,12 +622,62 @@ 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) { loadLiveChar(); } // load char as needed
|
live2dcheck().then(result => {
|
||||||
handleImageChange(switch_var); // Change image as needed
|
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.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSpriteFolderName(message) {
|
function getSpriteFolderName(message) {
|
||||||
@ -917,13 +978,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!");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user