mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Pass with eslint --fix
Resolved whitespace issues, e.g., space-before-function-paren and key-spacing
This commit is contained in:
parent
36e4683aa8
commit
68ed110b49
21 changed files with 975 additions and 975 deletions
|
@ -1,7 +1,7 @@
|
||||||
var Cast = require('../util/cast');
|
var Cast = require('../util/cast');
|
||||||
var Timer = require('../util/timer');
|
var Timer = require('../util/timer');
|
||||||
|
|
||||||
function Scratch3ControlBlocks(runtime) {
|
function Scratch3ControlBlocks (runtime) {
|
||||||
/**
|
/**
|
||||||
* The runtime instantiating this block package.
|
* The runtime instantiating this block package.
|
||||||
* @type {Runtime}
|
* @type {Runtime}
|
||||||
|
@ -13,7 +13,7 @@ function Scratch3ControlBlocks(runtime) {
|
||||||
* Retrieve the block primitives implemented by this package.
|
* Retrieve the block primitives implemented by this package.
|
||||||
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
||||||
*/
|
*/
|
||||||
Scratch3ControlBlocks.prototype.getPrimitives = function() {
|
Scratch3ControlBlocks.prototype.getPrimitives = function () {
|
||||||
return {
|
return {
|
||||||
'control_repeat': this.repeat,
|
'control_repeat': this.repeat,
|
||||||
'control_repeat_until': this.repeatUntil,
|
'control_repeat_until': this.repeatUntil,
|
||||||
|
@ -36,7 +36,7 @@ Scratch3ControlBlocks.prototype.getHats = function () {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3ControlBlocks.prototype.repeat = function(args, util) {
|
Scratch3ControlBlocks.prototype.repeat = function (args, util) {
|
||||||
var times = Math.floor(Cast.toNumber(args.TIMES));
|
var times = Math.floor(Cast.toNumber(args.TIMES));
|
||||||
// Initialize loop
|
// Initialize loop
|
||||||
if (util.stackFrame.loopCounter === undefined) {
|
if (util.stackFrame.loopCounter === undefined) {
|
||||||
|
@ -53,7 +53,7 @@ Scratch3ControlBlocks.prototype.repeat = function(args, util) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3ControlBlocks.prototype.repeatUntil = function(args, util) {
|
Scratch3ControlBlocks.prototype.repeatUntil = function (args, util) {
|
||||||
var condition = Cast.toBoolean(args.CONDITION);
|
var condition = Cast.toBoolean(args.CONDITION);
|
||||||
// If the condition is true, start the branch.
|
// If the condition is true, start the branch.
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
|
@ -61,18 +61,18 @@ Scratch3ControlBlocks.prototype.repeatUntil = function(args, util) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3ControlBlocks.prototype.waitUntil = function(args, util) {
|
Scratch3ControlBlocks.prototype.waitUntil = function (args, util) {
|
||||||
var condition = Cast.toBoolean(args.CONDITION);
|
var condition = Cast.toBoolean(args.CONDITION);
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
util.yield();
|
util.yield();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3ControlBlocks.prototype.forever = function(args, util) {
|
Scratch3ControlBlocks.prototype.forever = function (args, util) {
|
||||||
util.startBranch(1, true);
|
util.startBranch(1, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3ControlBlocks.prototype.wait = function(args, util) {
|
Scratch3ControlBlocks.prototype.wait = function (args, util) {
|
||||||
if (!util.stackFrame.timer) {
|
if (!util.stackFrame.timer) {
|
||||||
util.stackFrame.timer = new Timer();
|
util.stackFrame.timer = new Timer();
|
||||||
util.stackFrame.timer.start();
|
util.stackFrame.timer.start();
|
||||||
|
@ -86,14 +86,14 @@ Scratch3ControlBlocks.prototype.wait = function(args, util) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3ControlBlocks.prototype.if = function(args, util) {
|
Scratch3ControlBlocks.prototype.if = function (args, util) {
|
||||||
var condition = Cast.toBoolean(args.CONDITION);
|
var condition = Cast.toBoolean(args.CONDITION);
|
||||||
if (condition) {
|
if (condition) {
|
||||||
util.startBranch(1, false);
|
util.startBranch(1, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3ControlBlocks.prototype.ifElse = function(args, util) {
|
Scratch3ControlBlocks.prototype.ifElse = function (args, util) {
|
||||||
var condition = Cast.toBoolean(args.CONDITION);
|
var condition = Cast.toBoolean(args.CONDITION);
|
||||||
if (condition) {
|
if (condition) {
|
||||||
util.startBranch(1, false);
|
util.startBranch(1, false);
|
||||||
|
@ -102,7 +102,7 @@ Scratch3ControlBlocks.prototype.ifElse = function(args, util) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3ControlBlocks.prototype.stop = function(args, util) {
|
Scratch3ControlBlocks.prototype.stop = function (args, util) {
|
||||||
var option = args.STOP_OPTION;
|
var option = args.STOP_OPTION;
|
||||||
if (option == 'all') {
|
if (option == 'all') {
|
||||||
util.stopAll();
|
util.stopAll();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
var Cast = require('../util/cast');
|
var Cast = require('../util/cast');
|
||||||
|
|
||||||
function Scratch3DataBlocks(runtime) {
|
function Scratch3DataBlocks (runtime) {
|
||||||
/**
|
/**
|
||||||
* The runtime instantiating this block package.
|
* The runtime instantiating this block package.
|
||||||
* @type {Runtime}
|
* @type {Runtime}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
var Cast = require('../util/cast');
|
var Cast = require('../util/cast');
|
||||||
|
|
||||||
function Scratch3EventBlocks(runtime) {
|
function Scratch3EventBlocks (runtime) {
|
||||||
/**
|
/**
|
||||||
* The runtime instantiating this block package.
|
* The runtime instantiating this block package.
|
||||||
* @type {Runtime}
|
* @type {Runtime}
|
||||||
|
@ -12,7 +12,7 @@ function Scratch3EventBlocks(runtime) {
|
||||||
* Retrieve the block primitives implemented by this package.
|
* Retrieve the block primitives implemented by this package.
|
||||||
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
||||||
*/
|
*/
|
||||||
Scratch3EventBlocks.prototype.getPrimitives = function() {
|
Scratch3EventBlocks.prototype.getPrimitives = function () {
|
||||||
return {
|
return {
|
||||||
'event_broadcast': this.broadcast,
|
'event_broadcast': this.broadcast,
|
||||||
'event_broadcastandwait': this.broadcastAndWait,
|
'event_broadcastandwait': this.broadcastAndWait,
|
||||||
|
@ -54,7 +54,7 @@ Scratch3EventBlocks.prototype.hatGreaterThanPredicate = function (args, util) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3EventBlocks.prototype.broadcast = function(args, util) {
|
Scratch3EventBlocks.prototype.broadcast = function (args, util) {
|
||||||
var broadcastOption = Cast.toString(args.BROADCAST_OPTION);
|
var broadcastOption = Cast.toString(args.BROADCAST_OPTION);
|
||||||
util.startHats('event_whenbroadcastreceived', {
|
util.startHats('event_whenbroadcastreceived', {
|
||||||
'BROADCAST_OPTION': broadcastOption
|
'BROADCAST_OPTION': broadcastOption
|
||||||
|
@ -78,7 +78,7 @@ Scratch3EventBlocks.prototype.broadcastAndWait = function (args, util) {
|
||||||
}
|
}
|
||||||
// We've run before; check if the wait is still going on.
|
// We've run before; check if the wait is still going on.
|
||||||
var instance = this;
|
var instance = this;
|
||||||
var waiting = util.stackFrame.startedThreads.some(function(thread) {
|
var waiting = util.stackFrame.startedThreads.some(function (thread) {
|
||||||
return instance.runtime.isActiveThread(thread);
|
return instance.runtime.isActiveThread(thread);
|
||||||
});
|
});
|
||||||
if (waiting) {
|
if (waiting) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
var Cast = require('../util/cast');
|
var Cast = require('../util/cast');
|
||||||
|
|
||||||
function Scratch3LooksBlocks(runtime) {
|
function Scratch3LooksBlocks (runtime) {
|
||||||
/**
|
/**
|
||||||
* The runtime instantiating this block package.
|
* The runtime instantiating this block package.
|
||||||
* @type {Runtime}
|
* @type {Runtime}
|
||||||
|
@ -12,7 +12,7 @@ function Scratch3LooksBlocks(runtime) {
|
||||||
* Retrieve the block primitives implemented by this package.
|
* Retrieve the block primitives implemented by this package.
|
||||||
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
||||||
*/
|
*/
|
||||||
Scratch3LooksBlocks.prototype.getPrimitives = function() {
|
Scratch3LooksBlocks.prototype.getPrimitives = function () {
|
||||||
return {
|
return {
|
||||||
'looks_say': this.say,
|
'looks_say': this.say,
|
||||||
'looks_sayforsecs': this.sayforsecs,
|
'looks_sayforsecs': this.sayforsecs,
|
||||||
|
@ -45,8 +45,8 @@ Scratch3LooksBlocks.prototype.say = function (args, util) {
|
||||||
|
|
||||||
Scratch3LooksBlocks.prototype.sayforsecs = function (args, util) {
|
Scratch3LooksBlocks.prototype.sayforsecs = function (args, util) {
|
||||||
util.target.setSay('say', args.MESSAGE);
|
util.target.setSay('say', args.MESSAGE);
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function (resolve) {
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
// Clear say bubble and proceed.
|
// Clear say bubble and proceed.
|
||||||
util.target.setSay();
|
util.target.setSay();
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -60,8 +60,8 @@ Scratch3LooksBlocks.prototype.think = function (args, util) {
|
||||||
|
|
||||||
Scratch3LooksBlocks.prototype.thinkforsecs = function (args, util) {
|
Scratch3LooksBlocks.prototype.thinkforsecs = function (args, util) {
|
||||||
util.target.setSay('think', args.MESSAGE);
|
util.target.setSay('think', args.MESSAGE);
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function (resolve) {
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
// Clear say bubble and proceed.
|
// Clear say bubble and proceed.
|
||||||
util.target.setSay();
|
util.target.setSay();
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -149,7 +149,7 @@ Scratch3LooksBlocks.prototype.switchBackdropAndWait = function (args, util) {
|
||||||
}
|
}
|
||||||
// We've run before; check if the wait is still going on.
|
// We've run before; check if the wait is still going on.
|
||||||
var instance = this;
|
var instance = this;
|
||||||
var waiting = util.stackFrame.startedThreads.some(function(thread) {
|
var waiting = util.stackFrame.startedThreads.some(function (thread) {
|
||||||
return instance.runtime.isActiveThread(thread);
|
return instance.runtime.isActiveThread(thread);
|
||||||
});
|
});
|
||||||
if (waiting) {
|
if (waiting) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ var Cast = require('../util/cast');
|
||||||
var MathUtil = require('../util/math-util');
|
var MathUtil = require('../util/math-util');
|
||||||
var Timer = require('../util/timer');
|
var Timer = require('../util/timer');
|
||||||
|
|
||||||
function Scratch3MotionBlocks(runtime) {
|
function Scratch3MotionBlocks (runtime) {
|
||||||
/**
|
/**
|
||||||
* The runtime instantiating this block package.
|
* The runtime instantiating this block package.
|
||||||
* @type {Runtime}
|
* @type {Runtime}
|
||||||
|
@ -14,7 +14,7 @@ function Scratch3MotionBlocks(runtime) {
|
||||||
* Retrieve the block primitives implemented by this package.
|
* Retrieve the block primitives implemented by this package.
|
||||||
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
||||||
*/
|
*/
|
||||||
Scratch3MotionBlocks.prototype.getPrimitives = function() {
|
Scratch3MotionBlocks.prototype.getPrimitives = function () {
|
||||||
return {
|
return {
|
||||||
'motion_movesteps': this.moveSteps,
|
'motion_movesteps': this.moveSteps,
|
||||||
'motion_gotoxy': this.goToXY,
|
'motion_gotoxy': this.goToXY,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
var Cast = require('../util/cast.js');
|
var Cast = require('../util/cast.js');
|
||||||
|
|
||||||
function Scratch3OperatorsBlocks(runtime) {
|
function Scratch3OperatorsBlocks (runtime) {
|
||||||
/**
|
/**
|
||||||
* The runtime instantiating this block package.
|
* The runtime instantiating this block package.
|
||||||
* @type {Runtime}
|
* @type {Runtime}
|
||||||
|
@ -12,7 +12,7 @@ function Scratch3OperatorsBlocks(runtime) {
|
||||||
* Retrieve the block primitives implemented by this package.
|
* Retrieve the block primitives implemented by this package.
|
||||||
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
||||||
*/
|
*/
|
||||||
Scratch3OperatorsBlocks.prototype.getPrimitives = function() {
|
Scratch3OperatorsBlocks.prototype.getPrimitives = function () {
|
||||||
return {
|
return {
|
||||||
'operator_add': this.add,
|
'operator_add': this.add,
|
||||||
'operator_subtract': this.subtract,
|
'operator_subtract': this.subtract,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
function Scratch3ProcedureBlocks(runtime) {
|
function Scratch3ProcedureBlocks (runtime) {
|
||||||
/**
|
/**
|
||||||
* The runtime instantiating this block package.
|
* The runtime instantiating this block package.
|
||||||
* @type {Runtime}
|
* @type {Runtime}
|
||||||
|
@ -10,7 +10,7 @@ function Scratch3ProcedureBlocks(runtime) {
|
||||||
* Retrieve the block primitives implemented by this package.
|
* Retrieve the block primitives implemented by this package.
|
||||||
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
||||||
*/
|
*/
|
||||||
Scratch3ProcedureBlocks.prototype.getPrimitives = function() {
|
Scratch3ProcedureBlocks.prototype.getPrimitives = function () {
|
||||||
return {
|
return {
|
||||||
'procedures_defnoreturn': this.defNoReturn,
|
'procedures_defnoreturn': this.defNoReturn,
|
||||||
'procedures_callnoreturn': this.callNoReturn,
|
'procedures_callnoreturn': this.callNoReturn,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
var Cast = require('../util/cast');
|
var Cast = require('../util/cast');
|
||||||
|
|
||||||
function Scratch3SensingBlocks(runtime) {
|
function Scratch3SensingBlocks (runtime) {
|
||||||
/**
|
/**
|
||||||
* The runtime instantiating this block package.
|
* The runtime instantiating this block package.
|
||||||
* @type {Runtime}
|
* @type {Runtime}
|
||||||
|
@ -12,7 +12,7 @@ function Scratch3SensingBlocks(runtime) {
|
||||||
* Retrieve the block primitives implemented by this package.
|
* Retrieve the block primitives implemented by this package.
|
||||||
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
||||||
*/
|
*/
|
||||||
Scratch3SensingBlocks.prototype.getPrimitives = function() {
|
Scratch3SensingBlocks.prototype.getPrimitives = function () {
|
||||||
return {
|
return {
|
||||||
'sensing_touchingobject': this.touchingObject,
|
'sensing_touchingobject': this.touchingObject,
|
||||||
'sensing_touchingcolor': this.touchingColor,
|
'sensing_touchingcolor': this.touchingColor,
|
||||||
|
@ -114,11 +114,11 @@ Scratch3SensingBlocks.prototype.getKeyPressed = function (args, util) {
|
||||||
return util.ioQuery('keyboard', 'getKeyIsDown', args.KEY_OPTION);
|
return util.ioQuery('keyboard', 'getKeyIsDown', args.KEY_OPTION);
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3SensingBlocks.prototype.daysSince2000 = function()
|
Scratch3SensingBlocks.prototype.daysSince2000 = function ()
|
||||||
{
|
{
|
||||||
var msPerDay = 24 * 60 * 60 * 1000;
|
var msPerDay = 24 * 60 * 60 * 1000;
|
||||||
var start = new Date(2000, 1-1, 1);
|
var start = new Date(2000, 1-1, 1);
|
||||||
var today = new Date();
|
var today = new Date();
|
||||||
var dstAdjust = today.getTimezoneOffset() - start.getTimezoneOffset();
|
var dstAdjust = today.getTimezoneOffset() - start.getTimezoneOffset();
|
||||||
var mSecsSinceStart = today.valueOf() - start.valueOf();
|
var mSecsSinceStart = today.valueOf() - start.valueOf();
|
||||||
mSecsSinceStart += ((today.getTimezoneOffset() - dstAdjust) * 60 * 1000);
|
mSecsSinceStart += ((today.getTimezoneOffset() - dstAdjust) * 60 * 1000);
|
||||||
|
|
|
@ -170,7 +170,7 @@ var execute = function (sequencer, thread) {
|
||||||
primitiveReportedValue = blockFunction(argValues, {
|
primitiveReportedValue = blockFunction(argValues, {
|
||||||
stackFrame: currentStackFrame.executionContext,
|
stackFrame: currentStackFrame.executionContext,
|
||||||
target: target,
|
target: target,
|
||||||
yield: function() {
|
yield: function () {
|
||||||
thread.status = Thread.STATUS_YIELD;
|
thread.status = Thread.STATUS_YIELD;
|
||||||
},
|
},
|
||||||
startBranch: function (branchNum, isLoop) {
|
startBranch: function (branchNum, isLoop) {
|
||||||
|
@ -179,10 +179,10 @@ var execute = function (sequencer, thread) {
|
||||||
stopAll: function () {
|
stopAll: function () {
|
||||||
runtime.stopAll();
|
runtime.stopAll();
|
||||||
},
|
},
|
||||||
stopOtherTargetThreads: function() {
|
stopOtherTargetThreads: function () {
|
||||||
runtime.stopForTarget(target, thread);
|
runtime.stopForTarget(target, thread);
|
||||||
},
|
},
|
||||||
stopThread: function() {
|
stopThread: function () {
|
||||||
sequencer.retireThread(thread);
|
sequencer.retireThread(thread);
|
||||||
},
|
},
|
||||||
startProcedure: function (procedureCode) {
|
startProcedure: function (procedureCode) {
|
||||||
|
@ -197,7 +197,7 @@ var execute = function (sequencer, thread) {
|
||||||
getParam: function (paramName) {
|
getParam: function (paramName) {
|
||||||
return thread.getParam(paramName);
|
return thread.getParam(paramName);
|
||||||
},
|
},
|
||||||
startHats: function(requestedHat, opt_matchFields, opt_target) {
|
startHats: function (requestedHat, opt_matchFields, opt_target) {
|
||||||
return (
|
return (
|
||||||
runtime.startHats(requestedHat, opt_matchFields, opt_target)
|
runtime.startHats(requestedHat, opt_matchFields, opt_target)
|
||||||
);
|
);
|
||||||
|
@ -224,7 +224,7 @@ var execute = function (sequencer, thread) {
|
||||||
thread.status = Thread.STATUS_PROMISE_WAIT;
|
thread.status = Thread.STATUS_PROMISE_WAIT;
|
||||||
}
|
}
|
||||||
// Promise handlers
|
// Promise handlers
|
||||||
primitiveReportedValue.then(function(resolvedValue) {
|
primitiveReportedValue.then(function (resolvedValue) {
|
||||||
handleReport(resolvedValue);
|
handleReport(resolvedValue);
|
||||||
if (typeof resolvedValue !== 'undefined') {
|
if (typeof resolvedValue !== 'undefined') {
|
||||||
thread.popStack();
|
thread.popStack();
|
||||||
|
@ -233,7 +233,7 @@ var execute = function (sequencer, thread) {
|
||||||
var nextBlockId = thread.target.blocks.getNextBlock(popped);
|
var nextBlockId = thread.target.blocks.getNextBlock(popped);
|
||||||
thread.pushStack(nextBlockId);
|
thread.pushStack(nextBlockId);
|
||||||
}
|
}
|
||||||
}, function(rejectionReason) {
|
}, function (rejectionReason) {
|
||||||
// Promise rejected: the primitive had some error.
|
// Promise rejected: the primitive had some error.
|
||||||
// Log it and proceed.
|
// Log it and proceed.
|
||||||
console.warn('Primitive rejected promise: ', rejectionReason);
|
console.warn('Primitive rejected promise: ', rejectionReason);
|
||||||
|
|
|
@ -394,7 +394,7 @@ Runtime.prototype.startHats = function (requestedHatOpcode,
|
||||||
var instance = this;
|
var instance = this;
|
||||||
var newThreads = [];
|
var newThreads = [];
|
||||||
// Consider all scripts, looking for hats with opcode `requestedHatOpcode`.
|
// Consider all scripts, looking for hats with opcode `requestedHatOpcode`.
|
||||||
this.allScriptsDo(function(topBlockId, target) {
|
this.allScriptsDo(function (topBlockId, target) {
|
||||||
var potentialHatOpcode = target.blocks.getBlock(topBlockId).opcode;
|
var potentialHatOpcode = target.blocks.getBlock(topBlockId).opcode;
|
||||||
if (potentialHatOpcode !== requestedHatOpcode) {
|
if (potentialHatOpcode !== requestedHatOpcode) {
|
||||||
// Not the right hat.
|
// Not the right hat.
|
||||||
|
@ -750,7 +750,7 @@ Runtime.prototype.start = function () {
|
||||||
interval = Runtime.THREAD_STEP_INTERVAL_COMPATIBILITY;
|
interval = Runtime.THREAD_STEP_INTERVAL_COMPATIBILITY;
|
||||||
}
|
}
|
||||||
this.currentStepTime = interval;
|
this.currentStepTime = interval;
|
||||||
this._steppingInterval = self.setInterval(function() {
|
this._steppingInterval = self.setInterval(function () {
|
||||||
this._step();
|
this._step();
|
||||||
}.bind(this), interval);
|
}.bind(this), interval);
|
||||||
};
|
};
|
||||||
|
|
|
@ -78,7 +78,7 @@ Sequencer.prototype.stepThreads = function () {
|
||||||
ranFirstTick = true;
|
ranFirstTick = true;
|
||||||
}
|
}
|
||||||
// Filter inactive threads from `this.runtime.threads`.
|
// Filter inactive threads from `this.runtime.threads`.
|
||||||
this.runtime.threads = this.runtime.threads.filter(function(thread) {
|
this.runtime.threads = this.runtime.threads.filter(function (thread) {
|
||||||
if (inactiveThreads.indexOf(thread) > -1) {
|
if (inactiveThreads.indexOf(thread) > -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,7 @@ Thread.prototype.isRecursiveCall = function (procedureCode) {
|
||||||
for (var i = sp - 1; i >= 0; i--) {
|
for (var i = sp - 1; i >= 0; i--) {
|
||||||
var block = this.target.blocks.getBlock(this.stack[i]);
|
var block = this.target.blocks.getBlock(this.stack[i]);
|
||||||
if (block.opcode == 'procedures_callnoreturn' &&
|
if (block.opcode == 'procedures_callnoreturn' &&
|
||||||
block.mutation.proccode == procedureCode) {
|
block.mutation.proccode == procedureCode) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (--callCount < 0) return false;
|
if (--callCount < 0) return false;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -106,11 +106,11 @@ VirtualMachine.prototype.clear = function () {
|
||||||
VirtualMachine.prototype.getPlaygroundData = function () {
|
VirtualMachine.prototype.getPlaygroundData = function () {
|
||||||
var instance = this;
|
var instance = this;
|
||||||
// Only send back thread data for the current editingTarget.
|
// Only send back thread data for the current editingTarget.
|
||||||
var threadData = this.runtime.threads.filter(function(thread) {
|
var threadData = this.runtime.threads.filter(function (thread) {
|
||||||
return thread.target == instance.editingTarget;
|
return thread.target == instance.editingTarget;
|
||||||
});
|
});
|
||||||
// Remove the target key, since it's a circular reference.
|
// Remove the target key, since it's a circular reference.
|
||||||
var filteredThreadData = JSON.stringify(threadData, function(key, value) {
|
var filteredThreadData = JSON.stringify(threadData, function (key, value) {
|
||||||
if (key == 'target') return undefined;
|
if (key == 'target') return undefined;
|
||||||
return value;
|
return value;
|
||||||
}, 2);
|
}, 2);
|
||||||
|
@ -297,7 +297,7 @@ VirtualMachine.prototype.emitTargetsUpdate = function () {
|
||||||
targetList: this.runtime.targets.filter(function (target) {
|
targetList: this.runtime.targets.filter(function (target) {
|
||||||
// Don't report clones.
|
// Don't report clones.
|
||||||
return !target.hasOwnProperty('isOriginal') || target.isOriginal;
|
return !target.hasOwnProperty('isOriginal') || target.isOriginal;
|
||||||
}).map(function(target) {
|
}).map(function (target) {
|
||||||
return [target.id, target.getName()];
|
return [target.id, target.getName()];
|
||||||
}),
|
}),
|
||||||
// Currently editing target id.
|
// Currently editing target id.
|
||||||
|
|
|
@ -12,7 +12,7 @@ function Mouse (runtime) {
|
||||||
this.runtime = runtime;
|
this.runtime = runtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mouse.prototype.postData = function(data) {
|
Mouse.prototype.postData = function (data) {
|
||||||
if (data.x) {
|
if (data.x) {
|
||||||
this._x = data.x - data.canvasWidth / 2;
|
this._x = data.x - data.canvasWidth / 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ var Target = require('../engine/target');
|
||||||
* @param {Runtime} runtime Reference to the runtime.
|
* @param {Runtime} runtime Reference to the runtime.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function Clone(sprite, runtime) {
|
function Clone (sprite, runtime) {
|
||||||
Target.call(this, sprite.blocks);
|
Target.call(this, sprite.blocks);
|
||||||
this.runtime = runtime;
|
this.runtime = runtime;
|
||||||
/**
|
/**
|
||||||
|
@ -447,7 +447,7 @@ Clone.prototype.isTouchingSprite = function (spriteName) {
|
||||||
if (!firstClone || !this.renderer) {
|
if (!firstClone || !this.renderer) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var drawableCandidates = firstClone.sprite.clones.map(function(clone) {
|
var drawableCandidates = firstClone.sprite.clones.map(function (clone) {
|
||||||
return clone.drawableID;
|
return clone.drawableID;
|
||||||
});
|
});
|
||||||
return this.renderer.isTouchingDrawables(
|
return this.renderer.isTouchingDrawables(
|
||||||
|
|
|
@ -35,7 +35,7 @@ Color.decimalToRgb = function (decimal) {
|
||||||
*/
|
*/
|
||||||
Color.hexToRgb = function (hex) {
|
Color.hexToRgb = function (hex) {
|
||||||
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
||||||
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
|
hex = hex.replace(shorthandRegex, function (m, r, g, b) {
|
||||||
return r + r + g + g + b + b;
|
return r + r + g + g + b + b;
|
||||||
});
|
});
|
||||||
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||||
|
|
|
@ -9,75 +9,75 @@ test('getPrimitives', function (t) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('add', function (t) {
|
test('add', function (t) {
|
||||||
t.strictEqual(blocks.add({NUM1:'1', NUM2:'1'}), 2);
|
t.strictEqual(blocks.add({NUM1: '1', NUM2: '1'}), 2);
|
||||||
t.strictEqual(blocks.add({NUM1:'foo', NUM2:'bar'}), 0);
|
t.strictEqual(blocks.add({NUM1: 'foo', NUM2: 'bar'}), 0);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('subtract', function (t) {
|
test('subtract', function (t) {
|
||||||
t.strictEqual(blocks.subtract({NUM1:'1', NUM2:'1'}), 0);
|
t.strictEqual(blocks.subtract({NUM1: '1', NUM2: '1'}), 0);
|
||||||
t.strictEqual(blocks.subtract({NUM1:'foo', NUM2:'bar'}), 0);
|
t.strictEqual(blocks.subtract({NUM1: 'foo', NUM2: 'bar'}), 0);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('multiply', function (t) {
|
test('multiply', function (t) {
|
||||||
t.strictEqual(blocks.multiply({NUM1:'2', NUM2:'2'}), 4);
|
t.strictEqual(blocks.multiply({NUM1: '2', NUM2: '2'}), 4);
|
||||||
t.strictEqual(blocks.multiply({NUM1:'foo', NUM2:'bar'}), 0);
|
t.strictEqual(blocks.multiply({NUM1: 'foo', NUM2: 'bar'}), 0);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('divide', function (t) {
|
test('divide', function (t) {
|
||||||
t.strictEqual(blocks.divide({NUM1:'2', NUM2:'2'}), 1);
|
t.strictEqual(blocks.divide({NUM1: '2', NUM2: '2'}), 1);
|
||||||
t.strictEqual(blocks.divide({NUM1:'1', NUM2:'0'}), Infinity); // @todo
|
t.strictEqual(blocks.divide({NUM1: '1', NUM2: '0'}), Infinity); // @todo
|
||||||
t.ok(isNaN(blocks.divide({NUM1:'foo', NUM2:'bar'}))); // @todo
|
t.ok(isNaN(blocks.divide({NUM1: 'foo', NUM2: 'bar'}))); // @todo
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('lt', function (t) {
|
test('lt', function (t) {
|
||||||
t.strictEqual(blocks.lt({OPERAND1:'1', OPERAND2:'2'}), true);
|
t.strictEqual(blocks.lt({OPERAND1: '1', OPERAND2: '2'}), true);
|
||||||
t.strictEqual(blocks.lt({OPERAND1:'2', OPERAND2:'1'}), false);
|
t.strictEqual(blocks.lt({OPERAND1: '2', OPERAND2: '1'}), false);
|
||||||
t.strictEqual(blocks.lt({OPERAND1:'1', OPERAND2:'1'}), false);
|
t.strictEqual(blocks.lt({OPERAND1: '1', OPERAND2: '1'}), false);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('equals', function (t) {
|
test('equals', function (t) {
|
||||||
t.strictEqual(blocks.equals({OPERAND1:'1', OPERAND2:'2'}), false);
|
t.strictEqual(blocks.equals({OPERAND1: '1', OPERAND2: '2'}), false);
|
||||||
t.strictEqual(blocks.equals({OPERAND1:'2', OPERAND2:'1'}), false);
|
t.strictEqual(blocks.equals({OPERAND1: '2', OPERAND2: '1'}), false);
|
||||||
t.strictEqual(blocks.equals({OPERAND1:'1', OPERAND2:'1'}), true);
|
t.strictEqual(blocks.equals({OPERAND1: '1', OPERAND2: '1'}), true);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('gt', function (t) {
|
test('gt', function (t) {
|
||||||
t.strictEqual(blocks.gt({OPERAND1:'1', OPERAND2:'2'}), false);
|
t.strictEqual(blocks.gt({OPERAND1: '1', OPERAND2: '2'}), false);
|
||||||
t.strictEqual(blocks.gt({OPERAND1:'2', OPERAND2:'1'}), true);
|
t.strictEqual(blocks.gt({OPERAND1: '2', OPERAND2: '1'}), true);
|
||||||
t.strictEqual(blocks.gt({OPERAND1:'1', OPERAND2:'1'}), false);
|
t.strictEqual(blocks.gt({OPERAND1: '1', OPERAND2: '1'}), false);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('and', function (t) {
|
test('and', function (t) {
|
||||||
t.strictEqual(blocks.and({OPERAND1:true, OPERAND2:true}), true);
|
t.strictEqual(blocks.and({OPERAND1: true, OPERAND2: true}), true);
|
||||||
t.strictEqual(blocks.and({OPERAND1:true, OPERAND2:false}), false);
|
t.strictEqual(blocks.and({OPERAND1: true, OPERAND2: false}), false);
|
||||||
t.strictEqual(blocks.and({OPERAND1:false, OPERAND2:false}), false);
|
t.strictEqual(blocks.and({OPERAND1: false, OPERAND2: false}), false);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('or', function (t) {
|
test('or', function (t) {
|
||||||
t.strictEqual(blocks.or({OPERAND1:true, OPERAND2:true}), true);
|
t.strictEqual(blocks.or({OPERAND1: true, OPERAND2: true}), true);
|
||||||
t.strictEqual(blocks.or({OPERAND1:true, OPERAND2:false}), true);
|
t.strictEqual(blocks.or({OPERAND1: true, OPERAND2: false}), true);
|
||||||
t.strictEqual(blocks.or({OPERAND1:false, OPERAND2:false}), false);
|
t.strictEqual(blocks.or({OPERAND1: false, OPERAND2: false}), false);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('not', function (t) {
|
test('not', function (t) {
|
||||||
t.strictEqual(blocks.not({OPERAND:true}), false);
|
t.strictEqual(blocks.not({OPERAND: true}), false);
|
||||||
t.strictEqual(blocks.not({OPERAND:false}), true);
|
t.strictEqual(blocks.not({OPERAND: false}), true);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('random', function (t) {
|
test('random', function (t) {
|
||||||
var min = 0;
|
var min = 0;
|
||||||
var max = 100;
|
var max = 100;
|
||||||
var result = blocks.random({FROM:min, TO:max});
|
var result = blocks.random({FROM: min, TO: max});
|
||||||
t.ok(result >= min);
|
t.ok(result >= min);
|
||||||
t.ok(result <= max);
|
t.ok(result <= max);
|
||||||
t.end();
|
t.end();
|
||||||
|
@ -86,14 +86,14 @@ test('random', function (t) {
|
||||||
test('random - equal', function (t) {
|
test('random - equal', function (t) {
|
||||||
var min = 1;
|
var min = 1;
|
||||||
var max = 1;
|
var max = 1;
|
||||||
t.strictEqual(blocks.random({FROM:min, TO:max}), min);
|
t.strictEqual(blocks.random({FROM: min, TO: max}), min);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('random - decimal', function (t) {
|
test('random - decimal', function (t) {
|
||||||
var min = 0.1;
|
var min = 0.1;
|
||||||
var max = 10;
|
var max = 10;
|
||||||
var result = blocks.random({FROM:min, TO:max});
|
var result = blocks.random({FROM: min, TO: max});
|
||||||
t.ok(result >= min);
|
t.ok(result >= min);
|
||||||
t.ok(result <= max);
|
t.ok(result <= max);
|
||||||
t.end();
|
t.end();
|
||||||
|
@ -102,7 +102,7 @@ test('random - decimal', function (t) {
|
||||||
test('random - int', function (t) {
|
test('random - int', function (t) {
|
||||||
var min = 0;
|
var min = 0;
|
||||||
var max = 10;
|
var max = 10;
|
||||||
var result = blocks.random({FROM:min, TO:max});
|
var result = blocks.random({FROM: min, TO: max});
|
||||||
t.ok(result >= min);
|
t.ok(result >= min);
|
||||||
t.ok(result <= max);
|
t.ok(result <= max);
|
||||||
t.end();
|
t.end();
|
||||||
|
@ -111,65 +111,65 @@ test('random - int', function (t) {
|
||||||
test('random - reverse', function (t) {
|
test('random - reverse', function (t) {
|
||||||
var min = 0;
|
var min = 0;
|
||||||
var max = 10;
|
var max = 10;
|
||||||
var result = blocks.random({FROM:max, TO:min});
|
var result = blocks.random({FROM: max, TO: min});
|
||||||
t.ok(result >= min);
|
t.ok(result >= min);
|
||||||
t.ok(result <= max);
|
t.ok(result <= max);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('join', function (t) {
|
test('join', function (t) {
|
||||||
t.strictEqual(blocks.join({STRING1:'foo', STRING2:'bar'}), 'foobar');
|
t.strictEqual(blocks.join({STRING1: 'foo', STRING2: 'bar'}), 'foobar');
|
||||||
t.strictEqual(blocks.join({STRING1:'1', STRING2:'2'}), '12');
|
t.strictEqual(blocks.join({STRING1: '1', STRING2: '2'}), '12');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('letterOf', function (t) {
|
test('letterOf', function (t) {
|
||||||
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:0}), '');
|
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 0}), '');
|
||||||
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:1}), 'f');
|
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 1}), 'f');
|
||||||
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:2}), 'o');
|
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 2}), 'o');
|
||||||
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:3}), 'o');
|
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 3}), 'o');
|
||||||
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:4}), '');
|
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 4}), '');
|
||||||
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:'bar'}), '');
|
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 'bar'}), '');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('length', function (t) {
|
test('length', function (t) {
|
||||||
t.strictEqual(blocks.length({STRING:''}), 0);
|
t.strictEqual(blocks.length({STRING: ''}), 0);
|
||||||
t.strictEqual(blocks.length({STRING:'foo'}), 3);
|
t.strictEqual(blocks.length({STRING: 'foo'}), 3);
|
||||||
t.strictEqual(blocks.length({STRING:'1'}), 1);
|
t.strictEqual(blocks.length({STRING: '1'}), 1);
|
||||||
t.strictEqual(blocks.length({STRING:'100'}), 3);
|
t.strictEqual(blocks.length({STRING: '100'}), 3);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('mod', function (t) {
|
test('mod', function (t) {
|
||||||
t.strictEqual(blocks.mod({NUM1:1, NUM2:1}), 0);
|
t.strictEqual(blocks.mod({NUM1: 1, NUM2: 1}), 0);
|
||||||
t.strictEqual(blocks.mod({NUM1:3, NUM2:6}), 3);
|
t.strictEqual(blocks.mod({NUM1: 3, NUM2: 6}), 3);
|
||||||
t.strictEqual(blocks.mod({NUM1:-3, NUM2:6}), 3);
|
t.strictEqual(blocks.mod({NUM1: -3, NUM2: 6}), 3);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('round', function (t) {
|
test('round', function (t) {
|
||||||
t.strictEqual(blocks.round({NUM:1}), 1);
|
t.strictEqual(blocks.round({NUM: 1}), 1);
|
||||||
t.strictEqual(blocks.round({NUM:1.1}), 1);
|
t.strictEqual(blocks.round({NUM: 1.1}), 1);
|
||||||
t.strictEqual(blocks.round({NUM:1.5}), 2);
|
t.strictEqual(blocks.round({NUM: 1.5}), 2);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('mathop', function (t) {
|
test('mathop', function (t) {
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'abs', NUM:-1}), 1);
|
t.strictEqual(blocks.mathop({OPERATOR: 'abs', NUM: -1}), 1);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'floor', NUM:1.5}), 1);
|
t.strictEqual(blocks.mathop({OPERATOR: 'floor', NUM: 1.5}), 1);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'ceiling', NUM:0.1}), 1);
|
t.strictEqual(blocks.mathop({OPERATOR: 'ceiling', NUM: 0.1}), 1);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'sqrt', NUM:1}), 1);
|
t.strictEqual(blocks.mathop({OPERATOR: 'sqrt', NUM: 1}), 1);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'sin', NUM:1}), 0.01745240643728351);
|
t.strictEqual(blocks.mathop({OPERATOR: 'sin', NUM: 1}), 0.01745240643728351);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'cos', NUM:1}), 0.9998476951563913);
|
t.strictEqual(blocks.mathop({OPERATOR: 'cos', NUM: 1}), 0.9998476951563913);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'tan', NUM:1}), 0.017455064928217585);
|
t.strictEqual(blocks.mathop({OPERATOR: 'tan', NUM: 1}), 0.017455064928217585);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'asin', NUM:1}), 90);
|
t.strictEqual(blocks.mathop({OPERATOR: 'asin', NUM: 1}), 90);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'acos', NUM:1}), 0);
|
t.strictEqual(blocks.mathop({OPERATOR: 'acos', NUM: 1}), 0);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'atan', NUM:1}), 45);
|
t.strictEqual(blocks.mathop({OPERATOR: 'atan', NUM: 1}), 45);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'ln', NUM:1}), 0);
|
t.strictEqual(blocks.mathop({OPERATOR: 'ln', NUM: 1}), 0);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'log', NUM:1}), 0);
|
t.strictEqual(blocks.mathop({OPERATOR: 'log', NUM: 1}), 0);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'e ^', NUM:1}), 2.718281828459045);
|
t.strictEqual(blocks.mathop({OPERATOR: 'e ^', NUM: 1}), 2.718281828459045);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'10 ^', NUM:1}), 10);
|
t.strictEqual(blocks.mathop({OPERATOR: '10 ^', NUM: 1}), 10);
|
||||||
t.strictEqual(blocks.mathop({OPERATOR:'undefined', NUM:1}), 0);
|
t.strictEqual(blocks.mathop({OPERATOR: 'undefined', NUM: 1}), 0);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,10 +7,10 @@ test('spec', function (t) {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('invalid inputs', function(t) {
|
test('invalid inputs', function (t) {
|
||||||
var nothing = adapter('not an object');
|
var nothing = adapter('not an object');
|
||||||
t.type(nothing, 'undefined');
|
t.type(nothing, 'undefined');
|
||||||
nothing = adapter({noxmlproperty:true});
|
nothing = adapter({noxmlproperty: true});
|
||||||
t.type(nothing, 'undefined');
|
t.type(nothing, 'undefined');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -26,7 +26,7 @@ test('create event', function (t) {
|
||||||
t.type(result[0].opcode, 'string');
|
t.type(result[0].opcode, 'string');
|
||||||
t.type(result[0].fields, 'object');
|
t.type(result[0].fields, 'object');
|
||||||
t.type(result[0].inputs, 'object');
|
t.type(result[0].inputs, 'object');
|
||||||
t.type(result[0].inputs['DURATION'], 'object');
|
t.type(result[0].inputs.DURATION, 'object');
|
||||||
t.type(result[0].topLevel, 'boolean');
|
t.type(result[0].topLevel, 'boolean');
|
||||||
t.equal(result[0].topLevel, true);
|
t.equal(result[0].topLevel, true);
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ test('create event', function (t) {
|
||||||
t.type(result[1].opcode, 'string');
|
t.type(result[1].opcode, 'string');
|
||||||
t.type(result[1].fields, 'object');
|
t.type(result[1].fields, 'object');
|
||||||
t.type(result[1].inputs, 'object');
|
t.type(result[1].inputs, 'object');
|
||||||
t.type(result[1].fields['NUM'], 'object');
|
t.type(result[1].fields.NUM, 'object');
|
||||||
t.type(result[1].fields['NUM'].value, '10');
|
t.type(result[1].fields.NUM.value, '10');
|
||||||
t.type(result[1].topLevel, 'boolean');
|
t.type(result[1].topLevel, 'boolean');
|
||||||
t.equal(result[1].topLevel, false);
|
t.equal(result[1].topLevel, false);
|
||||||
|
|
||||||
|
@ -50,12 +50,12 @@ test('create with branch', function (t) {
|
||||||
t.type(result[0].opcode, 'string');
|
t.type(result[0].opcode, 'string');
|
||||||
t.type(result[0].fields, 'object');
|
t.type(result[0].fields, 'object');
|
||||||
t.type(result[0].inputs, 'object');
|
t.type(result[0].inputs, 'object');
|
||||||
t.type(result[0].inputs['SUBSTACK'], 'object');
|
t.type(result[0].inputs.SUBSTACK, 'object');
|
||||||
t.type(result[0].topLevel, 'boolean');
|
t.type(result[0].topLevel, 'boolean');
|
||||||
t.equal(result[0].topLevel, true);
|
t.equal(result[0].topLevel, true);
|
||||||
// In branch
|
// In branch
|
||||||
var branchBlockId = result[0].inputs['SUBSTACK']['block'];
|
var branchBlockId = result[0].inputs.SUBSTACK.block;
|
||||||
var branchShadowId = result[0].inputs['SUBSTACK']['shadow'];
|
var branchShadowId = result[0].inputs.SUBSTACK.shadow;
|
||||||
t.type(branchBlockId, 'string');
|
t.type(branchBlockId, 'string');
|
||||||
t.equal(branchShadowId, null);
|
t.equal(branchShadowId, null);
|
||||||
// Find actual branch block
|
// Find actual branch block
|
||||||
|
@ -76,17 +76,17 @@ test('create with two branches', function (t) {
|
||||||
t.type(result[0].opcode, 'string');
|
t.type(result[0].opcode, 'string');
|
||||||
t.type(result[0].fields, 'object');
|
t.type(result[0].fields, 'object');
|
||||||
t.type(result[0].inputs, 'object');
|
t.type(result[0].inputs, 'object');
|
||||||
t.type(result[0].inputs['SUBSTACK'], 'object');
|
t.type(result[0].inputs.SUBSTACK, 'object');
|
||||||
t.type(result[0].inputs['SUBSTACK2'], 'object');
|
t.type(result[0].inputs.SUBSTACK2, 'object');
|
||||||
t.type(result[0].topLevel, 'boolean');
|
t.type(result[0].topLevel, 'boolean');
|
||||||
t.equal(result[0].topLevel, true);
|
t.equal(result[0].topLevel, true);
|
||||||
// In branchs
|
// In branchs
|
||||||
var firstBranchBlockId = result[0].inputs['SUBSTACK']['block'];
|
var firstBranchBlockId = result[0].inputs.SUBSTACK.block;
|
||||||
var secondBranchBlockId = result[0].inputs['SUBSTACK2']['block'];
|
var secondBranchBlockId = result[0].inputs.SUBSTACK2.block;
|
||||||
t.type(firstBranchBlockId, 'string');
|
t.type(firstBranchBlockId, 'string');
|
||||||
t.type(secondBranchBlockId, 'string');
|
t.type(secondBranchBlockId, 'string');
|
||||||
var firstBranchShadowBlockId = result[0].inputs['SUBSTACK']['shadow'];
|
var firstBranchShadowBlockId = result[0].inputs.SUBSTACK.shadow;
|
||||||
var secondBranchShadowBlockId = result[0].inputs['SUBSTACK2']['shadow'];
|
var secondBranchShadowBlockId = result[0].inputs.SUBSTACK2.shadow;
|
||||||
t.equal(firstBranchShadowBlockId, null);
|
t.equal(firstBranchShadowBlockId, null);
|
||||||
t.equal(secondBranchShadowBlockId, null);
|
t.equal(secondBranchShadowBlockId, null);
|
||||||
// Find actual branch blocks
|
// Find actual branch blocks
|
||||||
|
|
|
@ -245,8 +245,8 @@ test('create', function (t) {
|
||||||
topLevel: true
|
topLevel: true
|
||||||
});
|
});
|
||||||
|
|
||||||
t.type(b._blocks['foo'], 'object');
|
t.type(b._blocks.foo, 'object');
|
||||||
t.equal(b._blocks['foo'].opcode, 'TEST_BLOCK');
|
t.equal(b._blocks.foo.opcode, 'TEST_BLOCK');
|
||||||
t.notEqual(b._scripts.indexOf('foo'), -1);
|
t.notEqual(b._scripts.indexOf('foo'), -1);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -277,7 +277,7 @@ test('move', function (t) {
|
||||||
});
|
});
|
||||||
t.equal(b._scripts.length, 1);
|
t.equal(b._scripts.length, 1);
|
||||||
t.equal(Object.keys(b._blocks).length, 2);
|
t.equal(Object.keys(b._blocks).length, 2);
|
||||||
t.equal(b._blocks['foo'].next, 'bar');
|
t.equal(b._blocks.foo.next, 'bar');
|
||||||
|
|
||||||
// Detach 'bar' from 'foo'
|
// Detach 'bar' from 'foo'
|
||||||
b.moveBlock({
|
b.moveBlock({
|
||||||
|
@ -286,7 +286,7 @@ test('move', function (t) {
|
||||||
});
|
});
|
||||||
t.equal(b._scripts.length, 2);
|
t.equal(b._scripts.length, 2);
|
||||||
t.equal(Object.keys(b._blocks).length, 2);
|
t.equal(Object.keys(b._blocks).length, 2);
|
||||||
t.equal(b._blocks['foo'].next, null);
|
t.equal(b._blocks.foo.next, null);
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -314,7 +314,7 @@ test('move into empty', function (t) {
|
||||||
newInput: 'fooInput',
|
newInput: 'fooInput',
|
||||||
newParent: 'foo'
|
newParent: 'foo'
|
||||||
});
|
});
|
||||||
t.equal(b._blocks['foo'].inputs['fooInput'].block, 'bar');
|
t.equal(b._blocks.foo.inputs.fooInput.block, 'bar');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -347,8 +347,8 @@ test('move no obscure shadow', function (t) {
|
||||||
newInput: 'fooInput',
|
newInput: 'fooInput',
|
||||||
newParent: 'foo'
|
newParent: 'foo'
|
||||||
});
|
});
|
||||||
t.equal(b._blocks['foo'].inputs['fooInput'].block, 'bar');
|
t.equal(b._blocks.foo.inputs.fooInput.block, 'bar');
|
||||||
t.equal(b._blocks['foo'].inputs['fooInput'].shadow, 'y');
|
t.equal(b._blocks.foo.inputs.fooInput.shadow, 'y');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ test('change', function (t) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test that the field is updated
|
// Test that the field is updated
|
||||||
t.equal(b._blocks['foo'].fields.someField.value, 'initial-value');
|
t.equal(b._blocks.foo.fields.someField.value, 'initial-value');
|
||||||
|
|
||||||
b.changeBlock({
|
b.changeBlock({
|
||||||
element: 'field',
|
element: 'field',
|
||||||
|
@ -378,7 +378,7 @@ test('change', function (t) {
|
||||||
value: 'final-value'
|
value: 'final-value'
|
||||||
});
|
});
|
||||||
|
|
||||||
t.equal(b._blocks['foo'].fields.someField.value, 'final-value');
|
t.equal(b._blocks.foo.fields.someField.value, 'final-value');
|
||||||
|
|
||||||
// Invalid cases
|
// Invalid cases
|
||||||
// No `element`
|
// No `element`
|
||||||
|
@ -387,7 +387,7 @@ test('change', function (t) {
|
||||||
name: 'someField',
|
name: 'someField',
|
||||||
value: 'invalid-value'
|
value: 'invalid-value'
|
||||||
});
|
});
|
||||||
t.equal(b._blocks['foo'].fields.someField.value, 'final-value');
|
t.equal(b._blocks.foo.fields.someField.value, 'final-value');
|
||||||
|
|
||||||
// No block ID
|
// No block ID
|
||||||
b.changeBlock({
|
b.changeBlock({
|
||||||
|
@ -395,7 +395,7 @@ test('change', function (t) {
|
||||||
name: 'someField',
|
name: 'someField',
|
||||||
value: 'invalid-value'
|
value: 'invalid-value'
|
||||||
});
|
});
|
||||||
t.equal(b._blocks['foo'].fields.someField.value, 'final-value');
|
t.equal(b._blocks.foo.fields.someField.value, 'final-value');
|
||||||
|
|
||||||
// No such field
|
// No such field
|
||||||
b.changeBlock({
|
b.changeBlock({
|
||||||
|
@ -404,7 +404,7 @@ test('change', function (t) {
|
||||||
name: 'someWrongField',
|
name: 'someWrongField',
|
||||||
value: 'final-value'
|
value: 'final-value'
|
||||||
});
|
});
|
||||||
t.equal(b._blocks['foo'].fields.someField.value, 'final-value');
|
t.equal(b._blocks.foo.fields.someField.value, 'final-value');
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -423,7 +423,7 @@ test('delete', function (t) {
|
||||||
id: 'foo'
|
id: 'foo'
|
||||||
});
|
});
|
||||||
|
|
||||||
t.type(b._blocks['foo'], 'undefined');
|
t.type(b._blocks.foo, 'undefined');
|
||||||
t.equal(b._scripts.indexOf('foo'), -1);
|
t.equal(b._scripts.indexOf('foo'), -1);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -459,9 +459,9 @@ test('delete chain', function (t) {
|
||||||
b.deleteBlock({
|
b.deleteBlock({
|
||||||
id: 'foo'
|
id: 'foo'
|
||||||
});
|
});
|
||||||
t.type(b._blocks['foo'], 'undefined');
|
t.type(b._blocks.foo, 'undefined');
|
||||||
t.type(b._blocks['foo2'], 'undefined');
|
t.type(b._blocks.foo2, 'undefined');
|
||||||
t.type(b._blocks['foo3'], 'undefined');
|
t.type(b._blocks.foo3, 'undefined');
|
||||||
t.equal(b._scripts.indexOf('foo'), -1);
|
t.equal(b._scripts.indexOf('foo'), -1);
|
||||||
t.equal(Object.keys(b._blocks).length, 0);
|
t.equal(Object.keys(b._blocks).length, 0);
|
||||||
t.equal(b._scripts.length, 0);
|
t.equal(b._scripts.length, 0);
|
||||||
|
@ -532,11 +532,11 @@ test('delete inputs', function (t) {
|
||||||
b.deleteBlock({
|
b.deleteBlock({
|
||||||
id: 'foo'
|
id: 'foo'
|
||||||
});
|
});
|
||||||
t.type(b._blocks['foo'], 'undefined');
|
t.type(b._blocks.foo, 'undefined');
|
||||||
t.type(b._blocks['foo2'], 'undefined');
|
t.type(b._blocks.foo2, 'undefined');
|
||||||
t.type(b._blocks['foo3'], 'undefined');
|
t.type(b._blocks.foo3, 'undefined');
|
||||||
t.type(b._blocks['foo4'], 'undefined');
|
t.type(b._blocks.foo4, 'undefined');
|
||||||
t.type(b._blocks['foo5'], 'undefined');
|
t.type(b._blocks.foo5, 'undefined');
|
||||||
t.equal(b._scripts.indexOf('foo'), -1);
|
t.equal(b._scripts.indexOf('foo'), -1);
|
||||||
t.equal(Object.keys(b._blocks).length, 0);
|
t.equal(Object.keys(b._blocks).length, 0);
|
||||||
t.equal(b._scripts.length, 0);
|
t.equal(b._scripts.length, 0);
|
||||||
|
|
|
@ -11,25 +11,25 @@ test('decimalToHex', function (t) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('decimalToRgb', function (t) {
|
test('decimalToRgb', function (t) {
|
||||||
t.deepEqual(color.decimalToRgb(0), {r:0,g:0,b:0});
|
t.deepEqual(color.decimalToRgb(0), {r: 0,g: 0,b: 0});
|
||||||
t.deepEqual(color.decimalToRgb(1), {r:0,g:0,b:1});
|
t.deepEqual(color.decimalToRgb(1), {r: 0,g: 0,b: 1});
|
||||||
t.deepEqual(color.decimalToRgb(16777215), {r:255,g:255,b:255});
|
t.deepEqual(color.decimalToRgb(16777215), {r: 255,g: 255,b: 255});
|
||||||
t.deepEqual(color.decimalToRgb(-16777215), {r:0,g:0,b:1});
|
t.deepEqual(color.decimalToRgb(-16777215), {r: 0,g: 0,b: 1});
|
||||||
t.deepEqual(color.decimalToRgb(99999999), {r:245,g:224,b:255});
|
t.deepEqual(color.decimalToRgb(99999999), {r: 245,g: 224,b: 255});
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('hexToRgb', function (t) {
|
test('hexToRgb', function (t) {
|
||||||
t.deepEqual(color.hexToRgb('#000'), {r:0,g:0,b:0});
|
t.deepEqual(color.hexToRgb('#000'), {r: 0,g: 0,b: 0});
|
||||||
t.deepEqual(color.hexToRgb('#000000'), {r:0,g:0,b:0});
|
t.deepEqual(color.hexToRgb('#000000'), {r: 0,g: 0,b: 0});
|
||||||
t.deepEqual(color.hexToRgb('#fff'), {r:255,g:255,b:255});
|
t.deepEqual(color.hexToRgb('#fff'), {r: 255,g: 255,b: 255});
|
||||||
t.deepEqual(color.hexToRgb('#ffffff'), {r:255,g:255,b:255});
|
t.deepEqual(color.hexToRgb('#ffffff'), {r: 255,g: 255,b: 255});
|
||||||
t.deepEqual(color.hexToRgb('#0fa'), {r:0,g:255,b:170});
|
t.deepEqual(color.hexToRgb('#0fa'), {r: 0,g: 255,b: 170});
|
||||||
t.deepEqual(color.hexToRgb('#00ffaa'), {r:0,g:255,b:170});
|
t.deepEqual(color.hexToRgb('#00ffaa'), {r: 0,g: 255,b: 170});
|
||||||
|
|
||||||
t.deepEqual(color.hexToRgb('000'), {r:0,g:0,b:0});
|
t.deepEqual(color.hexToRgb('000'), {r: 0,g: 0,b: 0});
|
||||||
t.deepEqual(color.hexToRgb('fff'), {r:255,g:255,b:255});
|
t.deepEqual(color.hexToRgb('fff'), {r: 255,g: 255,b: 255});
|
||||||
t.deepEqual(color.hexToRgb('00ffaa'), {r:0,g:255,b:170});
|
t.deepEqual(color.hexToRgb('00ffaa'), {r: 0,g: 255,b: 170});
|
||||||
|
|
||||||
t.deepEqual(color.hexToRgb('0'), null);
|
t.deepEqual(color.hexToRgb('0'), null);
|
||||||
t.deepEqual(color.hexToRgb('hello world'), null);
|
t.deepEqual(color.hexToRgb('hello world'), null);
|
||||||
|
@ -38,16 +38,16 @@ test('hexToRgb', function (t) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('rgbToHex', function (t) {
|
test('rgbToHex', function (t) {
|
||||||
t.strictEqual(color.rgbToHex({r:0,g:0,b:0}), '#000000');
|
t.strictEqual(color.rgbToHex({r: 0,g: 0,b: 0}), '#000000');
|
||||||
t.strictEqual(color.rgbToHex({r:255,g:255,b:255}), '#ffffff');
|
t.strictEqual(color.rgbToHex({r: 255,g: 255,b: 255}), '#ffffff');
|
||||||
t.strictEqual(color.rgbToHex({r:0,g:255,b:170}), '#00ffaa');
|
t.strictEqual(color.rgbToHex({r: 0,g: 255,b: 170}), '#00ffaa');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('rgbToDecimal', function (t) {
|
test('rgbToDecimal', function (t) {
|
||||||
t.strictEqual(color.rgbToDecimal({r:0,g:0,b:0}), 0);
|
t.strictEqual(color.rgbToDecimal({r: 0,g: 0,b: 0}), 0);
|
||||||
t.strictEqual(color.rgbToDecimal({r:255,g:255,b:255}), 16777215);
|
t.strictEqual(color.rgbToDecimal({r: 255,g: 255,b: 255}), 16777215);
|
||||||
t.strictEqual(color.rgbToDecimal({r:0,g:255,b:170}), 65450);
|
t.strictEqual(color.rgbToDecimal({r: 0,g: 255,b: 170}), 65450);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue