mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	live2d -> talkinghead
This commit is contained in:
		| @@ -9,7 +9,7 @@ const MODULE_NAME = 'expressions'; | |||||||
| const UPDATE_INTERVAL = 2000; | const UPDATE_INTERVAL = 2000; | ||||||
| const FALLBACK_EXPRESSION = 'joy'; | const FALLBACK_EXPRESSION = 'joy'; | ||||||
| const DEFAULT_EXPRESSIONS = [ | const DEFAULT_EXPRESSIONS = [ | ||||||
|     "live2d", |     "talkinghead", | ||||||
|     "admiration", |     "admiration", | ||||||
|     "amusement", |     "amusement", | ||||||
|     "anger", |     "anger", | ||||||
| @@ -396,7 +396,7 @@ function onExpressionsShowDefaultInput() { | |||||||
| async function unloadLiveChar() { | async function unloadLiveChar() { | ||||||
|     try { |     try { | ||||||
|         const url = new URL(getApiUrl()); |         const url = new URL(getApiUrl()); | ||||||
|         url.pathname = '/api/live2d/unload'; |         url.pathname = '/api/talkinghead/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); | ||||||
| @@ -409,8 +409,8 @@ async function unloadLiveChar() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function loadLiveChar() { | async function loadLiveChar() { | ||||||
|     if (!modules.includes('live2d')) { |     if (!modules.includes('talkinghead')) { | ||||||
|         console.debug('live2d module is disabled'); |         console.debug('talkinghead module is disabled'); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -426,22 +426,22 @@ async function loadLiveChar() { | |||||||
|         spriteFolderName = expressionOverride.path; |         spriteFolderName = expressionOverride.path; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const live2dPath = `/characters/${encodeURIComponent(spriteFolderName)}/live2d.png`; |     const talkingheadPath = `/characters/${encodeURIComponent(spriteFolderName)}/talkinghead.png`; | ||||||
|  |  | ||||||
|     try { |     try { | ||||||
|         const spriteResponse = await fetch(live2dPath); |         const spriteResponse = await fetch(talkingheadPath); | ||||||
|  |  | ||||||
|         if (!spriteResponse.ok) { |         if (!spriteResponse.ok) { | ||||||
|             throw new Error(spriteResponse.statusText); |             throw new Error(spriteResponse.statusText); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         const spriteBlob = await spriteResponse.blob(); |         const spriteBlob = await spriteResponse.blob(); | ||||||
|         const spriteFile = new File([spriteBlob], 'live2d.png', { type: 'image/png' }); |         const spriteFile = new File([spriteBlob], 'talkinghead.png', { type: 'image/png' }); | ||||||
|         const formData = new FormData(); |         const formData = new FormData(); | ||||||
|         formData.append('file', spriteFile); |         formData.append('file', spriteFile); | ||||||
|  |  | ||||||
|         const url = new URL(getApiUrl()); |         const url = new URL(getApiUrl()); | ||||||
|         url.pathname = '/api/live2d/load'; |         url.pathname = '/api/talkinghead/load'; | ||||||
|  |  | ||||||
|         const loadResponse = await doExtrasFetch(url, { |         const loadResponse = await doExtrasFetch(url, { | ||||||
|             method: 'POST', |             method: 'POST', | ||||||
| @@ -453,10 +453,10 @@ async function loadLiveChar() { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         const loadResponseText = await loadResponse.text(); |         const loadResponseText = await loadResponse.text(); | ||||||
|         console.log(`Load live2d response: ${loadResponseText}`); |         console.log(`Load talkinghead response: ${loadResponseText}`); | ||||||
|  |  | ||||||
|     } catch (error) { |     } catch (error) { | ||||||
|         console.error(`Error loading live2d image: ${live2dPath} - ${error}`); |         console.error(`Error loading talkinghead image: ${talkingheadPath} - ${error}`); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -468,11 +468,11 @@ function handleImageChange() { | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (extension_settings.expressions.live2d) { |     if (extension_settings.expressions.talkinghead) { | ||||||
|         // Method get IP of endpoint |         // Method get IP of endpoint | ||||||
|         const live2dResultFeedSrc = `${getApiUrl()}/api/live2d/result_feed`; |         const talkingheadResultFeedSrc = `${getApiUrl()}/api/talkinghead/result_feed`; | ||||||
|         $('#expression-holder').css({ display: '' }); |         $('#expression-holder').css({ display: '' }); | ||||||
|         if (imgElement.src !== live2dResultFeedSrc) { |         if (imgElement.src !== talkingheadResultFeedSrc) { | ||||||
|             const expressionImageElement = document.querySelector('.expression_list_image'); |             const expressionImageElement = document.querySelector('.expression_list_image'); | ||||||
|  |  | ||||||
|             if (expressionImageElement) { |             if (expressionImageElement) { | ||||||
| @@ -481,7 +481,7 @@ function handleImageChange() { | |||||||
|                 }) |                 }) | ||||||
|                     .then(response => { |                     .then(response => { | ||||||
|                         if (response.ok) { |                         if (response.ok) { | ||||||
|                             imgElement.src = live2dResultFeedSrc; |                             imgElement.src = talkingheadResultFeedSrc; | ||||||
|                         } |                         } | ||||||
|                     }) |                     }) | ||||||
|                     .catch(error => { |                     .catch(error => { | ||||||
| @@ -514,9 +514,9 @@ async function moduleWorker() { | |||||||
|         imgElement.src = ""; |         imgElement.src = ""; | ||||||
|  |  | ||||||
|         //set checkbox to global var |         //set checkbox to global var | ||||||
|         $('#image_type_toggle').prop('checked', extension_settings.expressions.live2d); |         $('#image_type_toggle').prop('checked', extension_settings.expressions.talkinghead); | ||||||
|         if(extension_settings.expressions.live2d == true){ |         if(extension_settings.expressions.talkinghead == true){ | ||||||
|             setLive2dState(extension_settings.expressions.live2d); |             settalkingheadState(extension_settings.expressions.talkinghead); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -622,7 +622,7 @@ async function moduleWorker() { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| async function live2dcheck() { | async function talkingheadcheck() { | ||||||
|     const context = getContext(); |     const context = getContext(); | ||||||
|     let spriteFolderName = context.name2; |     let spriteFolderName = context.name2; | ||||||
|     const message = getLastCharacterMessage(); |     const message = getLastCharacterMessage(); | ||||||
| @@ -638,14 +638,14 @@ async function live2dcheck() { | |||||||
|     try { |     try { | ||||||
|         await validateImages(spriteFolderName); |         await validateImages(spriteFolderName); | ||||||
|  |  | ||||||
|         let live2dObj = spriteCache[spriteFolderName].find(obj => obj.label === 'live2d'); |         let talkingheadObj = spriteCache[spriteFolderName].find(obj => obj.label === 'talkinghead'); | ||||||
|         let live2dPath_f = live2dObj ? live2dObj.path : null; |         let talkingheadPath_f = talkingheadObj ? talkingheadObj.path : null; | ||||||
|  |  | ||||||
|         if(live2dPath_f != null){ |         if(talkingheadPath_f != null){ | ||||||
|             //console.log("live2dPath_f " + live2dPath_f); |             //console.log("talkingheadPath_f " + talkingheadPath_f); | ||||||
|             return true; |             return true; | ||||||
|         } else {  |         } else {  | ||||||
|             //console.log("live2dPath_f is null");  |             //console.log("talkingheadPath_f is null");  | ||||||
|             unloadLiveChar(); |             unloadLiveChar(); | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| @@ -654,15 +654,15 @@ async function live2dcheck() { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| function setLive2dState(switch_var){ | function settalkingheadState(switch_var){ | ||||||
|     extension_settings.expressions.live2d = switch_var; // Store setting |     extension_settings.expressions.talkinghead = switch_var; // Store setting | ||||||
|     saveSettingsDebounced(); |     saveSettingsDebounced(); | ||||||
|  |  | ||||||
|     live2dcheck().then(result => { |     talkingheadcheck().then(result => { | ||||||
|         if (result) { |         if (result) { | ||||||
|             //console.log("Live2d exists!"); |             //console.log("talkinghead exists!"); | ||||||
|  |  | ||||||
|                 if (extension_settings.expressions.live2d) {  |                 if (extension_settings.expressions.talkinghead) {  | ||||||
|                     loadLiveChar();  |                     loadLiveChar();  | ||||||
|                 } else { |                 } else { | ||||||
|                     unloadLiveChar();  |                     unloadLiveChar();  | ||||||
| @@ -671,7 +671,7 @@ function setLive2dState(switch_var){ | |||||||
|  |  | ||||||
|  |  | ||||||
|         } else { |         } else { | ||||||
|             //console.log("Live2d does not exist."); |             //console.log("talkinghead does not exist."); | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
|      |      | ||||||
| @@ -867,7 +867,7 @@ async function getExpressionsList() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function setExpression(character, expression, force) { | async function setExpression(character, expression, force) { | ||||||
|     if (extension_settings.expressions.live2d == false) { |     if (extension_settings.expressions.talkinghead == false) { | ||||||
|  |  | ||||||
|         console.debug('entered setExpressions'); |         console.debug('entered setExpressions'); | ||||||
|         await validateImages(character); |         await validateImages(character); | ||||||
| @@ -980,14 +980,14 @@ async function setExpression(character, expression, force) { | |||||||
|     } else { |     } else { | ||||||
|  |  | ||||||
|  |  | ||||||
|         live2dcheck().then(result => { |         talkingheadcheck().then(result => { | ||||||
|             if (result) { |             if (result) { | ||||||
|                     // Find the <img> element with id="expression-image" and class="expression" |                     // Find the <img> element with id="expression-image" and class="expression" | ||||||
|                     const imgElement = document.querySelector('img#expression-image.expression'); |                     const imgElement = document.querySelector('img#expression-image.expression'); | ||||||
|                     //console.log("searching"); |                     //console.log("searching"); | ||||||
|                     if (imgElement) { |                     if (imgElement) { | ||||||
|                         //console.log("setting value"); |                         //console.log("setting value"); | ||||||
|                         imgElement.src = getApiUrl() + '/api/live2d/result_feed'; |                         imgElement.src = getApiUrl() + '/api/talkinghead/result_feed'; | ||||||
|                     } |                     } | ||||||
|      |      | ||||||
|             } else { |             } else { | ||||||
| @@ -1259,7 +1259,7 @@ function setExpressionOverrideHtml(forceClear = false) { | |||||||
| 						<label class="switch"> | 						<label class="switch"> | ||||||
|                             <input id="image_type_toggle" type="checkbox"> |                             <input id="image_type_toggle" type="checkbox"> | ||||||
|                             <span class="slider round"></span> |                             <span class="slider round"></span> | ||||||
|                         <label for="image_type_toggle">Image Type - Live2d (extras)</label> |                         <label for="image_type_toggle">Image Type - talkinghead (extras)</label> | ||||||
|                   </div> |                   </div> | ||||||
|                                       <div class="offline_mode"> |                                       <div class="offline_mode"> | ||||||
|                         <small>You are in offline mode. Click on the image below to set the expression.</small> |                         <small>You are in offline mode. Click on the image below to set the expression.</small> | ||||||
| @@ -1308,7 +1308,7 @@ function setExpressionOverrideHtml(forceClear = false) { | |||||||
|         $('.expression_settings').hide(); |         $('.expression_settings').hide(); | ||||||
|  |  | ||||||
|         $('#image_type_toggle').on('click', function () { |         $('#image_type_toggle').on('click', function () { | ||||||
|             setLive2dState(this.checked); |             settalkingheadState(this.checked); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -170,7 +170,7 @@ function talkingAnimation(switchValue) { | |||||||
|     if (switchValue !== storedvalue) { |     if (switchValue !== storedvalue) { | ||||||
|         try { |         try { | ||||||
|             console.log(animationType + " Talking Animation"); |             console.log(animationType + " Talking Animation"); | ||||||
|             doExtrasFetch(`${apiUrl}/api/live2d/${animationType}_talking`); |             doExtrasFetch(`${apiUrl}/api/talkinghead/${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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user