Skip to content

Commit

Permalink
Addon.json update and dont delete and remove all the time
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazza-231 committed Jun 18, 2024
1 parent 5339129 commit c9711ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion addons/clones/addon.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Clone counter",
"description": "Adds a counter above the stage in the editor which shows the total amount of clones.",
"description": "Adds a counter above the stage in the editor which shows the total amount of clones. There is also an option to add a counter to individual sprites.",
"credits": [
{
"name": "Jeffalo"
Expand Down
30 changes: 19 additions & 11 deletions addons/clones/spriteCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default async function ({ addon, console }) {
const vm = addon.tab.traps.vm;
const ogCloneCounter = vm.runtime.changeCloneCounter;

function updateCounts(remove) {
async function updateCounts(remove) {
let counts = {};

vm.runtime.targets
Expand All @@ -13,20 +13,28 @@ export default async function ({ addon, console }) {
else counts[target] += 1;
});

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

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

if (remove) {
existingElement?.remove();
return;
}

if (existingElement) {
count = existingElement;
} else {
count = document.createElement("div");
count.classList.add("sa-clone-count");
spriteName.appendChild(count);
}

count.classList.add("clone-count");
count.innerText = `(${counts[spriteName.innerText.split("\n")[0]]} clones)`;
spriteName.appendChild(count);
}
});
}
Expand Down

0 comments on commit c9711ac

Please sign in to comment.