change the Structure of Model_list.json

This commit is contained in:
2024-09-20 10:59:01 +02:00
parent c4ac07e39f
commit 88fdd1334d
5 changed files with 18 additions and 22 deletions

View File

@@ -1,11 +1,11 @@
{ {
"models": [ "models_json_path": [
"tororo", "tororo/index.json",
"hijiki", "hijiki/index.json",
"kesyoban", "kesyoban/index.json",
"pichu", "pichu/index3.json",
"pikachu", "pikachu/index3.json",
"pome" "pome/index3.json"
], ],
"messages": [ "messages": [

View File

@@ -221,24 +221,20 @@ function loadWidget() {
showMessage(message, 4000, 10); showMessage(message, 4000, 10);
if (!modelList) await loadModelList(); if (!modelList) await loadModelList();
let target = modelList.models[modelId]; let target = modelList.models_json_path[modelId];
// 模型路径 // 模型路径
const modelPath = `${live2d_path}model/${target}/index.json`; const modelPath = `${live2d_path}model/${target}`;
// 先尝试使用 loadlive2d 加载 // 使用正则表达式判断文件名
try { if (/index3\.json$/.test(modelPath)) {
await loadlive2d("live2d", modelPath); // 假设 loadlive2d 返回 Promise // 如果文件名为 index3.json则使用 loadModelPixi
console.log(`Live2D 模型 ${modelId}-${target} 的 index.json 文件加载完成`); loadModelPixi("live2d", modelPath);
} catch (error) { console.log(`使用 Pixi 加载 Live2D 模型 ${modelId}-${target} 的 index3.json 文件`);
console.error(`加载 Live2D 模型失败: ${error.message},尝试使用 Pixi 加载模型`); } else {
try { // 否则使用 loadlive2d 加载 index.json
// 如果 loadlive2d 失败,尝试使用 loadModelPixi 加载 index3.json loadlive2d("live2d", modelPath);
await loadModelPixi("live2d", modelPath); console.log(`使用 Live2D 加载模型 ${modelId}-${target} 的 index.json 文件`);
console.log(`Live2D 模型 ${modelId}-${target} 的 index.json 文件加载完成 (使用 Pixi)`);
} catch (pixiError) {
console.error(`使用 Pixi 加载模型也失败: ${pixiError.message}`);
}
} }
} }