Skip to content

Commit

Permalink
sprite clone count start
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazza-231 committed Jun 4, 2024
1 parent dbaf7c1 commit 7be60ae
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/addons.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"paint-skew",
"preview-project-description",
"collapse-footer",
"sprite-clone-count",

"// NEW ADDONS ABOVE THIS ↑↑",
"// Note: these themes need this exact order to work properly,",
Expand Down
21 changes: 21 additions & 0 deletions addons/sprite-clone-count/addon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Sprite clone count",
"description": "Adds a clone count to indivudal sprites.",
"credits": [
{
"name": "Jazza",
"link": "http://scratch.mit.edu/users/greeny--231"
}
],
"userscripts": [
{
"url": "userscript.js",
"matches": ["projects"]
}
],
"versionAdded": "1.35.0",
"tags": ["projects", "featured"],
"enabledByDefault": false,
"dynamicEnable": true,
"dynamicDisable": true
}
41 changes: 41 additions & 0 deletions addons/sprite-clone-count/userscript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export default async function ({ addon, console }) {
const vm = addon.tab.traps.vm;
const OGfunction = vm.runtime.changeCloneCounter;

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

setTimeout(() => {
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);

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

console.log(spriteNames);

spriteNames.forEach((spriteName) => {
if (counts[spriteName.innerText.split("\n")[0]]) {
spriteName.querySelector("div")?.remove();

const count = document.createElement("div");

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

0 comments on commit 7be60ae

Please sign in to comment.