mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Reformat new code
This commit is contained in:
@ -405,9 +405,9 @@ function loadLiveChar(value_name) {
|
|||||||
'Bypass-Tunnel-Reminder': 'bypass',
|
'Bypass-Tunnel-Reminder': 'bypass',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(data => console.log(data))
|
.then(data => console.log(data))
|
||||||
.catch((error) => console.error('Error:', error));
|
.catch((error) => console.error('Error:', error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -425,18 +425,18 @@ function handleImageChange(isChecked) {
|
|||||||
const expressionListItemElement = document.querySelector('#live2d');
|
const expressionListItemElement = document.querySelector('#live2d');
|
||||||
const expressionImageElement = expressionListItemElement.querySelector('.expression_list_image');
|
const expressionImageElement = expressionListItemElement.querySelector('.expression_list_image');
|
||||||
const newSrc = expressionImageElement.src;
|
const newSrc = expressionImageElement.src;
|
||||||
|
|
||||||
doExtrasFetch(newSrc, {
|
doExtrasFetch(newSrc, {
|
||||||
method: 'HEAD',
|
method: 'HEAD',
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
imgElement.src = getApiUrl() + '/api/live2d/result_feed';
|
imgElement.src = getApiUrl() + '/api/live2d/result_feed';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error); // Log the error if necessary
|
console.error(error); // Log the error if necessary
|
||||||
});
|
});
|
||||||
} else if (previousSrc) {
|
} else if (previousSrc) {
|
||||||
imgElement.src = previousSrc; // Revert the src to its previous value
|
imgElement.src = previousSrc; // Revert the src to its previous value
|
||||||
}
|
}
|
||||||
@ -459,12 +459,12 @@ async function moduleWorker() {
|
|||||||
if (context.groupId !== lastCharacter && context.characterId !== lastCharacter) {
|
if (context.groupId !== lastCharacter && context.characterId !== lastCharacter) {
|
||||||
removeExpression();
|
removeExpression();
|
||||||
spriteCache = {};
|
spriteCache = {};
|
||||||
|
|
||||||
previousSrc = null;
|
previousSrc = null;
|
||||||
|
|
||||||
//uncheck live image
|
//uncheck live image
|
||||||
let checkbox = document.getElementById('image_type_toggle');
|
let checkbox = document.getElementById('image_type_toggle');
|
||||||
if (checkbox.checked) {
|
if (checkbox.checked) {
|
||||||
checkbox.click();
|
checkbox.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -765,126 +765,127 @@ async function getExpressionsList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function setExpression(character, expression, force) {
|
async function setExpression(character, expression, force) {
|
||||||
if (live2d_var == false) {
|
if (live2d_var == false) {
|
||||||
|
|
||||||
console.debug('entered setExpressions');
|
console.debug('entered setExpressions');
|
||||||
await validateImages(character);
|
await validateImages(character);
|
||||||
const img = $('img.expression');
|
const img = $('img.expression');
|
||||||
const prevExpressionSrc = img.attr('src');
|
const prevExpressionSrc = img.attr('src');
|
||||||
const expressionClone = img.clone()
|
const expressionClone = img.clone()
|
||||||
|
|
||||||
const sprite = (spriteCache[character] && spriteCache[character].find(x => x.label === expression));
|
const sprite = (spriteCache[character] && spriteCache[character].find(x => x.label === expression));
|
||||||
console.debug('checking for expression images to show..');
|
console.debug('checking for expression images to show..');
|
||||||
if (sprite) {
|
if (sprite) {
|
||||||
console.debug('setting expression from character images folder');
|
console.debug('setting expression from character images folder');
|
||||||
|
|
||||||
if (force && isVisualNovelMode()) {
|
if (force && isVisualNovelMode()) {
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
const group = context.groups.find(x => x.id === context.groupId);
|
const group = context.groups.find(x => x.id === context.groupId);
|
||||||
|
|
||||||
for (const member of group.members) {
|
for (const member of group.members) {
|
||||||
const groupMember = context.characters.find(x => x.avatar === member);
|
const groupMember = context.characters.find(x => x.avatar === member);
|
||||||
|
|
||||||
if (!groupMember) {
|
if (!groupMember) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (groupMember.name == character) {
|
if (groupMember.name == character) {
|
||||||
await setImage($(`.expression-holder[data-avatar="${member}"] img`), sprite.path);
|
await setImage($(`.expression-holder[data-avatar="${member}"] img`), sprite.path);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
//only swap expressions when necessary
|
||||||
//only swap expressions when necessary
|
if (prevExpressionSrc !== sprite.path
|
||||||
if (prevExpressionSrc !== sprite.path
|
&& !img.hasClass('expression-animating')) {
|
||||||
&& !img.hasClass('expression-animating')) {
|
//clone expression
|
||||||
//clone expression
|
expressionClone.addClass('expression-clone')
|
||||||
expressionClone.addClass('expression-clone')
|
//make invisible and remove id to prevent double ids
|
||||||
//make invisible and remove id to prevent double ids
|
//must be made invisible to start because they share the same Z-index
|
||||||
//must be made invisible to start because they share the same Z-index
|
expressionClone.attr('id', '').css({ opacity: 0 });
|
||||||
expressionClone.attr('id', '').css({ opacity: 0 });
|
//add new sprite path to clone src
|
||||||
//add new sprite path to clone src
|
expressionClone.attr('src', sprite.path);
|
||||||
expressionClone.attr('src', sprite.path);
|
//add invisible clone to html
|
||||||
//add invisible clone to html
|
expressionClone.appendTo($("#expression-holder"))
|
||||||
expressionClone.appendTo($("#expression-holder"))
|
|
||||||
|
|
||||||
const duration = 200;
|
const duration = 200;
|
||||||
|
|
||||||
//add animation flags to both images
|
//add animation flags to both images
|
||||||
//to prevent multiple expression changes happening simultaneously
|
//to prevent multiple expression changes happening simultaneously
|
||||||
img.addClass('expression-animating');
|
img.addClass('expression-animating');
|
||||||
|
|
||||||
// Set the parent container's min width and height before running the transition
|
// Set the parent container's min width and height before running the transition
|
||||||
const imgWidth = img.width();
|
const imgWidth = img.width();
|
||||||
const imgHeight = img.height();
|
const imgHeight = img.height();
|
||||||
const expressionHolder = img.parent();
|
const expressionHolder = img.parent();
|
||||||
expressionHolder.css('min-width', imgWidth > 100 ? imgWidth : 100);
|
expressionHolder.css('min-width', imgWidth > 100 ? imgWidth : 100);
|
||||||
expressionHolder.css('min-height', imgHeight > 100 ? imgHeight : 100);
|
expressionHolder.css('min-height', imgHeight > 100 ? imgHeight : 100);
|
||||||
|
|
||||||
//position absolute prevent the original from jumping around during transition
|
//position absolute prevent the original from jumping around during transition
|
||||||
img.css('position', 'absolute');
|
img.css('position', 'absolute');
|
||||||
expressionClone.addClass('expression-animating');
|
expressionClone.addClass('expression-animating');
|
||||||
//fade the clone in
|
//fade the clone in
|
||||||
expressionClone.css({
|
expressionClone.css({
|
||||||
opacity: 0
|
opacity: 0
|
||||||
}).animate({
|
}).animate({
|
||||||
opacity: 1
|
opacity: 1
|
||||||
}, duration)
|
}, duration)
|
||||||
//when finshed fading in clone, fade out the original
|
//when finshed fading in clone, fade out the original
|
||||||
.promise().done(function () {
|
.promise().done(function () {
|
||||||
img.animate({
|
img.animate({
|
||||||
opacity: 0
|
opacity: 0
|
||||||
}, duration);
|
}, duration);
|
||||||
//remove old expression
|
//remove old expression
|
||||||
img.remove();
|
img.remove();
|
||||||
//replace ID so it becomes the new 'original' expression for next change
|
//replace ID so it becomes the new 'original' expression for next change
|
||||||
expressionClone.attr('id', 'expression-image');
|
expressionClone.attr('id', 'expression-image');
|
||||||
expressionClone.removeClass('expression-animating');
|
expressionClone.removeClass('expression-animating');
|
||||||
|
|
||||||
// Reset the expression holder min height and width
|
// Reset the expression holder min height and width
|
||||||
expressionHolder.css('min-width', 100);
|
expressionHolder.css('min-width', 100);
|
||||||
expressionHolder.css('min-height', 100);
|
expressionHolder.css('min-height', 100);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
expressionClone.removeClass('expression-clone');
|
||||||
|
|
||||||
|
expressionClone.removeClass('default');
|
||||||
|
expressionClone.off('error');
|
||||||
|
expressionClone.on('error', function () {
|
||||||
|
console.debug('Expression image error', sprite.path);
|
||||||
|
$(this).attr('src', '');
|
||||||
|
$(this).off('error');
|
||||||
|
if (force && extension_settings.expressions.showDefault) {
|
||||||
|
setDefault();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
if (extension_settings.expressions.showDefault) {
|
||||||
expressionClone.removeClass('expression-clone');
|
|
||||||
|
|
||||||
expressionClone.removeClass('default');
|
|
||||||
expressionClone.off('error');
|
|
||||||
expressionClone.on('error', function () {
|
|
||||||
console.debug('Expression image error', sprite.path);
|
|
||||||
$(this).attr('src', '');
|
|
||||||
$(this).off('error');
|
|
||||||
if (force && extension_settings.expressions.showDefault) {
|
|
||||||
setDefault();
|
setDefault();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} else {
|
}
|
||||||
if (extension_settings.expressions.showDefault) {
|
|
||||||
setDefault();
|
function setDefault() {
|
||||||
|
console.debug('setting default');
|
||||||
|
const defImgUrl = `/img/default-expressions/${expression}.png`;
|
||||||
|
//console.log(defImgUrl);
|
||||||
|
img.attr('src', defImgUrl);
|
||||||
|
img.addClass('default');
|
||||||
|
}
|
||||||
|
document.getElementById("expression-holder").style.display = '';
|
||||||
|
|
||||||
|
if (live2d_var == true) {
|
||||||
|
// Find the <img> element with id="expression-image" and class="expression"
|
||||||
|
const imgElement = document.querySelector('img#expression-image.expression');
|
||||||
|
//console.log("searching");
|
||||||
|
if (imgElement) {
|
||||||
|
console.log("setting value");
|
||||||
|
imgElement.src = getApiUrl() + '/api/live2d/result_feed';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
function setDefault() {
|
|
||||||
console.debug('setting default');
|
|
||||||
const defImgUrl = `/img/default-expressions/${expression}.png`;
|
|
||||||
//console.log(defImgUrl);
|
|
||||||
img.attr('src', defImgUrl);
|
|
||||||
img.addClass('default');
|
|
||||||
}
|
|
||||||
document.getElementById("expression-holder").style.display = '';
|
|
||||||
|
|
||||||
if (live2d_var == true) {
|
|
||||||
// Find the <img> element with id="expression-image" and class="expression"
|
|
||||||
const imgElement = document.querySelector('img#expression-image.expression');
|
|
||||||
//console.log("searching");
|
|
||||||
if (imgElement) {
|
|
||||||
console.log("setting value");
|
|
||||||
imgElement.src = getApiUrl() + '/api/live2d/result_feed';
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onClickExpressionImage() {
|
function onClickExpressionImage() {
|
||||||
// online mode doesn't need force set
|
// online mode doesn't need force set
|
||||||
@ -1194,7 +1195,7 @@ function setExpressionOverrideHtml(forceClear = false) {
|
|||||||
$('.expression_settings').hide();
|
$('.expression_settings').hide();
|
||||||
|
|
||||||
|
|
||||||
$('#image_type_toggle').on('change', function() {
|
$('#image_type_toggle').on('change', function () {
|
||||||
const isChecked = this.checked;
|
const isChecked = this.checked;
|
||||||
const inputElement = document.querySelector('input[name="avatar_url"]');
|
const inputElement = document.querySelector('input[name="avatar_url"]');
|
||||||
const value_name = inputElement ? inputElement.value : '';
|
const value_name = inputElement ? inputElement.value : '';
|
||||||
@ -1204,7 +1205,6 @@ function setExpressionOverrideHtml(forceClear = false) {
|
|||||||
handleImageChange(isChecked);
|
handleImageChange(isChecked);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
addExpressionImage();
|
addExpressionImage();
|
||||||
addVisualNovelMode();
|
addVisualNovelMode();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { callPopup, cancelTtsPlay, eventSource, event_types, isMultigenEnabled, is_send_press, saveSettingsDebounced } from '../../../script.js'
|
import { callPopup, cancelTtsPlay, eventSource, event_types, isMultigenEnabled, is_send_press, saveSettingsDebounced } from '../../../script.js'
|
||||||
import { ModuleWorkerWrapper, extension_settings, getContext } from '../../extensions.js'
|
import { ModuleWorkerWrapper, doExtrasFetch, extension_settings, getApiUrl, getContext } from '../../extensions.js'
|
||||||
import { escapeRegex, getStringHash } from '../../utils.js'
|
import { escapeRegex, getStringHash } from '../../utils.js'
|
||||||
import { EdgeTtsProvider } from './edge.js'
|
import { EdgeTtsProvider } from './edge.js'
|
||||||
import { ElevenLabsTtsProvider } from './elevenlabs.js'
|
import { ElevenLabsTtsProvider } from './elevenlabs.js'
|
||||||
@ -7,7 +7,6 @@ import { SileroTtsProvider } from './silerotts.js'
|
|||||||
import { CoquiTtsProvider } from './coquitts.js'
|
import { CoquiTtsProvider } from './coquitts.js'
|
||||||
import { SystemTtsProvider } from './system.js'
|
import { SystemTtsProvider } from './system.js'
|
||||||
import { NovelTtsProvider } from './novel.js'
|
import { NovelTtsProvider } from './novel.js'
|
||||||
import { isMobile } from '../../RossAscends-mods.js'
|
|
||||||
import { power_user } from '../../power-user.js'
|
import { power_user } from '../../power-user.js'
|
||||||
|
|
||||||
const UPDATE_INTERVAL = 1000
|
const UPDATE_INTERVAL = 1000
|
||||||
@ -165,18 +164,18 @@ async function moduleWorker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function talkingAnimation(switchValue) {
|
function talkingAnimation(switchValue) {
|
||||||
const apiKeyValue = document.getElementById("extensions_url").value;
|
const apiUrl = getApiUrl();
|
||||||
const animationType = switchValue ? "start" : "stop";
|
const animationType = switchValue ? "start" : "stop";
|
||||||
|
|
||||||
if (switchValue !== storedvalue) {
|
if (switchValue !== storedvalue) {
|
||||||
try {
|
try {
|
||||||
console.log(animationType + " Talking Animation");
|
console.log(animationType + " Talking Animation");
|
||||||
fetch(`${apiKeyValue}/api/live2d/${animationType}_talking`);
|
doExtrasFetch(`${apiUrl}/api/live2d/${animationType}_talking`);
|
||||||
storedvalue = switchValue; // Update the storedvalue to the current switchValue
|
storedvalue = switchValue; // Update the storedvalue to the current switchValue
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Handle the error here or simply ignore it to prevent logging
|
// Handle the error here or simply ignore it to prevent logging
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetTtsPlayback() {
|
function resetTtsPlayback() {
|
||||||
|
Reference in New Issue
Block a user