mirror of
https://github.com/Buriburizaem0n/live2d.git
synced 2026-11-04 13:40:20 +00:00
fixed error
This commit is contained in:
1 parent
ea5e227b43
commit
1fe6c80b37
2 files changed
+30
-32
No files matched your search
Vendored
+1
-1
@@ -388,7 +388,7 @@ eval("/*\n * Copyright Joyent, Inc. and other Node contributors.\n *\n * Permiss
|
|||||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var pixi_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! pixi.js */ \"./node_modules/pixi.js/lib/index.mjs\");\n/* harmony import */ var pixi_live2d_display__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! pixi-live2d-display */ \"./node_modules/pixi-live2d-display/dist/index.es.js\");\n\n\n\nfunction ap_init() {\n $(\".aplayer-body\").addClass(\"my-hide\");\n ap.lrc.hide(); //初始化时隐藏歌词\n ap.on('play', () => ap.lrc.show());\n ap.on('pause', () => ap.lrc.hide());\n}\n\nvar music_flag=false;\nfunction aplayer_panel_toggle(){\n\tif(music_flag){\n\t\t$(\".aplayer.aplayer-fixed .aplayer-body\").addClass(\"my-hide\");\n\t\t$(\".aplayer.aplayer-fixed .aplayer-list\").addClass(\"my-hide zero-margin-bottom\");\n\t\tmusic_flag=false;\n\t}\n\telse{\n\t\t$(\".aplayer.aplayer-fixed .aplayer-body\").removeClass(\"my-hide\");\n\t\t$(\".aplayer.aplayer-fixed .aplayer-list\").removeClass(\"my-hide zero-margin-bottom\");\n\t\tmusic_flag=true;\n\t}\n}\n\nfunction loadWidget() {\n\tlocalStorage.removeItem(\"waifu-display\");\n\tsessionStorage.removeItem(\"waifu-text\");\n\tdocument.body.insertAdjacentHTML(\"beforeend\", `<div id=\"waifu\">\n\t\t\t<div id=\"waifu-tips\"></div>\n\t\t\t<canvas id=\"live2d\" width=\"800\" height=\"800\"></canvas>\n\t\t\t<div id=\"waifu-tool\">\n\t\t\t\t<span class=\"fa fa-lg fa-music\"></span>\n\t\t\t\t<span class=\"fa fa-lg fa-comment\"></span>\n\t\t\t\t<span class=\"fa fa-lg fa-user-circle\"></span>\n\t\t\t\t<span class=\"fa fa-lg fa-times\"></span>\n\t\t\t</div>\n\t\t</div>`);\n\tsetTimeout(() => {\n\t\tdocument.getElementById(\"waifu\").style.bottom = 0;\n\t}, 0);\n\n\tfunction registerEventListener(result) {\n\t\tdocument.querySelector(\"#waifu-tool .fa-music\").addEventListener(\"click\", () => {\n\t\t\tap.toggle();\n\t\t});\n\t\tdocument.querySelector(\"#waifu-tool .fa-comment\").addEventListener(\"click\", showHitokoto);\n\t\tdocument.querySelector(\"#waifu-tool .fa-user-circle\").addEventListener(\"click\", loadNextModel);\n\t\tdocument.querySelector(\"#waifu-tool .fa-times\").addEventListener(\"click\", () => {\n\t\t\tlocalStorage.setItem(\"waifu-display\", Date.now());\n\t\t\tshowMessage(\"人生海海,祝你有帆也有岸。\", 2000, 11);\n\t\t\tdocument.getElementById(\"waifu\").style.bottom = \"-500px\";\n\t\t\tsetTimeout(() => {\n\t\t\t\tdocument.getElementById(\"waifu\").style.display = \"none\";\n\t\t\t\tdocument.getElementById(\"waifu-toggle\").classList.add(\"waifu-toggle-active\");\n\t\t\t}, 3000);\n\t\t});\n\t\t// 检测用户活动状态,并在空闲时显示消息\n let userAction = false,\n userActionTimer,\n messageArray = result.message.default,\n lastHoverElement;\n window.addEventListener(\"mousemove\", () => userAction = true);\n window.addEventListener(\"keydown\", () => userAction = true);\n setInterval(() => {\n if (userAction) {\n userAction = false;\n clearInterval(userActionTimer);\n userActionTimer = null;\n } else if (!userActionTimer) {\n userActionTimer = setInterval(() => {\n showMessage(messageArray, 6000, 9);\n }, 20000);\n }\n }, 1000);\n\t\tshowMessage(welcomeMessage(result.time), 7000, 11);\n window.addEventListener(\"mouseover\", event => {\n \t\tfor (let tips of result.mouseover) {\n \t\t\tif (!event.target.matches(tips.selector)) continue;\n \t\t\tlet text = randomSelection(tips.text);\n \t\t\ttext = text.replace(\"{text}\", event.target.innerText);\n \t\t\tshowMessage(text, 4000, 8);\n \t\t\treturn;\n \t\t}\n \t});\n \twindow.addEventListener(\"click\", event => {\n \t\tfor (let tips of result.click) {\n \t\t\tif (!event.target.matches(tips.selector)) continue;\n \t\t\tlet text = randomSelection(tips.text);\n \t\t\ttext = text.replace(\"{text}\", event.target.innerText);\n \t\t\tshowMessage(text, 4000, 8);\n \t\t\treturn;\n \t\t}\n \t});\n \t$(\"#live2d\").mousedown(function(e) {\n\t if(e.which==3){\n\t showMessage(result.message.secret_path,4000,12);\n\t\t\t}\n \t});\n \t$(\"#live2d\").bind(\"contextmenu\", function(e) {\n \t return false;\n \t});\n \tresult.seasons.forEach(({ date, text }) => {\n const now = new Date(),\n after = date.split(\"-\")[0],\n before = date.split(\"-\")[1] || after;\n if ((after.split(\"/\")[0] <= now.getMonth() + 1 && now.getMonth() + 1 <= before.split(\"/\")[0]) && (after.split(\"/\")[1] <= now.getDate() && now.getDate() <= before.split(\"/\")[1])) {\n text = randomSelection(text);\n text = text.replace(\"{year}\", now.getFullYear());\n messageArray.push(text);\n }\n });\n const devtools = ()
Line truncated
|
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var pixi_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! pixi.js */ \"./node_modules/pixi.js/lib/index.mjs\");\n/* harmony import */ var pixi_live2d_display__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! pixi-live2d-display */ \"./node_modules/pixi-live2d-display/dist/index.es.js\");\n\n\n\nfunction ap_init() {\n $(\".aplayer-body\").addClass(\"my-hide\");\n ap.lrc.hide(); //初始化时隐藏歌词\n ap.on('play', () => ap.lrc.show());\n ap.on('pause', () => ap.lrc.hide());\n}\n\nvar music_flag=false;\nfunction aplayer_panel_toggle(){\n\tif(music_flag){\n\t\t$(\".aplayer.aplayer-fixed .aplayer-body\").addClass(\"my-hide\");\n\t\t$(\".aplayer.aplayer-fixed .aplayer-list\").addClass(\"my-hide zero-margin-bottom\");\n\t\tmusic_flag=false;\n\t}\n\telse{\n\t\t$(\".aplayer.aplayer-fixed .aplayer-body\").removeClass(\"my-hide\");\n\t\t$(\".aplayer.aplayer-fixed .aplayer-list\").removeClass(\"my-hide zero-margin-bottom\");\n\t\tmusic_flag=true;\n\t}\n}\n\nfunction loadWidget() {\n\tlocalStorage.removeItem(\"waifu-display\");\n\tsessionStorage.removeItem(\"waifu-text\");\n\tdocument.body.insertAdjacentHTML(\"beforeend\", `<div id=\"waifu\">\n\t\t\t<div id=\"waifu-tips\"></div>\n\t\t\t<canvas id=\"live2d\" width=\"800\" height=\"800\"></canvas>\n\t\t\t<div id=\"waifu-tool\">\n\t\t\t\t<span class=\"fa fa-lg fa-music\"></span>\n\t\t\t\t<span class=\"fa fa-lg fa-comment\"></span>\n\t\t\t\t<span class=\"fa fa-lg fa-user-circle\"></span>\n\t\t\t\t<span class=\"fa fa-lg fa-times\"></span>\n\t\t\t</div>\n\t\t</div>`);\n\tsetTimeout(() => {\n\t\tdocument.getElementById(\"waifu\").style.bottom = 0;\n\t}, 0);\n\n\tfunction registerEventListener(result) {\n\t\tdocument.querySelector(\"#waifu-tool .fa-music\").addEventListener(\"click\", () => {\n\t\t\tap.toggle();\n\t\t});\n\t\tdocument.querySelector(\"#waifu-tool .fa-comment\").addEventListener(\"click\", showHitokoto);\n\t\tdocument.querySelector(\"#waifu-tool .fa-user-circle\").addEventListener(\"click\", loadNextModel);\n\t\tdocument.querySelector(\"#waifu-tool .fa-times\").addEventListener(\"click\", () => {\n\t\t\tlocalStorage.setItem(\"waifu-display\", Date.now());\n\t\t\tshowMessage(\"人生海海,祝你有帆也有岸。\", 2000, 11);\n\t\t\tdocument.getElementById(\"waifu\").style.bottom = \"-500px\";\n\t\t\tsetTimeout(() => {\n\t\t\t\tdocument.getElementById(\"waifu\").style.display = \"none\";\n\t\t\t\tdocument.getElementById(\"waifu-toggle\").classList.add(\"waifu-toggle-active\");\n\t\t\t}, 3000);\n\t\t});\n\t\t// 检测用户活动状态,并在空闲时显示消息\n let userAction = false,\n userActionTimer,\n messageArray = result.message.default,\n lastHoverElement;\n window.addEventListener(\"mousemove\", () => userAction = true);\n window.addEventListener(\"keydown\", () => userAction = true);\n setInterval(() => {\n if (userAction) {\n userAction = false;\n clearInterval(userActionTimer);\n userActionTimer = null;\n } else if (!userActionTimer) {\n userActionTimer = setInterval(() => {\n showMessage(messageArray, 6000, 9);\n }, 20000);\n }\n }, 1000);\n\t\tshowMessage(welcomeMessage(result.time), 7000, 11);\n window.addEventListener(\"mouseover\", event => {\n \t\tfor (let tips of result.mouseover) {\n \t\t\tif (!event.target.matches(tips.selector)) continue;\n \t\t\tlet text = randomSelection(tips.text);\n \t\t\ttext = text.replace(\"{text}\", event.target.innerText);\n \t\t\tshowMessage(text, 4000, 8);\n \t\t\treturn;\n \t\t}\n \t});\n \twindow.addEventListener(\"click\", event => {\n \t\tfor (let tips of result.click) {\n \t\t\tif (!event.target.matches(tips.selector)) continue;\n \t\t\tlet text = randomSelection(tips.text);\n \t\t\ttext = text.replace(\"{text}\", event.target.innerText);\n \t\t\tshowMessage(text, 4000, 8);\n \t\t\treturn;\n \t\t}\n \t});\n \t$(\"#live2d\").mousedown(function(e) {\n\t if(e.which==3){\n\t showMessage(result.message.secret_path,4000,12);\n\t\t\t}\n \t});\n \t$(\"#live2d\").bind(\"contextmenu\", function(e) {\n \t return false;\n \t});\n \tresult.seasons.forEach(({ date, text }) => {\n const now = new Date(),\n after = date.split(\"-\")[0],\n before = date.split(\"-\")[1] || after;\n if ((after.split(\"/\")[0] <= now.getMonth() + 1 && now.getMonth() + 1 <= before.split(\"/\")[0]) && (after.split(\"/\")[1] <= now.getDate() && now.getDate() <= before.split(\"/\")[1])) {\n text = randomSelection(text);\n text = text.replace(\"{year}\", now.getFullYear());\n messageArray.push(text);\n }\n });\n const devtools = ()
Line truncated
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
|
|||||||
+29
-31
@@ -1,3 +1,6 @@
|
|||||||
|
import * as PIXI from "pixi.js";
|
||||||
|
import { Live2DModel } from "pixi-live2d-display";
|
||||||
|
|
||||||
function ap_init() {
|
function ap_init() {
|
||||||
$(".aplayer-body").addClass("my-hide");
|
$(".aplayer-body").addClass("my-hide");
|
||||||
ap.lrc.hide(); //初始化时隐藏歌词
|
ap.lrc.hide(); //初始化时隐藏歌词
|
||||||
@@ -192,8 +195,7 @@ function loadWidget() {
|
|||||||
}
|
}
|
||||||
modelTexturesId = 0; // 材质ID
|
modelTexturesId = 0; // 材质ID
|
||||||
}
|
}
|
||||||
// loadModel(modelId, modelTexturesId);
|
loadModel(modelId, modelTexturesId);
|
||||||
loadModelPixi(modelId, modelTexturesId);
|
|
||||||
fetch(`${live2d_path}waifu-tips.json`)
|
fetch(`${live2d_path}waifu-tips.json`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(registerEventListener);
|
.then(registerEventListener);
|
||||||
@@ -211,7 +213,8 @@ 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[modelId];
|
||||||
loadlive2d("live2d", `${live2d_path}model/${target}/index.json`);
|
// loadlive2d("live2d", `${live2d_path}model/${target}/index.json`);
|
||||||
|
loadModelPixi("live2d", `${live2d_path}model/${target}/index.json`);
|
||||||
console.log(`Live2D 模型 ${modelId}-${target} 加载完成`);
|
console.log(`Live2D 模型 ${modelId}-${target} 加载完成`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,40 +222,35 @@ function loadWidget() {
|
|||||||
let modelId = localStorage.getItem("modelId");
|
let modelId = localStorage.getItem("modelId");
|
||||||
if (!modelList) await loadModelList();
|
if (!modelList) await loadModelList();
|
||||||
let index = (++modelId >= modelList.models.length) ? 0 : modelId;
|
let index = (++modelId >= modelList.models.length) ? 0 : modelId;
|
||||||
// loadModel(index, 0, modelList.messages[index]);
|
loadModel(index, 0, modelList.messages[index]);
|
||||||
loadModelPixi(index, 0, modelList.messages[index]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadModelPixi(modelId, modelTexturesId, message) {
|
window.PIXI = PIXI;
|
||||||
localStorage.setItem("modelId", modelId);
|
|
||||||
localStorage.setItem("modelTexturesId", modelTexturesId);
|
|
||||||
showMessage(message, 4000, 10);
|
|
||||||
if (!modelList) await loadModelList();
|
|
||||||
let target = modelList.models[modelId];
|
|
||||||
const jsonpath = `${live2d_path}model/${target}/index.json`;
|
|
||||||
const element = document.getElementById(modelId);
|
|
||||||
const app = new PIXI.Application({
|
|
||||||
view: element,
|
|
||||||
transparent: true,
|
|
||||||
});
|
|
||||||
const model = await Live2DModel.from(jsonpath);
|
|
||||||
|
|
||||||
app.stage.addChild(model);
|
async function loadModelPixi(id, jsonpath) {
|
||||||
|
const element = document.getElementById(id);
|
||||||
|
const app = new PIXI.Application({
|
||||||
|
view: element,
|
||||||
|
transparent: true,
|
||||||
|
});
|
||||||
|
const model = await Live2DModel.from(jsonpath);
|
||||||
|
|
||||||
const parentWidth = element.width;
|
app.stage.addChild(model);
|
||||||
const parentHeight = element.height;
|
|
||||||
// Scale to fit the stage
|
|
||||||
const ratio = Math.min(
|
|
||||||
parentWidth / model.width,
|
|
||||||
parentHeight / model.height
|
|
||||||
);
|
|
||||||
model.scale.set(ratio, ratio);
|
|
||||||
// Align bottom and center horizontally
|
|
||||||
|
|
||||||
model.x = (parentWidth - model.width) / 2;
|
const parentWidth = element.width;
|
||||||
model.y = parentHeight - model.height;
|
const parentHeight = element.height;
|
||||||
|
// Scale to fit the stage
|
||||||
|
const ratio = Math.min(
|
||||||
|
parentWidth / model.width,
|
||||||
|
parentHeight / model.height
|
||||||
|
);
|
||||||
|
model.scale.set(ratio, ratio);
|
||||||
|
// Align bottom and center horizontally
|
||||||
|
|
||||||
}
|
model.x = (parentWidth - model.width) / 2;
|
||||||
|
model.y = parentHeight - model.height;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user