mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
Merge pull request #670 from rschamp/eslint-config-scratch-4
Update eslint and eslint-config-scratch
This commit is contained in:
commit
f367f2d358
19 changed files with 103 additions and 110 deletions
|
@ -31,8 +31,8 @@
|
||||||
"babel-loader": "^7.0.0",
|
"babel-loader": "^7.0.0",
|
||||||
"babel-preset-es2015": "^6.24.1",
|
"babel-preset-es2015": "^6.24.1",
|
||||||
"copy-webpack-plugin": "4.0.1",
|
"copy-webpack-plugin": "4.0.1",
|
||||||
"eslint": "^3.16.0",
|
"eslint": "^4.5.0",
|
||||||
"eslint-config-scratch": "^3.1.0",
|
"eslint-config-scratch": "^4.0.0",
|
||||||
"expose-loader": "0.7.3",
|
"expose-loader": "0.7.3",
|
||||||
"gh-pages": "^0.12.0",
|
"gh-pages": "^0.12.0",
|
||||||
"got": "5.7.1",
|
"got": "5.7.1",
|
||||||
|
|
|
@ -106,22 +106,7 @@ class Scratch3MotionBlocks {
|
||||||
}
|
}
|
||||||
|
|
||||||
glide (args, util) {
|
glide (args, util) {
|
||||||
if (!util.stackFrame.timer) {
|
if (util.stackFrame.timer) {
|
||||||
// First time: save data for future use.
|
|
||||||
util.stackFrame.timer = new Timer();
|
|
||||||
util.stackFrame.timer.start();
|
|
||||||
util.stackFrame.duration = Cast.toNumber(args.SECS);
|
|
||||||
util.stackFrame.startX = util.target.x;
|
|
||||||
util.stackFrame.startY = util.target.y;
|
|
||||||
util.stackFrame.endX = Cast.toNumber(args.X);
|
|
||||||
util.stackFrame.endY = Cast.toNumber(args.Y);
|
|
||||||
if (util.stackFrame.duration <= 0) {
|
|
||||||
// Duration too short to glide.
|
|
||||||
util.target.setXY(util.stackFrame.endX, util.stackFrame.endY);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
util.yield();
|
|
||||||
} else {
|
|
||||||
const timeElapsed = util.stackFrame.timer.timeElapsed();
|
const timeElapsed = util.stackFrame.timer.timeElapsed();
|
||||||
if (timeElapsed < util.stackFrame.duration * 1000) {
|
if (timeElapsed < util.stackFrame.duration * 1000) {
|
||||||
// In progress: move to intermediate position.
|
// In progress: move to intermediate position.
|
||||||
|
@ -137,6 +122,21 @@ class Scratch3MotionBlocks {
|
||||||
// Finished: move to final position.
|
// Finished: move to final position.
|
||||||
util.target.setXY(util.stackFrame.endX, util.stackFrame.endY);
|
util.target.setXY(util.stackFrame.endX, util.stackFrame.endY);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// First time: save data for future use.
|
||||||
|
util.stackFrame.timer = new Timer();
|
||||||
|
util.stackFrame.timer.start();
|
||||||
|
util.stackFrame.duration = Cast.toNumber(args.SECS);
|
||||||
|
util.stackFrame.startX = util.target.x;
|
||||||
|
util.stackFrame.startY = util.target.y;
|
||||||
|
util.stackFrame.endX = Cast.toNumber(args.X);
|
||||||
|
util.stackFrame.endY = Cast.toNumber(args.Y);
|
||||||
|
if (util.stackFrame.duration <= 0) {
|
||||||
|
// Duration too short to glide.
|
||||||
|
util.target.setXY(util.stackFrame.endX, util.stackFrame.endY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
util.yield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -458,10 +458,7 @@ class Blocks {
|
||||||
`<${tagName}
|
`<${tagName}
|
||||||
id="${block.id}"
|
id="${block.id}"
|
||||||
type="${block.opcode}"
|
type="${block.opcode}"
|
||||||
${block.topLevel ?
|
${block.topLevel ? `x="${block.x}" y="${block.y}"` : ''}
|
||||||
`x="${block.x}" y="${block.y}"` :
|
|
||||||
''
|
|
||||||
}
|
|
||||||
>`;
|
>`;
|
||||||
// Add any mutation. Must come before inputs.
|
// Add any mutation. Must come before inputs.
|
||||||
if (block.mutation) {
|
if (block.mutation) {
|
||||||
|
|
|
@ -86,13 +86,11 @@ const execute = function (sequencer, thread) {
|
||||||
sequencer.retireThread(thread);
|
sequencer.retireThread(thread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!resolvedValue) {
|
||||||
// Not an edge-activated hat: retire the thread
|
// Not an edge-activated hat: retire the thread
|
||||||
// if predicate was false.
|
// if predicate was false.
|
||||||
if (!resolvedValue) {
|
|
||||||
sequencer.retireThread(thread);
|
sequencer.retireThread(thread);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// In a non-hat, report the value visually if necessary if
|
// In a non-hat, report the value visually if necessary if
|
||||||
// at the top of the thread stack.
|
// at the top of the thread stack.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* Object representing a Scratch list.
|
* Object representing a Scratch list.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!string} name Name of the list.
|
* @param {!string} name Name of the list.
|
||||||
* @param {Array} contents Contents of the list, as an array.
|
* @param {Array} contents Contents of the list, as an array.
|
||||||
* @constructor
|
* @constructor
|
||||||
|
|
|
@ -228,14 +228,12 @@ class Sequencer {
|
||||||
const doWarp = definitionBlock.mutation.warp;
|
const doWarp = definitionBlock.mutation.warp;
|
||||||
if (doWarp) {
|
if (doWarp) {
|
||||||
thread.peekStackFrame().warpMode = true;
|
thread.peekStackFrame().warpMode = true;
|
||||||
} else {
|
} else if (isRecursive) {
|
||||||
// In normal-mode threads, yield any time we have a recursive call.
|
// In normal-mode threads, yield any time we have a recursive call.
|
||||||
if (isRecursive) {
|
|
||||||
thread.status = Thread.STATUS_YIELD;
|
thread.status = Thread.STATUS_YIELD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retire a thread in the middle, without considering further blocks.
|
* Retire a thread in the middle, without considering further blocks.
|
||||||
|
|
|
@ -40,10 +40,10 @@ class Mouse {
|
||||||
*/
|
*/
|
||||||
postData (data) {
|
postData (data) {
|
||||||
if (data.x) {
|
if (data.x) {
|
||||||
this._x = data.x - data.canvasWidth / 2;
|
this._x = data.x - (data.canvasWidth / 2);
|
||||||
}
|
}
|
||||||
if (data.y) {
|
if (data.y) {
|
||||||
this._y = data.y - data.canvasHeight / 2;
|
this._y = data.y - (data.canvasHeight / 2);
|
||||||
}
|
}
|
||||||
if (typeof data.isDown !== 'undefined') {
|
if (typeof data.isDown !== 'undefined') {
|
||||||
this._isDown = data.isDown;
|
this._isDown = data.isDown;
|
||||||
|
|
|
@ -60,7 +60,7 @@ const parseScratchObject = function (object, runtime) {
|
||||||
sprite.name = object.name;
|
sprite.name = object.name;
|
||||||
}
|
}
|
||||||
if (object.hasOwnProperty('blocks')) {
|
if (object.hasOwnProperty('blocks')) {
|
||||||
for (let blockId in object.blocks) {
|
for (const blockId in object.blocks) {
|
||||||
blocks.createBlock(object.blocks[blockId]);
|
blocks.createBlock(object.blocks[blockId]);
|
||||||
}
|
}
|
||||||
// console.log(blocks);
|
// console.log(blocks);
|
||||||
|
@ -100,7 +100,7 @@ const parseScratchObject = function (object, runtime) {
|
||||||
const target = sprite.createClone();
|
const target = sprite.createClone();
|
||||||
// Load target properties from JSON.
|
// Load target properties from JSON.
|
||||||
if (object.hasOwnProperty('variables')) {
|
if (object.hasOwnProperty('variables')) {
|
||||||
for (let j in object.variables) {
|
for (const j in object.variables) {
|
||||||
const variable = object.variables[j];
|
const variable = object.variables[j];
|
||||||
const newVariable = new Variable(
|
const newVariable = new Variable(
|
||||||
variable.id,
|
variable.id,
|
||||||
|
|
|
@ -95,7 +95,7 @@ class Cast {
|
||||||
* @return {boolean} True if the argument is all white spaces or null / empty.
|
* @return {boolean} True if the argument is all white spaces or null / empty.
|
||||||
*/
|
*/
|
||||||
static isWhiteSpace (val) {
|
static isWhiteSpace (val) {
|
||||||
return val === null || typeof val === 'string' && val.trim().length === 0;
|
return val === null || (typeof val === 'string' && val.trim().length === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,9 +32,9 @@ class StringUtil {
|
||||||
const index = text.indexOf(separator);
|
const index = text.indexOf(separator);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
return [text.substring(0, index), text.substring(index + 1)];
|
return [text.substring(0, index), text.substring(index + 1)];
|
||||||
} else {
|
|
||||||
return [text, null];
|
|
||||||
}
|
}
|
||||||
|
return [text, null];
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ test('repeat', t => {
|
||||||
// Test harness (mocks `util`)
|
// Test harness (mocks `util`)
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const repeat = 10;
|
const repeat = 10;
|
||||||
var util = {
|
const util = {
|
||||||
stackFrame: Object.create(null),
|
stackFrame: Object.create(null),
|
||||||
startBranch: function () {
|
startBranch: function () {
|
||||||
i++;
|
i++;
|
||||||
|
@ -38,7 +38,7 @@ test('repeatUntil', t => {
|
||||||
// Test harness (mocks `util`)
|
// Test harness (mocks `util`)
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const repeat = 10;
|
const repeat = 10;
|
||||||
var util = {
|
const util = {
|
||||||
stackFrame: Object.create(null),
|
stackFrame: Object.create(null),
|
||||||
startBranch: function () {
|
startBranch: function () {
|
||||||
i++;
|
i++;
|
||||||
|
|
|
@ -75,12 +75,12 @@ test('set and clear effects', t => {
|
||||||
const a = new RenderedTarget(s, r);
|
const a = new RenderedTarget(s, r);
|
||||||
const renderer = new FakeRenderer();
|
const renderer = new FakeRenderer();
|
||||||
a.renderer = renderer;
|
a.renderer = renderer;
|
||||||
for (var effect in a.effects) {
|
for (const effect in a.effects) {
|
||||||
a.setEffect(effect, 1);
|
a.setEffect(effect, 1);
|
||||||
t.equals(a.effects[effect], 1);
|
t.equals(a.effects[effect], 1);
|
||||||
}
|
}
|
||||||
a.clearEffects();
|
a.clearEffects();
|
||||||
for (effect in a.effects) {
|
for (const effect in a.effects) {
|
||||||
t.equals(a.effects[effect], 0);
|
t.equals(a.effects[effect], 0);
|
||||||
}
|
}
|
||||||
t.end();
|
t.end();
|
||||||
|
|
Loading…
Reference in a new issue