From 1d7856adc4a391c918477dc3ca4ebbb01f3347c8 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 1 Feb 2021 14:31:38 +0530 Subject: [PATCH 1/3] refractored: turtles.js JSDoc, lint and prettify --- js/turtles.js | 55 +++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/js/turtles.js b/js/turtles.js index 9a0f86ff95..7076048479 100644 --- a/js/turtles.js +++ b/js/turtles.js @@ -33,6 +33,13 @@ const CONTAINERSCALEFACTOR = 4; * This component contains properties and controls relevant to the set * of all turtles like maintaining the canvases on which turtles draw. */ + +/* global createjs, platformColor, last, importMembers, setupRhythmActions, setupMeterActions, setupPitchActions, +setupIntervalsActions, setupToneActions, setupOrnamentActions, setupVolumeActions, setupDrumActions, +setupDictActions, _, Turtle, TURTLESVG, METRONOMESVG, sugarizerCompatibility, FILLCOLORS, STROKECOLORS, getMunsellColor, +DEFAULTVALUE, DEFAULTCHROMA, jQuery, loading, docById, LEADING, CARTESIANBUTTON, piemenuGrid, +CLEARBUTTON, COLLAPSEBUTTON, EXPANDBUTTON, MBOUNDARY */ + class Turtles { /** * @constructor @@ -104,13 +111,13 @@ class Turtles { */ add(startBlock, infoDict) { if (startBlock != null) { - console.debug("adding a new turtle " + startBlock.name); + // console.debug("adding a new turtle " + startBlock.name); if (startBlock.value !== this.turtleList.length) { startBlock.value = this.turtleList.length; - console.debug("turtle #" + startBlock.value); + // console.debug("turtle #" + startBlock.value); } } else { - console.debug("adding a new turtle: startBlock is null"); + // console.debug("adding a new turtle: startBlock is null"); } const blkInfoAvailable = @@ -160,11 +167,11 @@ class Turtles { const scale = this.scale; const offset = { x: turtle.container.x - event.stageX / scale, - y: turtle.container.y - event.stageY / scale, + y: turtle.container.y - event.stageY / scale }; turtlesStage.dispatchEvent("CursorDown" + turtle.id); - console.debug("--> [CursorDown " + turtle.name + "]"); + // console.debug("--> [CursorDown " + turtle.name + "]"); turtle.container.removeAllEventListeners("pressmove"); turtle.container.on("pressmove", (event) => { @@ -180,19 +187,19 @@ class Turtles { }); }); - turtle.container.on("pressup", (event) => { - console.debug("--> [CursorUp " + turtle.name + "]"); + turtle.container.on("pressup", () => { + // console.debug("--> [CursorUp " + turtle.name + "]"); turtlesStage.dispatchEvent("CursorUp" + turtle.id); }); - turtle.container.on("click", (event) => { + turtle.container.on("click", () => { // If turtles listen for clicks then they can be used as buttons - console.debug("--> [click " + turtle.name + "]"); + // console.debug("--> [click " + turtle.name + "]"); turtlesStage.dispatchEvent("click" + turtle.id); }); - turtle.container.on("mouseover", (event) => { - console.debug("--> [mouseover " + turtle.name + "]"); + turtle.container.on("mouseover", () => { + // console.debug("--> [mouseover " + turtle.name + "]"); turtlesStage.dispatchEvent("CursorOver" + turtle.id); if (turtle.running) { @@ -205,8 +212,8 @@ class Turtles { this.refreshCanvas(); }); - turtle.container.on("mouseout", (event) => { - console.debug("--> [mouseout " + turtle.name + "]"); + turtle.container.on("mouseout", () => { + // console.debug("--> [mouseout " + turtle.name + "]"); turtlesStage.dispatchEvent("CursorOut" + turtle.id); if (turtle.running) { @@ -698,11 +705,11 @@ Turtles.TurtlesView = class { let artwork = useTurtleArtwork ? TURTLESVG : METRONOMESVG; artwork = sugarizerCompatibility.isInsideSugarizer() ? artwork - .replace(/fill_color/g, sugarizerCompatibility.xoColor.fill) - .replace(/stroke_color/g, sugarizerCompatibility.xoColor.stroke) + .replace(/fill_color/g, sugarizerCompatibility.xoColor.fill) + .replace(/stroke_color/g, sugarizerCompatibility.xoColor.stroke) : artwork - .replace(/fill_color/g, FILLCOLORS[i]) - .replace(/stroke_color/g, STROKECOLORS[i]); + .replace(/fill_color/g, FILLCOLORS[i]) + .replace(/stroke_color/g, STROKECOLORS[i]); turtle.makeTurtleBitmap(artwork, this.refreshCanvas, useTurtleArtwork); @@ -739,16 +746,16 @@ Turtles.TurtlesView = class { container.setAttribute("data-position", "bottom"); jQuery.noConflict()(".tooltipped").tooltip({ html: true, - delay: 100, + delay: 100 }); - container.onmouseover = (event) => { + container.onmouseover = () => { if (!loading) { document.body.style.cursor = "pointer"; } }; - container.onmouseout = (event) => { + container.onmouseout = () => { if (!loading) { document.body.style.cursor = "default"; } @@ -779,7 +786,7 @@ Turtles.TurtlesView = class { turtlesStage.on("mousedown", (event) => { offset = { y: event.stageY - turtlesStage.y, - x: event.stageX - turtlesStage.x, + x: event.stageX - turtlesStage.x }; }); turtlesStage.on("pressmove", (event) => { @@ -847,7 +854,7 @@ Turtles.TurtlesView = class { 70 + LEADING + 6 ); - this._clearButton.onclick = (event) => { + this._clearButton.onclick = () => { this.doClear(); }; @@ -868,7 +875,7 @@ Turtles.TurtlesView = class { 70 + LEADING + 6 ); - this._collapseButton.onclick = (event) => { + this._collapseButton.onclick = () => { // If the aux toolbar is open, close it. const auxToolbar = docById("aux-toolbar"); if (auxToolbar.style.display === "block") { @@ -899,7 +906,7 @@ Turtles.TurtlesView = class { this._expandButton.style.visibility = "hidden"; } - this._expandButton.onclick = (event) => { + this._expandButton.onclick = () => { // If the aux toolbar is open, close it. const auxToolbar = docById("aux-toolbar"); if (auxToolbar.style.display === "block") { From 1293b6a7440a0b857583ca92457b6e949b097d8e Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 1 Feb 2021 14:39:54 +0530 Subject: [PATCH 2/3] solved indent issue --- js/turtles.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/turtles.js b/js/turtles.js index 7076048479..22320e524c 100644 --- a/js/turtles.js +++ b/js/turtles.js @@ -705,11 +705,11 @@ Turtles.TurtlesView = class { let artwork = useTurtleArtwork ? TURTLESVG : METRONOMESVG; artwork = sugarizerCompatibility.isInsideSugarizer() ? artwork - .replace(/fill_color/g, sugarizerCompatibility.xoColor.fill) - .replace(/stroke_color/g, sugarizerCompatibility.xoColor.stroke) + .replace(/fill_color/g, sugarizerCompatibility.xoColor.fill) + .replace(/stroke_color/g, sugarizerCompatibility.xoColor.stroke) : artwork - .replace(/fill_color/g, FILLCOLORS[i]) - .replace(/stroke_color/g, STROKECOLORS[i]); + .replace(/fill_color/g, FILLCOLORS[i]) + .replace(/stroke_color/g, STROKECOLORS[i]); turtle.makeTurtleBitmap(artwork, this.refreshCanvas, useTurtleArtwork); From 16b1422b1413344796212079d8721685770500bf Mon Sep 17 00:00:00 2001 From: Anindya Kundu Date: Mon, 1 Feb 2021 20:19:25 +0530 Subject: [PATCH 3/3] Format code --- js/turtles.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/js/turtles.js b/js/turtles.js index 22320e524c..81013b1dd5 100644 --- a/js/turtles.js +++ b/js/turtles.js @@ -16,6 +16,17 @@ * Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA. */ +/* + global createjs, platformColor, last, importMembers, setupRhythmActions, setupMeterActions, + setupPitchActions, setupIntervalsActions, setupToneActions, setupOrnamentActions, + setupVolumeActions, setupDrumActions, setupDictActions, _, Turtle, TURTLESVG, METRONOMESVG, + sugarizerCompatibility, FILLCOLORS, STROKECOLORS, getMunsellColor, DEFAULTVALUE, DEFAULTCHROMA, + jQuery, loading, docById, LEADING, CARTESIANBUTTON, piemenuGrid, CLEARBUTTON, COLLAPSEBUTTON, + EXPANDBUTTON, MBOUNDARY + */ + +/* exported Turtles */ + // What is the scale factor when stage is shrunk? const CONTAINERSCALEFACTOR = 4; @@ -33,13 +44,6 @@ const CONTAINERSCALEFACTOR = 4; * This component contains properties and controls relevant to the set * of all turtles like maintaining the canvases on which turtles draw. */ - -/* global createjs, platformColor, last, importMembers, setupRhythmActions, setupMeterActions, setupPitchActions, -setupIntervalsActions, setupToneActions, setupOrnamentActions, setupVolumeActions, setupDrumActions, -setupDictActions, _, Turtle, TURTLESVG, METRONOMESVG, sugarizerCompatibility, FILLCOLORS, STROKECOLORS, getMunsellColor, -DEFAULTVALUE, DEFAULTCHROMA, jQuery, loading, docById, LEADING, CARTESIANBUTTON, piemenuGrid, -CLEARBUTTON, COLLAPSEBUTTON, EXPANDBUTTON, MBOUNDARY */ - class Turtles { /** * @constructor