mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
Merge remote-tracking branch 'refs/remotes/LLK/develop' into feature/fencing
This commit is contained in:
commit
9aa81d6776
16 changed files with 370 additions and 57 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -14,10 +14,4 @@ npm-*
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
/dist
|
/dist
|
||||||
/playground/assets
|
/playground
|
||||||
/playground/media
|
|
||||||
/playground/scratch-vm.js
|
|
||||||
/playground/scratch-vm.js.map
|
|
||||||
/playground/vendor.js
|
|
||||||
/playground/vendor.js.map
|
|
||||||
/playground/zenburn.css
|
|
||||||
|
|
|
@ -45,6 +45,6 @@
|
||||||
"tap": "10.1.0",
|
"tap": "10.1.0",
|
||||||
"travis-after-all": "1.4.4",
|
"travis-after-all": "1.4.4",
|
||||||
"webpack": "2.2.1",
|
"webpack": "2.2.1",
|
||||||
"webpack-dev-server": "1.16.3"
|
"webpack-dev-server": "2.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ Scratch3ControlBlocks.prototype.stop = function (args, util) {
|
||||||
option === 'other scripts in stage') {
|
option === 'other scripts in stage') {
|
||||||
util.stopOtherTargetThreads();
|
util.stopOtherTargetThreads();
|
||||||
} else if (option === 'this script') {
|
} else if (option === 'this script') {
|
||||||
util.stopThread();
|
util.stopThisScript();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -147,6 +147,7 @@ Scratch3PenBlocks.prototype._updatePenColor = function (penState) {
|
||||||
penState.penAttributes.color4f[0] = rgb.r / 255.0;
|
penState.penAttributes.color4f[0] = rgb.r / 255.0;
|
||||||
penState.penAttributes.color4f[1] = rgb.g / 255.0;
|
penState.penAttributes.color4f[1] = rgb.g / 255.0;
|
||||||
penState.penAttributes.color4f[2] = rgb.b / 255.0;
|
penState.penAttributes.color4f[2] = rgb.b / 255.0;
|
||||||
|
penState.penAttributes.color4f[3] = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -260,6 +261,8 @@ Scratch3PenBlocks.prototype.setPenColorToColor = function (args, util) {
|
||||||
penState.penAttributes.color4f[2] = rgb.b / 255.0;
|
penState.penAttributes.color4f[2] = rgb.b / 255.0;
|
||||||
if (rgb.hasOwnProperty('a')) { // Will there always be an 'a'?
|
if (rgb.hasOwnProperty('a')) { // Will there always be an 'a'?
|
||||||
penState.penAttributes.color4f[3] = rgb.a / 255.0;
|
penState.penAttributes.color4f[3] = rgb.a / 255.0;
|
||||||
|
} else {
|
||||||
|
penState.penAttributes.color4f[3] = 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -135,8 +135,9 @@ Scratch3SoundBlocks.prototype.playNoteForBeats = function (args, util) {
|
||||||
var beats = Cast.toNumber(args.BEATS);
|
var beats = Cast.toNumber(args.BEATS);
|
||||||
var soundState = this._getSoundState(util.target);
|
var soundState = this._getSoundState(util.target);
|
||||||
var inst = soundState.currentInstrument;
|
var inst = soundState.currentInstrument;
|
||||||
|
var vol = soundState.volume;
|
||||||
if (typeof this.runtime.audioEngine === 'undefined') return;
|
if (typeof this.runtime.audioEngine === 'undefined') return;
|
||||||
return this.runtime.audioEngine.playNoteForBeatsWithInst(note, beats, inst);
|
return this.runtime.audioEngine.playNoteForBeatsWithInstAndVol(note, beats, inst, vol);
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3SoundBlocks.prototype.playDrumForBeats = function (args, util) {
|
Scratch3SoundBlocks.prototype.playDrumForBeats = function (args, util) {
|
||||||
|
|
|
@ -183,8 +183,8 @@ var execute = function (sequencer, thread) {
|
||||||
stopOtherTargetThreads: function () {
|
stopOtherTargetThreads: function () {
|
||||||
runtime.stopForTarget(target, thread);
|
runtime.stopForTarget(target, thread);
|
||||||
},
|
},
|
||||||
stopThread: function () {
|
stopThisScript: function () {
|
||||||
sequencer.retireThread(thread);
|
thread.stopThisScript();
|
||||||
},
|
},
|
||||||
startProcedure: function (procedureCode) {
|
startProcedure: function (procedureCode) {
|
||||||
sequencer.stepToProcedure(thread, procedureCode);
|
sequencer.stepToProcedure(thread, procedureCode);
|
||||||
|
|
|
@ -140,6 +140,27 @@ Thread.prototype.popStack = function () {
|
||||||
return this.stack.pop();
|
return this.stack.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pop back down the stack frame until we hit a procedure call or the stack frame is emptied
|
||||||
|
*/
|
||||||
|
Thread.prototype.stopThisScript = function () {
|
||||||
|
var blockID = this.peekStack();
|
||||||
|
while (blockID !== null) {
|
||||||
|
var block = this.target.blocks.getBlock(blockID);
|
||||||
|
if (typeof block !== 'undefined' && block.opcode === 'procedures_callnoreturn') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.popStack();
|
||||||
|
blockID = this.peekStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.stack.length === 0) {
|
||||||
|
// Clean up!
|
||||||
|
this.requestScriptGlowInFrame = false;
|
||||||
|
this.status = Thread.STATUS_DONE;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get top stack item.
|
* Get top stack item.
|
||||||
* @return {?string} Block ID on top of stack.
|
* @return {?string} Block ID on top of stack.
|
||||||
|
|
|
@ -56,7 +56,7 @@ Keyboard.prototype._keyCodeToScratchKey = function (keyCode) {
|
||||||
case 39: return 'right arrow';
|
case 39: return 'right arrow';
|
||||||
case 40: return 'down arrow';
|
case 40: return 'down arrow';
|
||||||
}
|
}
|
||||||
return null;
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
var loadProject = function () {
|
var loadProject = function () {
|
||||||
var id = location.hash.substring(1);
|
var id = location.hash.substring(1);
|
||||||
if (id.length < 1 || !isFinite(id)) {
|
if (id.length < 1 || !isFinite(id)) {
|
||||||
|
@ -83,7 +82,7 @@ window.onload = function() {
|
||||||
var threadexplorer = document.getElementById('threadexplorer');
|
var threadexplorer = document.getElementById('threadexplorer');
|
||||||
var cachedThreadJSON = '';
|
var cachedThreadJSON = '';
|
||||||
var updateThreadExplorer = function (newJSON) {
|
var updateThreadExplorer = function (newJSON) {
|
||||||
if (newJSON != cachedThreadJSON) {
|
if (newJSON !== cachedThreadJSON) {
|
||||||
cachedThreadJSON = newJSON;
|
cachedThreadJSON = newJSON;
|
||||||
threadexplorer.innerHTML = cachedThreadJSON;
|
threadexplorer.innerHTML = cachedThreadJSON;
|
||||||
window.hljs.highlightBlock(threadexplorer);
|
window.hljs.highlightBlock(threadexplorer);
|
||||||
|
@ -125,7 +124,7 @@ window.onload = function() {
|
||||||
var targetOption = document.createElement('option');
|
var targetOption = document.createElement('option');
|
||||||
targetOption.setAttribute('value', data.targetList[i].id);
|
targetOption.setAttribute('value', data.targetList[i].id);
|
||||||
// If target id matches editingTarget id, select it.
|
// If target id matches editingTarget id, select it.
|
||||||
if (data.targetList[i].id == data.editingTarget) {
|
if (data.targetList[i].id === data.editingTarget) {
|
||||||
targetOption.setAttribute('selected', 'selected');
|
targetOption.setAttribute('selected', 'selected');
|
||||||
}
|
}
|
||||||
targetOption.appendChild(
|
targetOption.appendChild(
|
||||||
|
@ -213,7 +212,7 @@ window.onload = function() {
|
||||||
// Feed keyboard events as VM I/O events.
|
// Feed keyboard events as VM I/O events.
|
||||||
document.addEventListener('keydown', function (e) {
|
document.addEventListener('keydown', function (e) {
|
||||||
// Don't capture keys intended for Blockly inputs.
|
// Don't capture keys intended for Blockly inputs.
|
||||||
if (e.target != document && e.target != document.body) {
|
if (e.target !== document && e.target !== document.body) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window.vm.postIOData('keyboard', {
|
window.vm.postIOData('keyboard', {
|
||||||
|
@ -230,7 +229,7 @@ window.onload = function() {
|
||||||
isDown: false
|
isDown: false
|
||||||
});
|
});
|
||||||
// E.g., prevent scroll.
|
// E.g., prevent scroll.
|
||||||
if (e.target != document && e.target != document.body) {
|
if (e.target !== document && e.target !== document.body) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
|
@ -90,6 +90,15 @@ Cast.toRgbColorObject = function (value) {
|
||||||
return color;
|
return color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a Scratch argument is a white space string (or null / empty).
|
||||||
|
* @param {*} val value to check.
|
||||||
|
* @return {boolean} True if the argument is all white spaces or null / empty.
|
||||||
|
*/
|
||||||
|
Cast.isWhiteSpace = function (val) {
|
||||||
|
return val === null || typeof val === 'string' && val.trim().length === 0;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare two values, using Scratch cast, case-insensitive string compare, etc.
|
* Compare two values, using Scratch cast, case-insensitive string compare, etc.
|
||||||
* In Scratch 2.0, this is captured by `interp.compare.`
|
* In Scratch 2.0, this is captured by `interp.compare.`
|
||||||
|
@ -100,6 +109,11 @@ Cast.toRgbColorObject = function (value) {
|
||||||
Cast.compare = function (v1, v2) {
|
Cast.compare = function (v1, v2) {
|
||||||
var n1 = Number(v1);
|
var n1 = Number(v1);
|
||||||
var n2 = Number(v2);
|
var n2 = Number(v2);
|
||||||
|
if (n1 === 0 && Cast.isWhiteSpace(v1)) {
|
||||||
|
n1 = NaN;
|
||||||
|
} else if (n2 === 0 && Cast.isWhiteSpace(v2)) {
|
||||||
|
n2 = NaN;
|
||||||
|
}
|
||||||
if (isNaN(n1) || isNaN(n2)) {
|
if (isNaN(n1) || isNaN(n2)) {
|
||||||
// At least one argument can't be converted to a number.
|
// At least one argument can't be converted to a number.
|
||||||
// Scratch compares strings as case insensitive.
|
// Scratch compares strings as case insensitive.
|
||||||
|
|
|
@ -23,16 +23,35 @@ var Timer = function () {};
|
||||||
*/
|
*/
|
||||||
Timer.prototype.startTime = 0;
|
Timer.prototype.startTime = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable use of self.performance for now as it results in lower performance
|
||||||
|
* However, instancing it like below (caching the self.performance to a local variable) negates most of the issues.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
var USE_PERFORMANCE = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Legacy object to allow for us to call now to get the old style date time (for backwards compatibility)
|
||||||
|
* @deprecated This is only called via the nowObj.now() if no other means is possible...
|
||||||
|
*/
|
||||||
|
var legacyDateCode = {
|
||||||
|
now: function () {
|
||||||
|
return new Date().getTime();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this object to route all time functions through single access points.
|
||||||
|
*/
|
||||||
|
var nowObj = (USE_PERFORMANCE && typeof self !== 'undefined' && self.performance && 'now' in self.performance) ?
|
||||||
|
self.performance : Date.now ? Date : legacyDateCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the currently known absolute time, in ms precision.
|
* Return the currently known absolute time, in ms precision.
|
||||||
* @returns {number} ms elapsed since 1 January 1970 00:00:00 UTC.
|
* @returns {number} ms elapsed since 1 January 1970 00:00:00 UTC.
|
||||||
*/
|
*/
|
||||||
Timer.prototype.time = function () {
|
Timer.prototype.time = function () {
|
||||||
if (Date.now) {
|
return nowObj.now();
|
||||||
return Date.now();
|
|
||||||
} else {
|
|
||||||
return new Date().getTime();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,12 +62,7 @@ Timer.prototype.time = function () {
|
||||||
* @returns {number} ms-scale accurate time relative to other relative times.
|
* @returns {number} ms-scale accurate time relative to other relative times.
|
||||||
*/
|
*/
|
||||||
Timer.prototype.relativeTime = function () {
|
Timer.prototype.relativeTime = function () {
|
||||||
if (typeof self !== 'undefined' &&
|
return nowObj.now();
|
||||||
self.performance && 'now' in self.performance) {
|
|
||||||
return self.performance.now();
|
|
||||||
} else {
|
|
||||||
return this.time();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,15 +70,11 @@ Timer.prototype.relativeTime = function () {
|
||||||
* at the most accurate precision possible.
|
* at the most accurate precision possible.
|
||||||
*/
|
*/
|
||||||
Timer.prototype.start = function () {
|
Timer.prototype.start = function () {
|
||||||
this.startTime = this.relativeTime();
|
this.startTime = nowObj.now();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Check time elapsed since `timer.start` was called.
|
|
||||||
* @returns {number} Time elapsed, in ms (possibly sub-ms precision).
|
|
||||||
*/
|
|
||||||
Timer.prototype.timeElapsed = function () {
|
Timer.prototype.timeElapsed = function () {
|
||||||
return this.relativeTime() - this.startTime;
|
return nowObj.now() - this.startTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Timer;
|
module.exports = Timer;
|
||||||
|
|
|
@ -104,7 +104,7 @@ test('stop', function (t) {
|
||||||
var state = {
|
var state = {
|
||||||
stopAll: 0,
|
stopAll: 0,
|
||||||
stopOtherTargetThreads: 0,
|
stopOtherTargetThreads: 0,
|
||||||
stopThread: 0
|
stopThisScript: 0
|
||||||
};
|
};
|
||||||
var util = {
|
var util = {
|
||||||
stopAll: function () {
|
stopAll: function () {
|
||||||
|
@ -113,8 +113,8 @@ test('stop', function (t) {
|
||||||
stopOtherTargetThreads: function () {
|
stopOtherTargetThreads: function () {
|
||||||
state.stopOtherTargetThreads++;
|
state.stopOtherTargetThreads++;
|
||||||
},
|
},
|
||||||
stopThread: function () {
|
stopThisScript: function () {
|
||||||
state.stopThread++;
|
state.stopThisScript++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -125,6 +125,6 @@ test('stop', function (t) {
|
||||||
c.stop({STOP_OPTION: 'this script'}, util);
|
c.stop({STOP_OPTION: 'this script'}, util);
|
||||||
t.strictEqual(state.stopAll, 1);
|
t.strictEqual(state.stopAll, 1);
|
||||||
t.strictEqual(state.stopOtherTargetThreads, 2);
|
t.strictEqual(state.stopOtherTargetThreads, 2);
|
||||||
t.strictEqual(state.stopThread, 1);
|
t.strictEqual(state.stopThisScript, 1);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,277 @@
|
||||||
var test = require('tap').test;
|
var test = require('tap').test;
|
||||||
var Thread = require('../../src/engine/thread');
|
var Thread = require('../../src/engine/thread');
|
||||||
|
var RenderedTarget = require('../../src/sprites/rendered-target');
|
||||||
|
var Sprite = require('../../src/sprites/sprite');
|
||||||
|
|
||||||
test('spec', function (t) {
|
test('spec', function (t) {
|
||||||
t.type(Thread, 'function');
|
t.type(Thread, 'function');
|
||||||
// @todo
|
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
t.type(th, 'object');
|
||||||
|
t.ok(th instanceof Thread);
|
||||||
|
t.type(th.pushStack, 'function');
|
||||||
|
t.type(th.reuseStackForNextBlock, 'function');
|
||||||
|
t.type(th.popStack, 'function');
|
||||||
|
t.type(th.stopThisScript, 'function');
|
||||||
|
t.type(th.peekStack, 'function');
|
||||||
|
t.type(th.peekStackFrame, 'function');
|
||||||
|
t.type(th.peekParentStackFrame, 'function');
|
||||||
|
t.type(th.pushReportedValue, 'function');
|
||||||
|
t.type(th.pushParam, 'function');
|
||||||
|
t.type(th.peekStack, 'function');
|
||||||
|
t.type(th.getParam, 'function');
|
||||||
|
t.type(th.atStackTop, 'function');
|
||||||
|
t.type(th.goToNextBlock, 'function');
|
||||||
|
t.type(th.isRecursiveCall, 'function');
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('pushStack', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('popStack', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
t.strictEquals(th.popStack(), 'arbitraryString');
|
||||||
|
t.strictEquals(th.popStack(), undefined);
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('atStackTop', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
th.pushStack('secondString');
|
||||||
|
t.strictEquals(th.atStackTop(), false);
|
||||||
|
th.popStack();
|
||||||
|
t.strictEquals(th.atStackTop(), true);
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('reuseStackForNextBlock', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
th.reuseStackForNextBlock('secondString');
|
||||||
|
t.strictEquals(th.popStack(), 'secondString');
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('peekStackFrame', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
t.strictEquals(th.peekStackFrame().warpMode, false);
|
||||||
|
th.popStack();
|
||||||
|
t.strictEquals(th.peekStackFrame(), null);
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('peekParentStackFrame', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
th.peekStackFrame().warpMode = true;
|
||||||
|
t.strictEquals(th.peekParentStackFrame(), null);
|
||||||
|
th.pushStack('secondString');
|
||||||
|
t.strictEquals(th.peekParentStackFrame().warpMode, true);
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('pushReportedValue', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
th.pushStack('secondString');
|
||||||
|
th.pushReportedValue('value');
|
||||||
|
t.strictEquals(th.peekParentStackFrame().reported.null, 'value');
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('peekStack', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
t.strictEquals(th.peekStack(), 'arbitraryString');
|
||||||
|
th.popStack();
|
||||||
|
t.strictEquals(th.peekStack(), null);
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('PushGetParam', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
th.pushParam('testParam', 'testValue');
|
||||||
|
t.strictEquals(th.peekStackFrame().params.testParam, 'testValue');
|
||||||
|
t.strictEquals(th.getParam('testParam'), 'testValue');
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('goToNextBlock', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
var s = new Sprite();
|
||||||
|
var rt = new RenderedTarget(s, null);
|
||||||
|
var block1 = {fields: Object,
|
||||||
|
id: 'arbitraryString',
|
||||||
|
inputs: Object,
|
||||||
|
STEPS: Object,
|
||||||
|
block: 'fakeBlock',
|
||||||
|
name: 'STEPS',
|
||||||
|
next: 'secondString',
|
||||||
|
opcode: 'motion_movesteps',
|
||||||
|
parent: null,
|
||||||
|
shadow: false,
|
||||||
|
topLevel: true,
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
};
|
||||||
|
var block2 = {fields: Object,
|
||||||
|
id: 'secondString',
|
||||||
|
inputs: Object,
|
||||||
|
STEPS: Object,
|
||||||
|
block: 'fakeBlock',
|
||||||
|
name: 'STEPS',
|
||||||
|
next: null,
|
||||||
|
opcode: 'procedures_callnoreturn',
|
||||||
|
mutation: {proccode: 'fakeCode'},
|
||||||
|
parent: null,
|
||||||
|
shadow: false,
|
||||||
|
topLevel: true,
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
rt.blocks.createBlock(block1);
|
||||||
|
rt.blocks.createBlock(block2);
|
||||||
|
rt.blocks.createBlock(block2);
|
||||||
|
th.target = rt;
|
||||||
|
|
||||||
|
t.strictEquals(th.peekStack(), null);
|
||||||
|
th.pushStack('secondString');
|
||||||
|
t.strictEquals(th.peekStack(), 'secondString');
|
||||||
|
th.goToNextBlock();
|
||||||
|
t.strictEquals(th.peekStack(), null);
|
||||||
|
th.pushStack('secondString');
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
t.strictEquals(th.peekStack(), 'arbitraryString');
|
||||||
|
th.goToNextBlock();
|
||||||
|
t.strictEquals(th.peekStack(), 'secondString');
|
||||||
|
th.goToNextBlock();
|
||||||
|
t.strictEquals(th.peekStack(), null);
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('stopThisScript', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
var s = new Sprite();
|
||||||
|
var rt = new RenderedTarget(s, null);
|
||||||
|
var block1 = {fields: Object,
|
||||||
|
id: 'arbitraryString',
|
||||||
|
inputs: Object,
|
||||||
|
STEPS: Object,
|
||||||
|
block: 'fakeBlock',
|
||||||
|
name: 'STEPS',
|
||||||
|
next: null,
|
||||||
|
opcode: 'motion_movesteps',
|
||||||
|
parent: null,
|
||||||
|
shadow: false,
|
||||||
|
topLevel: true,
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
};
|
||||||
|
var block2 = {fields: Object,
|
||||||
|
id: 'secondString',
|
||||||
|
inputs: Object,
|
||||||
|
STEPS: Object,
|
||||||
|
block: 'fakeBlock',
|
||||||
|
name: 'STEPS',
|
||||||
|
next: null,
|
||||||
|
opcode: 'procedures_callnoreturn',
|
||||||
|
mutation: {proccode: 'fakeCode'},
|
||||||
|
parent: null,
|
||||||
|
shadow: false,
|
||||||
|
topLevel: true,
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
rt.blocks.createBlock(block1);
|
||||||
|
rt.blocks.createBlock(block2);
|
||||||
|
th.target = rt;
|
||||||
|
|
||||||
|
th.stopThisScript();
|
||||||
|
t.strictEquals(th.peekStack(), null);
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
t.strictEquals(th.peekStack(), 'arbitraryString');
|
||||||
|
th.stopThisScript();
|
||||||
|
t.strictEquals(th.peekStack(), null);
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
th.pushStack('secondString');
|
||||||
|
th.stopThisScript();
|
||||||
|
t.strictEquals(th.peekStack(), 'secondString');
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('isRecursiveCall', function (t) {
|
||||||
|
var th = new Thread('arbitraryString');
|
||||||
|
var s = new Sprite();
|
||||||
|
var rt = new RenderedTarget(s, null);
|
||||||
|
var block1 = {fields: Object,
|
||||||
|
id: 'arbitraryString',
|
||||||
|
inputs: Object,
|
||||||
|
STEPS: Object,
|
||||||
|
block: 'fakeBlock',
|
||||||
|
name: 'STEPS',
|
||||||
|
next: null,
|
||||||
|
opcode: 'motion_movesteps',
|
||||||
|
parent: null,
|
||||||
|
shadow: false,
|
||||||
|
topLevel: true,
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
};
|
||||||
|
var block2 = {fields: Object,
|
||||||
|
id: 'secondString',
|
||||||
|
inputs: Object,
|
||||||
|
STEPS: Object,
|
||||||
|
block: 'fakeBlock',
|
||||||
|
name: 'STEPS',
|
||||||
|
next: null,
|
||||||
|
opcode: 'procedures_callnoreturn',
|
||||||
|
mutation: {proccode: 'fakeCode'},
|
||||||
|
parent: null,
|
||||||
|
shadow: false,
|
||||||
|
topLevel: true,
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
rt.blocks.createBlock(block1);
|
||||||
|
rt.blocks.createBlock(block2);
|
||||||
|
th.target = rt;
|
||||||
|
|
||||||
|
t.strictEquals(th.isRecursiveCall('fakeCode'), false);
|
||||||
|
th.pushStack('secondString');
|
||||||
|
t.strictEquals(th.isRecursiveCall('fakeCode'), false);
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
t.strictEquals(th.isRecursiveCall('fakeCode'), true);
|
||||||
|
th.pushStack('arbitraryString');
|
||||||
|
t.strictEquals(th.isRecursiveCall('fakeCode'), true);
|
||||||
|
th.popStack();
|
||||||
|
t.strictEquals(th.isRecursiveCall('fakeCode'), true);
|
||||||
|
th.popStack();
|
||||||
|
t.strictEquals(th.isRecursiveCall('fakeCode'), false);
|
||||||
|
th.popStack();
|
||||||
|
t.strictEquals(th.isRecursiveCall('fakeCode'), false);
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,7 @@ var webpack = require('webpack');
|
||||||
|
|
||||||
var base = {
|
var base = {
|
||||||
devServer: {
|
devServer: {
|
||||||
contentBase: path.resolve(__dirname, 'playground'),
|
contentBase: false,
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
port: process.env.PORT || 8073
|
port: process.env.PORT || 8073
|
||||||
},
|
},
|
||||||
|
@ -108,6 +108,8 @@ module.exports = [
|
||||||
to: 'media'
|
to: 'media'
|
||||||
}, {
|
}, {
|
||||||
from: 'node_modules/highlightjs/styles/zenburn.css'
|
from: 'node_modules/highlightjs/styles/zenburn.css'
|
||||||
|
}, {
|
||||||
|
from: 'src/playground'
|
||||||
}])
|
}])
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue