Skip to content

Commit

Permalink
Merge branch 'develop' into greenkeeper/tap-11.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
thisandagain committed Jan 19, 2018
2 parents 2343e04 + 90e9e1c commit a9dd658
Show file tree
Hide file tree
Showing 18 changed files with 491 additions and 118 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"socket.io-client": "2.0.4",
"stats.js": "^0.17.0",
"tap": "^11.0.1",
"text-encoding": "0.6.4",
"tiny-worker": "^2.1.1",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.4.1",
Expand Down
51 changes: 31 additions & 20 deletions src/blocks/scratch3_looks.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,19 @@ 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,
looks_backdropname: this.getBackdropName
looks_costumenumbername: this.getCostumeNumberName,
looks_backdropnumbername: this.getBackdropNumberName
};
}

getMonitored () {
return {
looks_size: {isSpriteSpecific: true},
looks_costumeorder: {isSpriteSpecific: true},
looks_backdroporder: {},
looks_backdropname: {}
looks_costumenumbername: {isSpriteSpecific: true},
looks_backdropnumbername: {}
};
}

Expand Down Expand Up @@ -409,32 +407,45 @@ 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) {
return Math.round(util.target.size);
}

getBackdropIndex () {
const stage = this.runtime.getTargetForStage();
return stage.currentCostume + 1;
}

