Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refractor: prettified the code in js folder #2881

Closed
Closed
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
85 changes: 25 additions & 60 deletions js/blocks/ActionBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function setupActionBlocks() {
const xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", outurl, true);
// Call a function when the state changes.
xmlHttp.onreadystatechange = function() {
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
alert(xmlHttp.responseText);
}
Expand All @@ -85,9 +85,7 @@ function setupActionBlocks() {
super("calc");
this.setPalette("action");
this.setHelpString([
_(
"The Calculate block returns a value calculated by an action."
),
_("The Calculate block returns a value calculated by an action."),
"documentation",
""
]);
Expand Down Expand Up @@ -135,9 +133,7 @@ function setupActionBlocks() {
super("namedcalc");
this.setPalette("action");
this.setHelpString([
_(
"The Calculate block returns a value calculated by an action."
),
_("The Calculate block returns a value calculated by an action."),
"documentation",
""
]);
Expand Down Expand Up @@ -199,11 +195,7 @@ function setupActionBlocks() {
}

if (logo.blocks.blockList[blk].argClampSlots.length > 0) {
for (
let i = 0;
i < logo.blocks.blockList[blk].argClampSlots.length;
i++
) {
for (let i = 0; i < logo.blocks.blockList[blk].argClampSlots.length; i++) {
if (logo.blocks.blockList[blk].connections[i + 1] != null) {
const t = logo.parseArg(
logo,
Expand Down Expand Up @@ -246,7 +238,7 @@ function setupActionBlocks() {
}
}

const __listener = event => tur.singer.backward.pop();
const __listener = (event) => tur.singer.backward.pop();

logo.setTurtleListener(turtle, listenerName, __listener);
} else {
Expand All @@ -265,9 +257,7 @@ function setupActionBlocks() {
super("namedcalcArg");
this.setPalette("action");
this.setHelpString([
_(
"The Calculate block returns a value calculated by an action."
),
_("The Calculate block returns a value calculated by an action."),
"documentation",
""
]);
Expand All @@ -288,11 +278,7 @@ function setupActionBlocks() {
const actionArgs = [];
// logo.getBlockAtStartOfArg(blk);
if (logo.blocks.blockList[blk].argClampSlots.length > 0) {
for (
let i = 0;
i < logo.blocks.blockList[blk].argClampSlots.length;
i++
) {
for (let i = 0; i < logo.blocks.blockList[blk].argClampSlots.length; i++) {
const t = logo.parseArg(
logo,
turtle,
Expand Down Expand Up @@ -350,11 +336,7 @@ function setupActionBlocks() {
}

if (logo.blocks.blockList[blk].argClampSlots.length > 0) {
for (
let i = 0;
i < logo.blocks.blockList[blk].argClampSlots.length;
i++
) {
for (let i = 0; i < logo.blocks.blockList[blk].argClampSlots.length; i++) {
if (logo.blocks.blockList[blk].connections[i + 2] != null) {
const t = logo.parseArg(
logo,
Expand Down Expand Up @@ -388,9 +370,7 @@ function setupActionBlocks() {
super("calcArg");
this.setPalette("action");
this.setHelpString([
_(
"The Calculate block returns a value calculated by an action."
),
_("The Calculate block returns a value calculated by an action."),
"documentation",
""
]);
Expand All @@ -413,11 +393,7 @@ function setupActionBlocks() {
const actionArgs = [];
// logo.getBlockAtStartOfArg(blk);
if (logo.blocks.blockList[blk].argClampSlots.length > 0) {
for (
let i = 0;
i < logo.blocks.blockList[blk].argClampSlots.length;
i++
) {
for (let i = 0; i < logo.blocks.blockList[blk].argClampSlots.length; i++) {
const t = logo.parseArg(
logo,
turtle,
Expand Down Expand Up @@ -458,9 +434,7 @@ function setupActionBlocks() {
super("arg");
this.setPalette("action");
this.setHelpString([
_(
"The Arg block contains the value of an argument passed to an action."
),
_("The Arg block contains the value of an argument passed to an action."),
"documentation",
""
]);
Expand Down Expand Up @@ -500,9 +474,7 @@ function setupActionBlocks() {
super("namedarg");
this.setPalette("action");
this.setHelpString([
_(
"The Arg block contains the value of an argument passed to an action."
),
_("The Arg block contains the value of an argument passed to an action."),
"documentation",
""
]);
Expand Down Expand Up @@ -540,17 +512,15 @@ function setupActionBlocks() {

class DoBlock extends FlowBlock {
constructor() {
//.TRANS: do is the do something or take an action.
//.TRANS: do is the do something or take an action.
super("do");
this.setPalette("action");
this.beginnerBlock(true);

this.setHelpString([
_("The Do block is used to initiate an action.") +
" " +
_(
"In the example, it is used with the One of block to choose a random phase."
),
_("In the example, it is used with the One of block to choose a random phase."),
"documentation",
null,
"dohelp"
Expand Down Expand Up @@ -589,18 +559,14 @@ function setupActionBlocks() {
if (this.lang === "ja") {
this.extraWidth = 15;
this.setHelpString([
_(
"The Listen block is used to listen for an event such as a mouse click."
),
_("The Listen block is used to listen for an event such as a mouse click."),
"documentation",
null,
"broadcasthelp"
]);
} else {
this.setHelpString([
_(
"The Listen block is used to listen for an event such as a mouse click."
) +
_("The Listen block is used to listen for an event such as a mouse click.") +
" " +
_("When the event happens, an action is taken."),
"documentation",
Expand All @@ -615,10 +581,7 @@ function setupActionBlocks() {
args: 2,
argTypes: ["anyin", "anyin"],
//.TRANS: do1 is do (take) an action (JAPANESE ONLY)
argLabels: [
_("event"),
this.lang === "ja" ? _("do1") : _("do")
],
argLabels: [_("event"), this.lang === "ja" ? _("do1") : _("do")],
defaults: [_("event"), _("action")]
});
}
Expand All @@ -631,7 +594,7 @@ function setupActionBlocks() {
} else {
const tur = logo.turtles.ithTurtle(turtle);

const __listener = event => {
const __listener = (event) => {
if (tur.running) {
const queueBlock = new Queue(logo.actions[args[1]], 1, blk);
tur.parentFlowQueue.push(blk);
Expand All @@ -640,7 +603,11 @@ function setupActionBlocks() {
// Since the turtle has stopped running, we must run the stack from here
tur.singer.runningFromEvent = true;
logo.runFromBlockNow(
logo, turtle, logo.actions[args[1]], false, receivedArg
logo,
turtle,
logo.actions[args[1]],
false,
receivedArg
);
}
};
Expand Down Expand Up @@ -737,9 +704,7 @@ function setupActionBlocks() {
"The Action block is used to group together blocks so that they can be used more than once."
) +
" " +
_(
"It is often used for storing a phrase of music that is repeated."
),
_("It is often used for storing a phrase of music that is repeated."),
"documentation",
null,
"actionhelp"
Expand Down Expand Up @@ -823,7 +788,7 @@ function setupActionBlocks() {
}
}

const __listener = event => tur.singer.backward.pop();
const __listener = (event) => tur.singer.backward.pop();

logo.setTurtleListener(turtle, listenerName, __listener);
} else {
Expand Down
2 changes: 1 addition & 1 deletion js/blocks/BooleanBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function setupBooleanBlocks() {
} else {
const a = logo.parseArg(logo, turtle, cblk1, blk, receivedArg);
const b = logo.parseArg(logo, turtle, cblk2, blk, receivedArg);
return ((a && !b)||(!a && b));
return (a && !b) || (!a && b);
}
}
}
Expand Down
41 changes: 10 additions & 31 deletions js/blocks/BoxesBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@ function setupBoxesBlocks() {

if (beginnerMode && this.lang === "ja") {
this.setHelpString([
_(
"The Add-to block is used to add to the value stored in a box."
),
_("The Add-to block is used to add to the value stored in a box."),
"documentation",
""
]);
} else {
this.setHelpString([
_(
"The Add-to block is used to add to the value stored in a box."
) +
_("The Add-to block is used to add to the value stored in a box.") +
" " +
_(
"It can also be used with other blocks such as Color and Pen size."
),
_("It can also be used with other blocks such as Color and Pen size."),
"documentation",
""
]);
Expand All @@ -30,10 +24,7 @@ function setupBoxesBlocks() {
this.formBlock({
name: _("add"),
args: 2,
argLabels: [
_("to"),
this.lang === "ja" ? _("value1") : _("value")
],
argLabels: [_("to"), this.lang === "ja" ? _("value1") : _("value")],
argTypes: ["anyin", "anyin"]
});
}
Expand Down Expand Up @@ -229,8 +220,7 @@ function setupBoxesBlocks() {
const name = logo.blocks.blockList[blk].privateData;
if (
logo.inStatusMatrix &&
logo.blocks.blockList[logo.blocks.blockList[blk].connections[0]]
.name === "print"
logo.blocks.blockList[logo.blocks.blockList[blk].connections[0]].name === "print"
) {
logo.statusFields.push([blk, logo.blocks.blockList[blk].name]);
} else if (!logo.updatingStatusMatrix) {
Expand Down Expand Up @@ -288,10 +278,7 @@ function setupBoxesBlocks() {
argTypes: ["anyin", "anyin"],
defaults: [_("box"), 4],
//.TRANS: name1 is name as in name of box, value1 is value as in the numeric value stored in a box (JAPANESE ONLY)
argLabels:
this.lang === "ja"
? [_("name1"), _("value1")]
: [_("name"), _("value")]
argLabels: this.lang === "ja" ? [_("name1"), _("value1")] : [_("name"), _("value")]
});
}

Expand All @@ -315,9 +302,7 @@ function setupBoxesBlocks() {
]);

this.formBlock({ name: _("box2") });
this.makeMacro((x, y) => [
[0, ["namedbox", { value: "box2" }], x, y, [null]]
]);
this.makeMacro((x, y) => [[0, ["namedbox", { value: "box2" }], x, y, [null]]]);
}
}

Expand All @@ -328,9 +313,7 @@ function setupBoxesBlocks() {
this.beginnerBlock(true);

this.setHelpString([
_(
"The Store in Box2 block is used to store a value in Box2."
),
_("The Store in Box2 block is used to store a value in Box2."),
"documentation",
null,
"box2help"
Expand Down Expand Up @@ -362,9 +345,7 @@ function setupBoxesBlocks() {
]);

this.formBlock({ name: _("box1") });
this.makeMacro((x, y) => [
[0, ["namedbox", { value: "box1" }], x, y, [null]]
]);
this.makeMacro((x, y) => [[0, ["namedbox", { value: "box1" }], x, y, [null]]]);
}
}

Expand All @@ -375,9 +356,7 @@ function setupBoxesBlocks() {
this.beginnerBlock(true);

this.setHelpString([
_(
"The Store in Box1 block is used to store a value in Box1."
),
_("The Store in Box1 block is used to store a value in Box1."),
"documentation",
null,
"box1help"
Expand Down
Loading