From df5fa3773c53e215c0c26634422eb5d11f70c6e6 Mon Sep 17 00:00:00 2001
From: yuri-kiss <135030944+yuri-kiss@users.noreply.github.com>
Date: Fri, 2 May 2025 10:13:30 -0400
Subject: [PATCH 1/2] add 2 things and use switch case
---
extensions/NexusKitten/moremotion.js | 63 +++++++++++++++++++++-------
1 file changed, 48 insertions(+), 15 deletions(-)
diff --git a/extensions/NexusKitten/moremotion.js b/extensions/NexusKitten/moremotion.js
index f7c76c1464..52263eede0 100644
--- a/extensions/NexusKitten/moremotion.js
+++ b/extensions/NexusKitten/moremotion.js
@@ -2,6 +2,7 @@
// ID: nkmoremotion
// Description: More motion-related blocks.
// By: NamelessCat
+// By: Mio
// License: MIT
(function (Scratch) {
@@ -86,6 +87,27 @@
}),
extensions: ["colours_motion"],
},
+ {
+ filter: [Scratch.TargetType.SPRITE],
+ opcode: "fenceXY",
+ blockType: Scratch.BlockType.REPORTER,
+ text: Scratch.translate({
+ default: "manually fence new x: [X] new y: [Y]",
+ description:
+ "Fences a specific new X and new Y for the sprite.",
+ }),
+ arguments: {
+ X: {
+ type: Scratch.ArgumentType.NUMBER,
+ defaultValue: "0",
+ },
+ Y: {
+ type: Scratch.ArgumentType.NUMBER,
+ defaultValue: "0",
+ },
+ },
+ extensions: ["colours_motion"],
+ },
"---",
{
filter: [Scratch.TargetType.SPRITE],
@@ -255,6 +277,10 @@
text: Scratch.translate("height"),
value: "height",
},
+ {
+ text: Scratch.translate("bounds"),
+ value: "bounds",
+ },
{
text: Scratch.translate("costume width"),
value: "costume width",
@@ -294,6 +320,12 @@
);
util.target.setXY(newpos[0], newpos[1]);
}
+ fenceXY(args, util) {
+ return JSON.stringify(util.target.keepInFence(
+ Scratch.Cast.toNumber(args.X),
+ Scratch.Cast.toNumber(args.Y)
+ ));
+ }
directionto(args, util) {
// Old version, returns values from -90 to 270
@@ -425,23 +457,24 @@
}
spritewh(args, util) {
- if (args.WHAT === "width" || args.WHAT === "height") {
- const bounds = Scratch.vm.renderer.getBounds(util.target.drawableID);
- if (args.WHAT === "width") {
+ if (args.WHAT.startsWith("costume ")) {
+ const [w, h] = util.target.sprite.costumes[util.target.currentCostume].size;
+ if (args.WHAT.endsWith("width")) return Math.ceil(w);
+ if (args.WHAT.endsWith("height")) return Math.ceil(h);
+ return 0;
+ }
+ // Bounds may not always exist so default to a similar 0 valued object
+ const bounds = Scratch.vm.renderer.getBounds(util.target.drawableID) ?? {left: 0, right: 0, top: 0, bottom: 0, width: 0, height: 0};
+ switch(args.WHAT) {
+ case "bounds":
+ // Useful for more precision or just getting the edges
+ return JSON.stringify(Object.assign({ width: bounds.width, height: bounds.height }, bounds));
+ case "width":
return Math.ceil(bounds.width);
- } else {
+ case "height":
return Math.ceil(bounds.height);
- }
- } else if (
- args.WHAT === "costume width" ||
- args.WHAT === "costume height"
- ) {
- const costume = util.target.sprite.costumes[util.target.currentCostume];
- if (args.WHAT === "costume width") {
- return Math.ceil(costume.size[0]);
- } else {
- return Math.ceil(costume.size[1]);
- }
+ default:
+ return 0;
}
}
}
From c1636122c6b57ea4a7adb8a89ab852ab8edda94d Mon Sep 17 00:00:00 2001
From: "DangoCat[bot]"
Date: Fri, 2 May 2025 14:17:01 +0000
Subject: [PATCH 2/2] [Automated] Format code
---
extensions/NexusKitten/moremotion.js | 34 ++++++++++++++++++++--------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/extensions/NexusKitten/moremotion.js b/extensions/NexusKitten/moremotion.js
index 52263eede0..de296eca43 100644
--- a/extensions/NexusKitten/moremotion.js
+++ b/extensions/NexusKitten/moremotion.js
@@ -93,8 +93,7 @@
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate({
default: "manually fence new x: [X] new y: [Y]",
- description:
- "Fences a specific new X and new Y for the sprite.",
+ description: "Fences a specific new X and new Y for the sprite.",
}),
arguments: {
X: {
@@ -321,10 +320,12 @@
util.target.setXY(newpos[0], newpos[1]);
}
fenceXY(args, util) {
- return JSON.stringify(util.target.keepInFence(
- Scratch.Cast.toNumber(args.X),
- Scratch.Cast.toNumber(args.Y)
- ));
+ return JSON.stringify(
+ util.target.keepInFence(
+ Scratch.Cast.toNumber(args.X),
+ Scratch.Cast.toNumber(args.Y)
+ )
+ );
}
directionto(args, util) {
@@ -458,17 +459,30 @@
spritewh(args, util) {
if (args.WHAT.startsWith("costume ")) {
- const [w, h] = util.target.sprite.costumes[util.target.currentCostume].size;
+ const [w, h] =
+ util.target.sprite.costumes[util.target.currentCostume].size;
if (args.WHAT.endsWith("width")) return Math.ceil(w);
if (args.WHAT.endsWith("height")) return Math.ceil(h);
return 0;
}
// Bounds may not always exist so default to a similar 0 valued object
- const bounds = Scratch.vm.renderer.getBounds(util.target.drawableID) ?? {left: 0, right: 0, top: 0, bottom: 0, width: 0, height: 0};
- switch(args.WHAT) {
+ const bounds = Scratch.vm.renderer.getBounds(util.target.drawableID) ?? {
+ left: 0,
+ right: 0,
+ top: 0,
+ bottom: 0,
+ width: 0,
+ height: 0,
+ };
+ switch (args.WHAT) {
case "bounds":
// Useful for more precision or just getting the edges
- return JSON.stringify(Object.assign({ width: bounds.width, height: bounds.height }, bounds));
+ return JSON.stringify(
+ Object.assign(
+ { width: bounds.width, height: bounds.height },
+ bounds
+ )
+ );
case "width":
return Math.ceil(bounds.width);
case "height":