From f829017d620f55a3c100097ac98f1aa036b42224 Mon Sep 17 00:00:00 2001 From: ilikecoding-197 <64pigpig2014@gmail.com> Date: Fri, 6 Feb 2026 19:09:39 -0500 Subject: [PATCH] this took forever but now the scratch blocks are integrated!! --- split.html | 2 +- src/byob.js | 3 + src/gui.js | 149 ++++------------------------------------- src/objects.js | 123 +++++++++++++++++++++++----------- src/scratch_blocks.xml | 2 +- src/store.js | 6 +- 6 files changed, 108 insertions(+), 177 deletions(-) diff --git a/split.html b/split.html index 14d2c66e11..cef089f92e 100644 --- a/split.html +++ b/split.html @@ -58,7 +58,7 @@ }; if ('serviceWorker' in navigator) { - navigator.serviceWorker.register('sw.js'); + //navigator.serviceWorker.register('sw.js'); } world = new WorldMorph(document.getElementById('world')); // store the ide in a varibale so we can change the palette mode later diff --git a/src/byob.js b/src/byob.js index 8ad481b077..522d715765 100644 --- a/src/byob.js +++ b/src/byob.js @@ -184,6 +184,9 @@ function CustomBlockDefinition(spec, receiver) { // transient - for "wishes" this.storedSemanticSpec = null; + + // for scratch blocks - null otherwise + this.scratchBlockID = null; } // CustomBlockDefinition instantiating blocks diff --git a/src/gui.js b/src/gui.js index 914820e102..6bd2e45606 100644 --- a/src/gui.js +++ b/src/gui.js @@ -263,137 +263,6 @@ IDE_Morph.prototype.scriptsTexture = function () { IDE_Morph.prototype.setDefaultTheme(); IDE_Morph.prototype.setFlatDesign(); -// Scratch blocks XML -// Doesn't contain all blocks yet, original in "scratch_blocks.xml" -// in src (this directory), for editing -// "Why"? Because you can't load file text on a local webpage, -// and that's how I test. However, it might be better for me to test on a locsl -// HTTP server... Eh. This is how I do it - codingisfun2831t - -// Q: by the way... did you put the + manually? - d016 -// A: yes, that is how I did it. not that hard, just copy `` +\n\t`` -// (\n = newline, \t = tab (two spaces, for your atleast) and paste -// that every 80 characters or so - codingisfun2831t - -IDE_Morph.prototype.scratchBlocksXml = - `
$_all aro` + - `und$_all around $_left-right $_don't rotate<` + - `/input>left-rightdon't rotate
1$_random position§` + - `_destinationsMenu
` + - `§_dynamicMenu<` + - `/options>prev` + - `ious backdrop<` + - `l>random backdroptrueStage` + - `nameEmpty&` + - `#126;Stagenext backdropprevious ba` + - `ckdroprandom backdrop
namenu` + - `mber name
namenumber namelast
§_dynamicMenu
draggabledraggable not drag` + - `gable
`; - // IDE_Morph instance creation: function IDE_Morph() { @@ -5125,12 +4994,22 @@ IDE_Morph.prototype.projectMenu = function () { "file menu import hint", // looks up the actual text in the translator ); - menu.addItem( + menu.addItem( "Import Scratch Blocks", - () => - this.rawOpenBlocksString(this.scratchBlocksXml, "Scratch Blocks", true), + () => fetch("src/scratch_blocks.xml") + .then(res => { + if (!res.ok) throw new Error("HTTP error"); + return res.text(); + }) + .then(str => { + this.rawOpenBlocksString(str, "Scratch Blocks", true); + this.refreshIDE(); + }) + .catch(() => { + this.showMessage("Failed to fetch scratch blocks"); + }), "import the library containing replications\n" + - "of scratch blocks for Split!", + "of scratch blocks for Split!" ); menu.addItem( "Export project...", diff --git a/src/objects.js b/src/objects.js index 7d68035f6d..4cb019768c 100644 --- a/src/objects.js +++ b/src/objects.js @@ -789,15 +789,6 @@ SpriteMorph.prototype.primitiveBlocks = function () { animation: true, code: "back", }, - goBackNew: { - only: SpriteMorph, - type: "command", - category: "looks", - spec: "go %layers %n layers", - defaults: [["back"], 1], - animation: true, - code: "back", - }, // Looks - Debugging primitives for development mode doScreenshot: { @@ -3889,7 +3880,8 @@ SpriteMorph.prototype.blockTemplates = function ( varNames, inheritedVars = this.inheritedVariableNames(), wrld = this.world(), - devMode = wrld && wrld.isDevMode; + devMode = wrld && wrld.isDevMode, + stage = this.parentThatIsA(StageMorph) function block(selector, isGhosted) { if (StageMorph.prototype.hiddenPrimitives[selector] && !all) { @@ -3904,6 +3896,26 @@ SpriteMorph.prototype.blockTemplates = function ( return newBlock; } + + function hasScratchBlock(id) { + if (!stage) return false; + + var found = false; + stage.globalBlocks.forEach((def) => { + if (def.scratchBlockID === id) found = true; + }); + + return found; + } + + + function scratchBlock(id) { + if (!stage) return; + stage.globalBlocks.forEach((def) => { + if (def.scratchBlockID === id) blocks.push(def.templateInstance()); + }); + } + function variableBlock(varName, isLocal) { var newBlock = SpriteMorph.prototype.variableBlock(varName, isLocal); newBlock.isDraggable = false; @@ -3976,8 +3988,8 @@ SpriteMorph.prototype.blockTemplates = function ( blocks.push("-"); blocks.push(block("doGotoObject")); blocks.push(block("gotoXY")); + scratchBlock("glideToObject"); blocks.push(block("doGlide")); - //blocks.push(block('doGlideSprite')); blocks.push("-"); blocks.push(block("setHeading")); blocks.push(block("doFaceTowards")); @@ -3989,6 +4001,8 @@ SpriteMorph.prototype.blockTemplates = function ( blocks.push("-"); blocks.push(block("bounceOffEdge")); blocks.push("-"); + scratchBlock("rotationStyle"); + blocks.push("-"); blocks.push(block("getPosition")); blocks.push(watcherToggle("xPosition")); blocks.push(block("xPosition", this.inheritsAttribute("x position"))); @@ -4004,8 +4018,12 @@ SpriteMorph.prototype.blockTemplates = function ( blocks.push("-"); blocks.push(block("doSwitchToCostume")); blocks.push(block("doWearNextCostume")); - blocks.push(watcherToggle("getCostumeIdx")); - blocks.push(block("getCostumeIdx", this.inheritsAttribute("costume #"))); + scratchBlock("switchBackdrop"); + scratchBlock("nextBackdrop"); + if (!hasScratchBlock("costumeProp")) { + blocks.push(watcherToggle("getCostumeIdx")); + blocks.push(block("getCostumeIdx", this.inheritsAttribute("costume #"))); + } blocks.push("-"); blocks.push(block("changeScale")); blocks.push(block("setScale")); @@ -4023,7 +4041,12 @@ SpriteMorph.prototype.blockTemplates = function ( blocks.push(block("reportShown", this.inheritsAttribute("shown?"))); blocks.push("-"); blocks.push(block("goToLayer")); - blocks.push(block("goBackNew")); + if (!hasScratchBlock("goBackNew")) { + blocks.push(block("goBack")); + } + scratchBlock("goBackNew"); + scratchBlock("costumeProp"); + scratchBlock("backdropProp"); blocks.push("-"); blocks.push(block("reportNewCostume")); blocks.push(block("reportGetImageAttribute")); @@ -4111,6 +4134,7 @@ SpriteMorph.prototype.blockTemplates = function ( blocks.push(block("receiveKey")); blocks.push(block("receiveInteraction")); blocks.push(block("receiveConditionEvent")); + scratchBlock("backdropSwitch"); blocks.push("-"); blocks.push(block("receiveMessage")); blocks.push(block("doBroadcast")); @@ -4198,6 +4222,8 @@ SpriteMorph.prototype.blockTemplates = function ( blocks.push(block("reportMouseY")); blocks.push(block("reportMousePosition")); blocks.push("-"); + scratchBlock("dragMode"); + blocks.push("-"); blocks.push(watcherToggle("getTimer")); blocks.push(block("getTimer")); blocks.push(block("doResetTimer")); @@ -4256,6 +4282,7 @@ SpriteMorph.prototype.blockTemplates = function ( blocks.push(block("reportJoinWords")); blocks.push(block("reportLetter")); blocks.push(block("reportTextAttribute")); + scratchBlock("contains"); blocks.push(block("reportTextSplit")); blocks.push("-"); blocks.push(block("reportModulus")); @@ -4513,6 +4540,8 @@ SpriteMorph.prototype.customBlockTemplatesForCategory = function ( inheritedBlocks; function addCustomBlock(definition) { + if (definition.scratchBlockID) return; + if ( (!definition.isHelper || includeHidden) && (definition.category === category) @@ -6865,24 +6894,6 @@ SpriteMorph.prototype.goBack = function (layers) { this.parent.children.splice(targetLayer, null, this); this.parent.changed(); }; -SpriteMorph.prototype.goBackNew = function (l, layers) { - var layer, - newLayer = +layers, - targetLayer; - if (Process.prototype.inputOption(l) == "forward") { - newLayer *= -1; - } else if (Process.prototype.inputOption(l) != "forward") { - return; - } - if (!this.parent) { - return null; - } - layer = this.parent.children.indexOf(this); - this.parent.removeChild(this); - targetLayer = Math.max(layer - newLayer, 0); - this.parent.children.splice(targetLayer, null, this); - this.parent.changed(); -}; // SpriteMorph collision detection @@ -11525,7 +11536,8 @@ StageMorph.prototype.blockTemplates = function ( var blocks = [], myself = this, varNames, - txt; + txt, + stage = this.parentThatIsA(StageMorph) function block(selector) { if (myself.hiddenPrimitives[selector] && !all) { @@ -11537,6 +11549,24 @@ StageMorph.prototype.blockTemplates = function ( return newBlock; } + function hasScratchBlock(id) { + if (!stage) return false; + + var found = false; + stage.globalBlocks.forEach((def) => { + if (def.scratchBlockID === id) found = true; + }); + + return found; + } + + function scratchBlock(id) { + if (!stage) return; + stage.globalBlocks.forEach((def) => { + if (def.scratchBlockID === id) blocks.push(def.templateInstance()); + }); + } + function variableBlock(varName, isLocal) { var newBlock = SpriteMorph.prototype.variableBlock(varName, isLocal); newBlock.isDraggable = false; @@ -11605,10 +11635,21 @@ StageMorph.prototype.blockTemplates = function ( txt.hideWithCategory = true; // hide txt when category names are hidden blocks.push(txt); } else if (category === "looks") { - blocks.push(block("doSwitchToCostume")); - blocks.push(block("doWearNextCostume")); - blocks.push(watcherToggle("getCostumeIdx")); - blocks.push(block("getCostumeIdx")); + if (!hasScratchBlock("switchBackdrop")) { + blocks.push(block("doSwitchToCostume")); + } + scratchBlock("switchBackdrop"); + + if (!hasScratchBlock("nextBackdrop")) { + blocks.push(block("doWearNextCostume")); + } + scratchBlock("nextBackdrop"); + + if (!hasScratchBlock("backdropProp")) { + blocks.push(watcherToggle("getCostumeIdx")); + blocks.push(block("getCostumeIdx")); + } + blocks.push("-"); blocks.push(block("doSayFor")); blocks.push(block("bubble")); @@ -11622,6 +11663,8 @@ StageMorph.prototype.blockTemplates = function ( blocks.push(block("setEffect")); blocks.push(block("clearEffects")); blocks.push(block("getEffect")); + if (!hasScratchBlock("backdropProp")) blocks.push("-"); + scratchBlock("backdropProp"); /*blocks.push("-"); blocks.push(block("show")); blocks.push(block("hide")); @@ -11698,6 +11741,7 @@ StageMorph.prototype.blockTemplates = function ( blocks.push(block("receiveKey")); blocks.push(block("receiveInteraction")); blocks.push(block("receiveConditionEvent")); + scratchBlock("backdropSwitch"); blocks.push("-"); blocks.push(block("receiveMessage")); blocks.push(block("doBroadcast")); @@ -11776,12 +11820,12 @@ StageMorph.prototype.blockTemplates = function ( //blocks.push(block('getLastAnswer')); blocks.push("-"); blocks.push(block("reportMousePosition")); + blocks.push(watcherToggle("reportMouseDown")); + blocks.push(block("reportMouseDown")); blocks.push(watcherToggle("reportMouseX")); blocks.push(block("reportMouseX")); blocks.push(watcherToggle("reportMouseY")); blocks.push(block("reportMouseY")); - blocks.push(watcherToggle("reportMouseDown")); - blocks.push(block("reportMouseDown")); blocks.push("-"); blocks.push(block("reportKeyPressed")); blocks.push("-"); @@ -11854,6 +11898,7 @@ StageMorph.prototype.blockTemplates = function ( blocks.push(block("reportTextSplit")); blocks.push(block("reportLetter")); blocks.push(block("reportTextAttribute")); + scratchBlock("contains"); blocks.push("-"); blocks.push(block("reportUnicode")); blocks.push(block("reportUnicodeAsLetter")); diff --git a/src/scratch_blocks.xml b/src/scratch_blocks.xml index 0192a86c18..127c267ff2 100644 --- a/src/scratch_blocks.xml +++ b/src/scratch_blocks.xml @@ -1 +1 @@ -
$_all around$_all around $_left-right $_don't rotateleft-rightdon't rotate
1$_random position§_destinationsMenu
§_dynamicMenuprevious backdroprandom backdroptrue
namenumber name
namenumber name
last
§_dynamicMenu
draggabledraggable not draggable
\ No newline at end of file +
$_all around$_all around $_left-right $_don't rotateleft-rightdon't rotate
1$_random position§_destinationsMenu
§_dynamicMenuprevious backdroprandom backdroptrue
namenumber name
namenumber name
last
§_dynamicMenu
draggabledraggable not draggable
applea
forwardforward back1
\ No newline at end of file diff --git a/src/store.js b/src/store.js index d06f68ff4a..8e46a4199c 100644 --- a/src/store.js +++ b/src/store.js @@ -1072,6 +1072,7 @@ SnapSerializer.prototype.loadCustomBlocks = function ( definition.isHelper = (child.attributes.helper === 'true') || false; definition.spaceAbove = (child.attributes.space === 'true') || false; definition.semantics = child.attributes.semantics || null; + definition.scratchBlockID = child.attributes.scrblkid || null; definition.isGlobal = (isGlobal === true); if (isDispatch) { object.inheritedMethodsCache.push(definition); @@ -2568,7 +2569,7 @@ CustomBlockDefinition.prototype.toXML = function (serializer) { } return serializer.format( - '' + + '' + '%' + (this.variableNames.length ? '%' : '@') + '
@
' + @@ -2589,6 +2590,9 @@ CustomBlockDefinition.prototype.toXML = function (serializer) { this.spaceAbove ? ' space="true"' : '', this.type === 'hat' && this.semantics === 'rule' ? ' semantics="rule"' : '', + this.scratchBlockID ? + ' scrblkid="' + this.scratchBlockID + '"' + : '', this.comment ? this.comment.toXML(serializer) : '', (this.variableNames.length ? serializer.store(new List(this.variableNames)) : ''),