Skip to content

Commit 1848315

Browse files
authored
Clone Count Addon -- DO NOT patch runtime.step. Use proper events
1 parent 8e45d9e commit 1848315

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

src/addons/addons/clones/userscript.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,10 @@ export default async function ({ addon, console, msg }) {
6767
doCloneChecks(true);
6868
});
6969

70-
const oldStep = vm.runtime._step;
71-
vm.runtime._step = function (...args) {
72-
const ret = oldStep.call(this, ...args);
73-
doCloneChecks();
74-
return ret;
75-
};
76-
77-
/*
78-
if (addon.self.enabledLate) {
79-
// Clone count might be inaccurate if the user deleted sprites
80-
// before enabling the addon
81-
let count = 0;
82-
for (let target of vm.runtime.targets) {
83-
if (!target.isOriginal) ++count;
84-
}
85-
vm.runtime._cloneCounter = count;
86-
}
87-
*/
70+
vm.runtime.on("targetWasCreated", (_, originalTarget) => {
71+
if (originalTarget) doCloneChecks();
72+
});
73+
vm.runtime.on("targetWasRemoved", doCloneChecks);
8874

8975
while (true) {
9076
await addon.tab.waitForElement('[class*="controls_controls-container"]', {
@@ -96,4 +82,4 @@ export default async function ({ addon, console, msg }) {
9682
addon.tab.appendToSharedSpace({ space: "afterStopButton", element: countContainerContainer, order: 2 });
9783
}
9884
}
99-
}
85+
}

0 commit comments

Comments
 (0)