diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index 1429b6dd7..c694fb38e 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -233,8 +233,8 @@ class Scratch3LooksBlocks { looks_cleargraphiceffects: this.clearEffects, looks_changesizeby: this.changeSize, looks_setsizeto: this.setSize, - looks_gotofront: this.goToFront, - looks_gobacklayers: this.goBackLayers, + looks_gotofrontback: this.goToFrontBack, + looks_goforwardbackwardlayers: this.goForwardBackwardLayers, looks_size: this.getSize, looks_costumeorder: this.getCostumeIndex, looks_backdroporder: this.getBackdropIndex, @@ -409,14 +409,24 @@ class Scratch3LooksBlocks { util.target.setSize(size); } - goToFront (args, util) { + goToFrontBack (args, util) { if (!util.target.isStage) { - util.target.goToFront(); + if (args.FRONT_BACK === 'front') { + util.target.goToFront(); + } else { + util.target.goToBack(); + } } } - goBackLayers (args, util) { - util.target.goBackLayers(args.NUM); + goForwardBackwardLayers (args, util) { + if (!util.target.isStage) { + if (args.FORWARD_BACKWARD === 'forward') { + util.target.goForwardLayers(Cast.toNumber(args.NUM)); + } else { + util.target.goBackwardLayers(Cast.toNumber(args.NUM)); + } + } } getSize (args, util) { diff --git a/src/blocks/scratch3_sensing.js b/src/blocks/scratch3_sensing.js index 75ee571c7..0ee1286eb 100644 --- a/src/blocks/scratch3_sensing.js +++ b/src/blocks/scratch3_sensing.js @@ -40,6 +40,7 @@ class Scratch3SensingBlocks { sensing_of: this.getAttributeOf, sensing_mousex: this.getMouseX, sensing_mousey: this.getMouseY, + sensing_setdragmode: this.setDragMode, sensing_mousedown: this.getMouseDown, sensing_keypressed: this.getKeyPressed, sensing_current: this.current, @@ -162,6 +163,10 @@ class Scratch3SensingBlocks { return Math.sqrt((dx * dx) + (dy * dy)); } + setDragMode (args, util) { + util.target.draggable = args.DRAG_MODE === 'draggable'; + } + getTimer (args, util) { return util.ioQuery('clock', 'projectTimer'); } diff --git a/src/serialization/sb2.js b/src/serialization/sb2.js index 40304ce2d..85f55910a 100644 --- a/src/serialization/sb2.js +++ b/src/serialization/sb2.js @@ -601,6 +601,20 @@ const parseBlock = function (sb2block, addBroadcastMsg, getVariableId, extension } } } + + // Updated layering blocks + if (oldOpcode === 'comeToFront') { + activeBlock.fields.FRONT_BACK = { + name: 'FRONT_BACK', + value: 'front' + }; + } else if (oldOpcode === 'goBackByLayers:') { + activeBlock.fields.FORWARD_BACKWARD = { + name: 'FORWARD_BACKWARD', + value: 'backward' + }; + } + // Special cases to generate mutations. if (oldOpcode === 'stopScripts') { // Mutation for stop block: if the argument is 'other scripts', diff --git a/src/serialization/sb2_specmap.js b/src/serialization/sb2_specmap.js index b829fc174..a8ca43540 100644 --- a/src/serialization/sb2_specmap.js +++ b/src/serialization/sb2_specmap.js @@ -345,12 +345,12 @@ const specMap = { ] }, 'comeToFront': { - opcode: 'looks_gotofront', + opcode: 'looks_gotofrontback', argMap: [ ] }, 'goBackByLayers:': { - opcode: 'looks_gobacklayers', + opcode: 'looks_goforwardbackwardlayers', argMap: [ { type: 'input', diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index c41b967a3..85c1d5365 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -699,10 +699,29 @@ class RenderedTarget extends Target { } /** - * Move back a number of layers. - * @param {number} nLayers How many layers to go back. + * Move to the back layer. */ - goBackLayers (nLayers) { + goToBack () { + if (this.renderer) { + this.renderer.setDrawableOrder(this.drawableID, -Infinity, false, 1); + } + } + + /** + * Move forward a number of layers. + * @param {number} nLayers How many layers to go forward. + */ + goForwardLayers (nLayers) { + if (this.renderer) { + this.renderer.setDrawableOrder(this.drawableID, nLayers, true, 1); + } + } + + /** + * Move backward a number of layers. + * @param {number} nLayers How many layers to go backward. + */ + goBackwardLayers (nLayers) { if (this.renderer) { this.renderer.setDrawableOrder(this.drawableID, -nLayers, true, 1); } diff --git a/test/unit/blocks_sensing.js b/test/unit/blocks_sensing.js index 5c2b927a8..221742b99 100644 --- a/test/unit/blocks_sensing.js +++ b/test/unit/blocks_sensing.js @@ -65,3 +65,17 @@ test('ask and answer with a visible target', t => { s.askAndWait({QUESTION: expectedQuestion}, util); }); + +test('set drag mode', t => { + const rt = new Runtime(); + const s = new Sensing(rt); + const util = {target: {draggable: true}}; + + s.setDragMode({DRAG_MODE: 'not draggable'}, util); + t.strictEqual(util.target.draggable, false); + + s.setDragMode({DRAG_MODE: 'draggable'}, util); + t.strictEqual(util.target.draggable, true); + + t.end(); +}); diff --git a/test/unit/sprites_rendered-target.js b/test/unit/sprites_rendered-target.js index 1592c357f..332a78111 100644 --- a/test/unit/sprites_rendered-target.js +++ b/test/unit/sprites_rendered-target.js @@ -293,8 +293,12 @@ test('layers', t => { a.renderer = renderer; a.goToFront(); t.equals(a.renderer.order, 5); - a.goBackLayers(2); + a.goBackwardLayers(2); t.equals(a.renderer.order, 3); + a.goToBack(); + t.equals(a.renderer.order, 1); + a.goForwardLayers(1); + t.equals(a.renderer.order, 2); o.drawableID = 999; a.goBehindOther(o); t.equals(a.renderer.order, 1);