Merge pull request #880 from paulkaplan/layering-blocks

New layering blocks
This commit is contained in:
Paul Kaplan 2017-12-29 09:34:40 -05:00 committed by GitHub
commit c2cfe9a083
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 78 additions and 12 deletions

View file

@ -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) {

View file

@ -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');
}

View file

@ -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',

View file

@ -345,12 +345,12 @@ const specMap = {
]
},
'comeToFront': {
opcode: 'looks_gotofront',
opcode: 'looks_gotofrontback',
argMap: [
]
},
'goBackByLayers:': {
opcode: 'looks_gobacklayers',
opcode: 'looks_goforwardbackwardlayers',
argMap: [
{
type: 'input',

View file

@ -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);
}

View file

@ -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();
});

View file

@ -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);