Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .eslintrc

This file was deleted.

3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['scratch', 'scratch/node']

This comment was marked as abuse.

};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@
"version": "./node_modules/.bin/json -f package.json -I -e \"this.repository.sha = '$(git log -n1 --pretty=format:%H)'\""
},
"devDependencies": {
"babel-eslint": "7.0.0",
"copy-webpack-plugin": "3.0.1",
"eslint": "2.7.0",
"eslint": "3.8.1",
"eslint-config-scratch": "^2.0.0",
"expose-loader": "0.7.1",
"gh-pages": "0.11.0",
"highlightjs": "8.7.0",
"htmlparser2": "3.9.0",
"json": "9.0.4",
"json-loader": "0.5.4",
"lodash.defaultsdeep": "4.6.0",
"minilog": "3.0.1",
"promise": "7.1.1",
"scratch-blocks": "latest",
"scratch-render": "latest",
Expand Down
10 changes: 10 additions & 0 deletions src/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
root: true,
extends: 'scratch',
env: {
browser: true
},
globals: {
Promise: true
}
};
56 changes: 28 additions & 28 deletions src/blocks/scratch3_control.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
var Cast = require('../util/cast');
var Timer = require('../util/timer');

function Scratch3ControlBlocks(runtime) {
var Scratch3ControlBlocks = function (runtime) {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

/**
* The runtime instantiating this block package.
* @type {Runtime}
*/
this.runtime = runtime;
}
};

