mirror of
https://github.com/Buriburizaem0n/live2d.git
synced 2026-02-04 11:30:02 +00:00
added regular expression
This commit is contained in:
@@ -227,22 +227,19 @@ function loadWidget() {
|
|||||||
const modelPath = `${live2d_path}model/${target}/index.json`;
|
const modelPath = `${live2d_path}model/${target}/index.json`;
|
||||||
const modelPathAlt = `${live2d_path}model/${target}/index3.json`;
|
const modelPathAlt = `${live2d_path}model/${target}/index3.json`;
|
||||||
|
|
||||||
// 先尝试使用 loadlive2d 加载
|
// 使用正则表达式判断文件名
|
||||||
try {
|
if (/index3\.json$/.test(modelPathAlt)) {
|
||||||
await loadlive2d("live2d", modelPath); // 假设 loadlive2d 返回的是 Promise
|
// 如果文件名为 index3.json,则使用 loadModelPixi
|
||||||
console.log(`Live2D 模型 ${modelId}-${target} 的 index.json 文件加载完成`);
|
loadModelPixi("live2d", modelPathAlt);
|
||||||
} 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", modelPathAlt);
|
console.log(`使用 Live2D 加载模型 ${modelId}-${target} 的 index.json 文件`);
|
||||||
console.log(`Live2D 模型 ${modelId}-${target} 的 index3.json 文件加载完成 (使用 Pixi)`);
|
|
||||||
} catch (pixiError) {
|
|
||||||
console.error(`使用 Pixi 加载模型也失败: ${pixiError.message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function loadNextModel() {
|
async function loadNextModel() {
|
||||||
let modelId = localStorage.getItem("modelId");
|
let modelId = localStorage.getItem("modelId");
|
||||||
if (!modelList) await loadModelList();
|
if (!modelList) await loadModelList();
|
||||||
|
|||||||
Reference in New Issue
Block a user