fix:高级动画ticker跨层摧毁的同时,自身被摧毁不会保留引用

This commit is contained in:
ShakeFlower 2025-05-27 10:51:27 +08:00
parent d085e923fb
commit 574fa21160
3 changed files with 14 additions and 12 deletions

View File

@ -532,7 +532,7 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
}, },
{ {
"type": "function", "type": "function",
"function": "function(){\n// 默认读取弹幕数据\nif (core.hasFlag('comment') && !core.isReplaying()) {\n\tcore.plugin.getComment();\n\tsetTimeout(core.plugin.drawCommentSign, 1000);\n}\n}" "function": "function(){\n// 默认读取弹幕数据\nif (core.hasFlag('comment') && !core.isReplaying()) {\n\tnew Promise(res => {\n\t\t\tsetTimeout(res, 1000);\n\t\t})\n\t\t.then(value => {\n\t\t\treturn new Promise(res => {\n\t\t\t\tcore.plugin.getComment();\n\t\t\t\tsetTimeout(res, 1000);\n\t\t\t})\n\t\t})\n\t\t.then(value => {\n\t\t\tcore.plugin.drawCommentSign();\n\t\t})\n}\n}"
} }
], ],
"shops": [ "shops": [
@ -746,6 +746,6 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
"enableRouteFolding": true, "enableRouteFolding": true,
"disableShopOnDamage": false, "disableShopOnDamage": false,
"blurFg": false, "blurFg": false,
"chaseThroughEnemy": false, "chaseThroughEnemy": false
} }
} }

View File

@ -1153,18 +1153,17 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
if (main.replayChecking) __enable = false; if (main.replayChecking) __enable = false;
if (!__enable) { if (!__enable) {
core.plugin.animate = {}; core.plugin.animate = {};
this.aniMap = new Map(); this.tickerSet = new Set();
this.deleteAllAnis = () => { }; this.deleteAllAnis = () => { };
return; return;
} }
/** 键为一个自建Ticker, 值为摧毁它的事件 */ /** 该集合中的所有Ticker在跨层时需要被摧毁 */
this.aniMap = new Map(); this.tickerSet = new Set();
/** 对Map中所有Ticker执行摧毁事件 */ /** 对Map中所有Ticker执行摧毁事件 */
this.deleteAllAnis = function () { this.deleteAllAnis = function () {
core.plugin.aniMap.forEach((destroyEvent, ani) => destroyEvent(ani)); core.plugin.tickerSet.forEach((ticker) => ticker.destroy());
core.plugin.aniMap.clear();
} }
// var M = Object.defineProperty; // var M = Object.defineProperty;
@ -1202,6 +1201,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
this.funcs.clear(); this.funcs.clear();
} }
destroy() { destroy() {
core.plugin.tickerSet.delete(this);
this.clear(), this.stop(); this.clear(), this.stop();
} }
stop() { stop() {
@ -1894,7 +1894,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
const { Transition, hyper, Ticker } = core.plugin.animate ?? {}; const { Transition, hyper, Ticker } = core.plugin.animate ?? {};
// 磁吸特效的时长,单位毫秒 // 磁吸特效的时长,单位毫秒
const transitionTime = 600; const transitionTime = 400;
const transitionList = []; const transitionList = [];
@ -2119,7 +2119,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
const index = transitionList.findIndex(v => v === t); const index = transitionList.findIndex(v => v === t);
transitionList.splice(index, 1); transitionList.splice(index, 1);
} // 摧毁Transition t } // 摧毁Transition t
core.plugin.aniMap.set(t, onDestory); core.plugin.tickerSet.add(t.ticker);
t.mode(hyper('sin', 'out')) t.mode(hyper('sin', 'out'))
.time(transitionTime) .time(transitionTime)
.absolute() .absolute()
@ -2388,12 +2388,12 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
function drawCommentStr(content, x, y, vx) { function drawCommentStr(content, x, y, vx) {
if (core.isReplaying() || !Animation) return; if (core.isReplaying() || !Animation) return;
const ani = new Animation(); const ani = new Animation();
core.plugin.aniMap.set(ani, (ani) => ani.ticker.destroy()); core.plugin.tickerSet.add(ani.ticker);
ani.ticker.add(() => { ani.ticker.add(() => {
core.fillText(ctxName, content, x + ani.x, y, 'white', '16px Verdana'); core.fillText(ctxName, content, x + ani.x, y, 'white', '16px Verdana');
}) })
// 弹幕的最大长度5600再长属于异常数据 // 弹幕的最大长度5600再长属于异常数据
const aim = 600 + Math.min(core.calWidth(ctxName, content, '16px Verdana'), 5000); const aim = 100 + Math.min(core.calWidth(ctxName, content, '16px Verdana'), 5000);
ani.mode(linear()) ani.mode(linear())
.time(aim / vx) .time(aim / vx)
.absolute() .absolute()

4
runtime.d.ts vendored
View File

@ -3058,7 +3058,9 @@ interface plugin {
animate: { animate: {
Animation: any, AnimationBase: any, Ticker: any, Transition: any, bezier: any, bezierPath: any, circle: any, Animation: any, AnimationBase: any, Ticker: any, Transition: any, bezier: any, bezierPath: any, circle: any,
hyper: any, inverseTrigo: any, linear: any, power: any, shake: any, sleep: any, trigo: any, hyper: any, inverseTrigo: any, linear: any, power: any, shake: any, sleep: any, trigo: any,
} & {} }
/** 该集合中的所有Ticker在跨层时需要被摧毁 */
tickerSet: Set
/** 打开一个道具商店 */ /** 打开一个道具商店 */
openItemShop: (itemShopId: string) => void openItemShop: (itemShopId: string) => void