/**
* Retrieve the block primitives implemented by this package.
* @return {Object.<string, Function>} Mapping of opcode to Function.
*/
Scratch3ControlBlocks.prototype.getPrimitives = function() {
Scratch3ControlBlocks.prototype.getPrimitives = function () {
return {
'control_repeat': this.repeat,
'control_repeat_until': this.repeatUntil,
'control_forever': this.forever,
'control_wait': this.wait,
'control_wait_until': this.waitUntil,
'control_if': this.if,
'control_if_else': this.ifElse,
'control_stop': this.stop,
'control_create_clone_of': this.createClone,
'control_delete_this_clone': this.deleteClone
control_repeat: this.repeat,
control_repeat_until: this.repeatUntil,
control_forever: this.forever,
control_wait: this.wait,
control_wait_until: this.waitUntil,
control_if: this.if,
control_if_else: this.ifElse,
control_stop: this.stop,
control_create_clone_of: this.createClone,
control_delete_this_clone: this.deleteClone
};
};

Scratch3ControlBlocks.prototype.getHats = function () {
return {
'control_start_as_clone': {
control_start_as_clone: {
restartExistingThreads: false
}
};
};

Scratch3ControlBlocks.prototype.repeat = function(args, util) {
Scratch3ControlBlocks.prototype.repeat = function (args, util) {
var times = Math.floor(Cast.toNumber(args.TIMES));
// Initialize loop
if (util.stackFrame.loopCounter === undefined) {
if (typeof util.stackFrame.loopCounter === 'undefined') {

This comment was marked as abuse.

util.stackFrame.loopCounter = times;
}
// Only execute once per frame.
Expand All @@ -53,26 +53,26 @@ Scratch3ControlBlocks.prototype.repeat = function(args, util) {
}
};

Scratch3ControlBlocks.prototype.repeatUntil = function(args, util) {
Scratch3ControlBlocks.prototype.repeatUntil = function (args, util) {
var condition = Cast.toBoolean(args.CONDITION);
// If the condition is true, start the branch.
if (!condition) {
util.startBranch(1, true);
}
};

Scratch3ControlBlocks.prototype.waitUntil = function(args, util) {
Scratch3ControlBlocks.prototype.waitUntil = function (args, util) {
var condition = Cast.toBoolean(args.CONDITION);
if (!condition) {
util.yield();
}
};

Scratch3ControlBlocks.prototype.forever = function(args, util) {
Scratch3ControlBlocks.prototype.forever = function (args, util) {
util.startBranch(1, true);
};

Scratch3ControlBlocks.prototype.wait = function(args, util) {
Scratch3ControlBlocks.prototype.wait = function (args, util) {
if (!util.stackFrame.timer) {
util.stackFrame.timer = new Timer();
util.stackFrame.timer.start();
Expand All @@ -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);
if (condition) {
util.startBranch(1, false);
}
};

Scratch3ControlBlocks.prototype.ifElse = function(args, util) {
Scratch3ControlBlocks.prototype.ifElse = function (args, util) {
var condition = Cast.toBoolean(args.CONDITION);
if (condition) {
util.startBranch(1, false);
Expand All @@ -102,21 +102,21 @@ Scratch3ControlBlocks.prototype.ifElse = function(args, util) {
}
};

Scratch3ControlBlocks.prototype.stop = function(args, util) {
Scratch3ControlBlocks.prototype.stop = function (args, util) {
var option = args.STOP_OPTION;
if (option == 'all') {
if (option === 'all') {

This comment was marked as abuse.

util.stopAll();
} else if (option == 'other scripts in sprite' ||
option == 'other scripts in stage') {
} else if (option === 'other scripts in sprite' ||
option === 'other scripts in stage') {
util.stopOtherTargetThreads();
} else if (option == 'this script') {
} else if (option === 'this script') {
util.stopThread();
}
};

Scratch3ControlBlocks.prototype.createClone = function (args, util) {
var cloneTarget;
if (args.CLONE_OPTION == '_myself_') {
if (args.CLONE_OPTION === '_myself_') {
cloneTarget = util.target;
} else {
cloneTarget = this.runtime.getSpriteTargetByName(args.CLONE_OPTION);
Expand Down
30 changes: 15 additions & 15 deletions src/blocks/scratch3_data.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
var Cast = require('../util/cast');

function Scratch3DataBlocks(runtime) {
var Scratch3DataBlocks = function (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
*/
this.runtime = runtime;
}
};

/**
* Retrieve the block primitives implemented by this package.
* @return {Object.<string, Function>} Mapping of opcode to Function.
*/
Scratch3DataBlocks.prototype.getPrimitives = function () {
return {
'data_variable': this.getVariable,
'data_setvariableto': this.setVariableTo,
'data_changevariableby': this.changeVariableBy,
'data_listcontents': this.getListContents,
'data_addtolist': this.addToList,
'data_deleteoflist': this.deleteOfList,
'data_insertatlist': this.insertAtList,
'data_replaceitemoflist': this.replaceItemOfList,
'data_itemoflist': this.getItemOfList,
'data_lengthoflist': this.lengthOfList,
'data_listcontainsitem': this.listContainsItem
data_variable: this.getVariable,
data_setvariableto: this.setVariableTo,
data_changevariableby: this.changeVariableBy,
data_listcontents: this.getListContents,
data_addtolist: this.addToList,
data_deleteoflist: this.deleteOfList,
data_insertatlist: this.insertAtList,
data_replaceitemoflist: this.replaceItemOfList,
data_itemoflist: this.getItemOfList,
data_lengthoflist: this.lengthOfList,
data_listcontainsitem: this.listContainsItem
};
};

Expand Down Expand Up @@ -54,7 +54,7 @@ Scratch3DataBlocks.prototype.getListContents = function (args, util) {
for (var i = 0; i < list.contents.length; i++) {
var listItem = list.contents[i];
if (!((typeof listItem === 'string') &&
(listItem.length == 1))) {
(listItem.length === 1))) {
allSingleLetters = false;
break;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ Scratch3DataBlocks.prototype.listContainsItem = function (args, util) {
// Try using Scratch comparison operator on each item.
// (Scratch considers the string '123' equal to the number 123).
for (var i = 0; i < list.contents.length; i++) {
if (Cast.compare(list.contents[i], item) == 0) {
if (Cast.compare(list.contents[i], item) === 0) {
return true;
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/blocks/scratch3_event.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
var Cast = require('../util/cast');

function Scratch3EventBlocks(runtime) {
var Scratch3EventBlocks = function (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
*/
this.runtime = runtime;
}
};

/**
* Retrieve the block primitives implemented by this package.
* @return {Object.<string, Function>} Mapping of opcode to Function.
*/
Scratch3EventBlocks.prototype.getPrimitives = function() {
Scratch3EventBlocks.prototype.getPrimitives = function () {
return {
'event_broadcast': this.broadcast,
'event_broadcastandwait': this.broadcastAndWait,
'event_whengreaterthan': this.hatGreaterThanPredicate
event_broadcast: this.broadcast,
event_broadcastandwait: this.broadcastAndWait,
event_whengreaterthan: this.hatGreaterThanPredicate
};
};

Scratch3EventBlocks.prototype.getHats = function () {
return {
'event_whenflagclicked': {
event_whenflagclicked: {
restartExistingThreads: true
},
'event_whenkeypressed': {
event_whenkeypressed: {
restartExistingThreads: false
},
'event_whenthisspriteclicked': {
event_whenthisspriteclicked: {
restartExistingThreads: true
},
'event_whenbackdropswitchesto': {
event_whenbackdropswitchesto: {
restartExistingThreads: true
},
'event_whengreaterthan': {
event_whengreaterthan: {
restartExistingThreads: false,
edgeActivated: true
},
'event_whenbroadcastreceived': {
event_whenbroadcastreceived: {
restartExistingThreads: true
}
};
Expand All @@ -48,16 +48,16 @@ Scratch3EventBlocks.prototype.hatGreaterThanPredicate = function (args, util) {
var option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase();
var value = Cast.toNumber(args.VALUE);
// @todo: Other cases :)
if (option == 'timer') {
if (option === 'timer') {
return util.ioQuery('clock', 'projectTimer') > value;
}
return false;
};

Scratch3EventBlocks.prototype.broadcast = function(args, util) {
Scratch3EventBlocks.prototype.broadcast = function (args, util) {
var broadcastOption = Cast.toString(args.BROADCAST_OPTION);
util.startHats('event_whenbroadcastreceived', {
'BROADCAST_OPTION': broadcastOption
BROADCAST_OPTION: broadcastOption
});
};

Expand All @@ -68,17 +68,17 @@ Scratch3EventBlocks.prototype.broadcastAndWait = function (args, util) {
// No - start hats for this broadcast.
util.stackFrame.startedThreads = util.startHats(
'event_whenbroadcastreceived', {
'BROADCAST_OPTION': broadcastOption
BROADCAST_OPTION: broadcastOption
}
);
if (util.stackFrame.startedThreads.length == 0) {
if (util.stackFrame.startedThreads.length === 0) {
// Nothing was started.
return;
}
}
// We've run before; check if the wait is still going on.
var instance = this;
var waiting = util.stackFrame.startedThreads.some(function(thread) {
var waiting = util.stackFrame.startedThreads.some(function (thread) {
return instance.runtime.isActiveThread(thread);
});
if (waiting) {
Expand Down
Loading