diff --git a/features/features.json b/features/features.json index cb1a0966..3d9e01bb 100644 --- a/features/features.json +++ b/features/features.json @@ -1,4 +1,9 @@ [ + { + "version": 2, + "id": "snap-to-grid", + "versionAdded": "v4.0.0" + }, { "version": 2, "id": "select-self", diff --git a/features/snap-to-grid/data.json b/features/snap-to-grid/data.json new file mode 100644 index 00000000..d31111bd --- /dev/null +++ b/features/snap-to-grid/data.json @@ -0,0 +1,22 @@ +{ + "title": "Snap Scripts to Grid", + "description": "Automatically aligns scripts to the dotted grid in the editor when placed.", + "credits": [ + { + "username": "rgantzos", + "url": "https://scratch.mit.edu/users/rgantzos/" + } + ], + "type": [ + "Editor" + ], + "tags": [ + "New" + ], + "scripts": [ + { + "file": "script.js", + "runOn": "/projects/*" + } + ] +} \ No newline at end of file diff --git a/features/snap-to-grid/script.js b/features/snap-to-grid/script.js new file mode 100644 index 00000000..21816eec --- /dev/null +++ b/features/snap-to-grid/script.js @@ -0,0 +1,12 @@ +export default async function ({ feature, console }) { + await ScratchTools.waitForElement("div.gui") + update() + + feature.traps.vm.on("workspaceUpdate", function() { + update() + }) + + function update() { + Blockly.getMainWorkspace().grid_.snapToGrid_ = feature.self.enabled + } +} \ No newline at end of file