Skip to content

Commit

Permalink
Restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazza-231 committed Jun 13, 2024
1 parent fa5c79f commit 9b1afad
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
4 changes: 2 additions & 2 deletions addons/sprite-clone-count/addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"matches": ["projects"]
}
],
"versionAdded": "1.35.0",
"tags": ["projects", "featured"],
"versionAdded": "1.39.0",
"tags": ["editor", "codeEditor", "featured"],
"enabledByDefault": false,
"dynamicEnable": true,
"dynamicDisable": true
Expand Down
64 changes: 35 additions & 29 deletions addons/sprite-clone-count/userscript.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
export default async function ({ addon, console }) {
const vm = addon.tab.traps.vm;
const OGfunction = vm.runtime.changeCloneCounter;
const ogCloneCounter = vm.runtime.changeCloneCounter;

vm.runtime.changeCloneCounter = (e) => {
OGfunction.call(vm.runtime, e);

setTimeout(() => {
let counts = {};
function updateCounts() {
let counts = {};

vm.runtime.targets
.filter((target) => !target.isOriginal)
.map((target) => target.sprite.name)
.forEach((target) => {
if (!counts[target]) counts[target] = 1;
else counts[target] += 1;
});

console.log(counts);
vm.runtime.targets
.filter((target) => !target.isOriginal)
.map((target) => target.sprite.name)
.forEach((target) => {
if (!counts[target]) counts[target] = 1;
else counts[target] += 1;
});

const spriteNames = Array.from(
document
.querySelector("[class*=sprite-selector_items-wrapper]")
.querySelectorAll("[class*=sprite-selector-item_sprite-name]")
);
const spriteNames = Array.from(
document
.querySelector("[class*=sprite-selector_items-wrapper]")
.querySelectorAll("[class*=sprite-selector-item_sprite-name]")
);

console.log(spriteNames);
spriteNames.forEach((spriteName) => {
spriteName.querySelector(".clone-count")?.remove();
if (counts[spriteName.innerText.split("\n")[0]] !== undefined) {
const count = document.createElement("div");

spriteNames.forEach((spriteName) => {
if (counts[spriteName.innerText.split("\n")[0]]) {
spriteName.querySelector("div")?.remove();
count.classList.add("clone-count");
count.innerText = `(${counts[spriteName.innerText.split("\n")[0]]} clones)`;
spriteName.appendChild(count);
}
});
}

const count = document.createElement("div");
vm.runtime.changeCloneCounter = (e) => {
ogCloneCounter.call(vm.runtime, e);

count.innerText = `(${counts[spriteName.innerText.split("\n")[0]]} clones)`;
spriteName.appendChild(count);
}
});
setTimeout(() => {
updateCounts();
}, 100);
};

vm.addListener("targetsUpdate", () => {
setTimeout(() => {
updateCounts();
}, 0);
});
}

0 comments on commit 9b1afad

Please sign in to comment.