getBackdropName () {
getBackdropNumberName (args) {
const stage = this.runtime.getTargetForStage();
if (args.NUMBER_NAME === 'number') {
return stage.currentCostume + 1;
}
// Else return name
return stage.sprite.costumes[stage.currentCostume].name;
}

getCostumeIndex (args, util) {
return util.target.currentCostume + 1;
getCostumeNumberName (args, util) {
if (args.NUMBER_NAME === 'number') {
return util.target.currentCostume + 1;
}
// Else return name
return util.target.sprite.costumes[util.target.currentCostume].name;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/blocks/scratch3_motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class Scratch3MotionBlocks {
let targetX = 0;
let targetY = 0;
if (targetName === '_mouse_') {
targetX = util.ioQuery('mouse', 'getX');
targetY = util.ioQuery('mouse', 'getY');
targetX = util.ioQuery('mouse', 'getScratchX');
targetY = util.ioQuery('mouse', 'getScratchY');
} else if (targetName === '_random_') {
const stageWidth = this.runtime.constructor.STAGE_WIDTH;
const stageHeight = this.runtime.constructor.STAGE_HEIGHT;
Expand Down Expand Up @@ -106,8 +106,8 @@ class Scratch3MotionBlocks {
let targetX = 0;
let targetY = 0;
if (args.TOWARDS === '_mouse_') {
targetX = util.ioQuery('mouse', 'getX');
targetY = util.ioQuery('mouse', 'getY');
targetX = util.ioQuery('mouse', 'getScratchX');
targetY = util.ioQuery('mouse', 'getScratchY');
} else {
const pointTarget = this.runtime.getSpriteTargetByName(args.TOWARDS);
if (!pointTarget) return;
Expand Down Expand Up @@ -155,7 +155,7 @@ class Scratch3MotionBlocks {
util.yield();
}
}

glideTo (args, util) {
const targetXY = this.getTargetXY(args.TO, util);
if (targetXY) {
Expand Down
18 changes: 11 additions & 7 deletions src/blocks/scratch3_sensing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -55,7 +56,6 @@ class Scratch3SensingBlocks {
sensing_answer: {},
sensing_loudness: {},
sensing_timer: {},
sensing_of: {},
sensing_current: {}
};
}
Expand Down Expand Up @@ -119,8 +119,8 @@ class Scratch3SensingBlocks {
touchingObject (args, util) {
const requestedObject = args.TOUCHINGOBJECTMENU;
if (requestedObject === '_mouse_') {
const mouseX = util.ioQuery('mouse', 'getX');
const mouseY = util.ioQuery('mouse', 'getY');
const mouseX = util.ioQuery('mouse', 'getClientX');
const mouseY = util.ioQuery('mouse', 'getClientY');
return util.target.isTouchingPoint(mouseX, mouseY);
} else if (requestedObject === '_edge_') {
return util.target.isTouchingEdge();
Expand All @@ -146,8 +146,8 @@ class Scratch3SensingBlocks {
let targetX = 0;
let targetY = 0;
if (args.DISTANCETOMENU === '_mouse_') {
targetX = util.ioQuery('mouse', 'getX');
targetY = util.ioQuery('mouse', 'getY');
targetX = util.ioQuery('mouse', 'getScratchX');
targetY = util.ioQuery('mouse', 'getScratchY');
} else {
const distTarget = this.runtime.getSpriteTargetByName(
args.DISTANCETOMENU
Expand All @@ -162,6 +162,10 @@ class Scratch3SensingBlocks {
return Math.sqrt((dx * dx) + (dy * dy));
}

setDragMode (args, util) {
util.target.setDraggable(args.DRAG_MODE === 'draggable');
}

getTimer (args, util) {
return util.ioQuery('clock', 'projectTimer');
}
Expand All @@ -171,11 +175,11 @@ class Scratch3SensingBlocks {
}

getMouseX (args, util) {
return util.ioQuery('mouse', 'getX');
return util.ioQuery('mouse', 'getScratchX');
}

getMouseY (args, util) {
return util.ioQuery('mouse', 'getY');
return util.ioQuery('mouse', 'getScratchY');
}

getMouseDown (args, util) {
Expand Down
32 changes: 25 additions & 7 deletions src/engine/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const mutationAdapter = require('./mutation-adapter');
const xmlEscape = require('../util/xml-escape');
const MonitorRecord = require('./monitor-record');
const Clone = require('../util/clone');
const {Map} = require('immutable');

/**
* @fileoverview
Expand Down Expand Up @@ -382,22 +383,38 @@ class Blocks {
block.fields[args.name].id = args.value;
}
} else {
// Changing the value in a dropdown
block.fields[args.name].value = args.value;

if (!optRuntime){
break;
}

const flyoutBlock = block.shadow && block.parent ? this._blocks[block.parent] : block;
if (flyoutBlock.isMonitored) {
optRuntime.requestUpdateMonitor(Map({
id: flyoutBlock.id,
params: this._getBlockParams(flyoutBlock)
}));
}
}
break;
case 'mutation':
block.mutation = mutationAdapter(args.value);
break;
case 'checkbox':
case 'checkbox': {
block.isMonitored = args.value;
if (optRuntime) {
const isSpriteSpecific = optRuntime.monitorBlockInfo.hasOwnProperty(block.opcode) &&
optRuntime.monitorBlockInfo[block.opcode].isSpriteSpecific;
block.targetId = isSpriteSpecific ? optRuntime.getEditingTarget().id : null;
if (!optRuntime) {
break;
}
if (optRuntime && wasMonitored && !block.isMonitored) {

const isSpriteSpecific = optRuntime.monitorBlockInfo.hasOwnProperty(block.opcode) &&
optRuntime.monitorBlockInfo[block.opcode].isSpriteSpecific;
block.targetId = isSpriteSpecific ? optRuntime.getEditingTarget().id : null;

if (wasMonitored && !block.isMonitored) {
optRuntime.requestRemoveMonitor(block.id);
} else if (optRuntime && !wasMonitored && block.isMonitored) {
} else if (!wasMonitored && block.isMonitored) {
optRuntime.requestAddMonitor(MonitorRecord({
// @todo(vm#564) this will collide if multiple sprites use same block
id: block.id,
Expand All @@ -411,6 +428,7 @@ class Blocks {
}
break;
}
}

this.resetCache();
}
Expand Down
26 changes: 25 additions & 1 deletion src/engine/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const BlockUtility = require('./block-utility');
const log = require('../util/log');
const Thread = require('./thread');
const {Map} = require('immutable');
const cast = require('../util/cast');

/**
* Single BlockUtility instance reused by execute for every pritimive ran.
Expand Down Expand Up @@ -211,7 +212,30 @@ const execute = function (sequencer, thread) {
currentStackFrame.waitingReporter = null;
thread.popStack();
}
argValues[inputName] = currentStackFrame.reported[inputName];
const inputValue = currentStackFrame.reported[inputName];
if (inputName === 'BROADCAST_INPUT') {
const broadcastInput = inputs[inputName];
// Check if something is plugged into the broadcast block, or
// if the shadow dropdown menu is being used.
if (broadcastInput.block === broadcastInput.shadow) {
// Shadow dropdown menu is being used.
// Get the appropriate information out of it.
const shadow = blockContainer.getBlock(broadcastInput.shadow);
const broadcastField = shadow.fields.BROADCAST_OPTION;
argValues.BROADCAST_OPTION = {
id: broadcastField.id,
name: broadcastField.value
};
} else {
// Something is plugged into the broadcast input.
// Cast it to a string. We don't need an id here.
argValues.BROADCAST_OPTION = {
name: cast.toString(inputValue)
};
}
} else {
argValues[inputName] = inputValue;
}
}

// Add any mutation to args (e.g., for procedures).
Expand Down
32 changes: 28 additions & 4 deletions src/engine/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,19 @@ class Target extends EventEmitter {
* if it exists.
* @param {string} id Id of the variable.
* @param {string} name Name of the variable.
* @return {!Variable} Variable object.
* @return {?Variable} Variable object.
*/
lookupBroadcastMsg (id, name) {
const broadcastMsg = this.lookupVariableById(id);
let broadcastMsg;
if (id) {
broadcastMsg = this.lookupVariableById(id);
} else if (name) {
broadcastMsg = this.lookupBroadcastByInputValue(name);
} else {
log.error('Cannot find broadcast message if neither id nor name are provided.');
}
if (broadcastMsg) {
if (broadcastMsg.name !== name) {
if (name && (broadcastMsg.name.toLowerCase() !== name.toLowerCase())) {
log.error(`Found broadcast message with id: ${id}, but` +
`its name, ${broadcastMsg.name} did not match expected name ${name}.`);
}
Expand All @@ -115,6 +122,23 @@ class Target extends EventEmitter {
}
}

/**
* Look up a broadcast message with the given name and return the variable
* if it exists. Does not create a new broadcast message variable if
* it doesn't exist.
* @param {string} name Name of the variable.
* @return {?Variable} Variable object.
*/
lookupBroadcastByInputValue (name) {
const vars = this.variables;
for (const propName in vars) {
if ((vars[propName].type === Variable.BROADCAST_MESSAGE_TYPE) &&
(vars[propName].name.toLowerCase() === name.toLowerCase())) {
return vars[propName];
}
}
}

/**
* Look up a variable object.
* Search begins for local variables; then look for globals.
Expand All @@ -141,7 +165,7 @@ class Target extends EventEmitter {
* Search begins for local lists; then look for globals.
* @param {!string} id Id of the list.
* @param {!string} name Name of the list.
* @return {!List} List object.
* @return {!Varible} Variable object representing the found/created list.
*/
lookupOrCreateList (id, name) {
const list = this.lookupVariableById(id);
Expand Down

0 comments on commit a9dd658

Please sign in to comment.