From 72ea7510e7de4df703d2dc0dc5a45f9a11125156 Mon Sep 17 00:00:00 2001 From: kushal khare Date: Sat, 28 Nov 2020 19:51:37 +0530 Subject: [PATCH 1/6] adding classes to boundary.js --- js/boundary.js | 158 +++++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 78 deletions(-) diff --git a/js/boundary.js b/js/boundary.js index 0456ed01dd..74e00d4dbd 100644 --- a/js/boundary.js +++ b/js/boundary.js @@ -14,86 +14,88 @@ // trash and hidden. There is a menu button that can be used to // restore trash. -function Boundary() { - this._stage = null; - this._container = null; - - this.setStage = function(stage) { - this._stage = stage; - return this; - }; - - this.resizeEvent = function(scale) {}; - - this.init = function() { - this._container = new createjs.Container(); - this._stage.addChild(this._container); - this._stage.setChildIndex(this._container, 0); - }; - - this.setScale = function(w, h, scale) { - this.destroy(); - this.create(w, h, scale); - }; - - this.destroy = function() { - if (this._container.children.length > 0) { - this._container.removeChild(this._container.children[0]); - } - }; - - this.offScreen = function(x, y) { - return ( - x < this.x || - x > this.x + this.dx || - y < this.y || - y > this.y + this.dy - ); - }; - - this.create = function(w, h, scale) { - this.w = w / scale; - this.x = 55 + 13; - this.dx = this.w - (110 + 26); - - this.h = h / scale; - this.y = 55 + 13; - this.dy = this.h - (55 + 26); - - that = this; - - function __makeBoundary() { - let img = new Image(); - img.onload = function() { - bitmap = new createjs.Bitmap(img); - that._container.addChild(bitmap); - }; - - img.src = - "data:image/svg+xml;base64," + - window.btoa( - unescape( - encodeURIComponent( - BOUNDARY.replace("HEIGHT", that.h) - .replace("WIDTH", that.w) - .replace("Y", that.y) - .replace("X", that.x) - .replace("DY", that.dy) - .replace("DX", that.dx) - .replace("stroke_color", "#e08080") +class Boundary { + constructor() { + this._stage = null; + this._container = null; + + this.setStage = function(stage) { + this._stage = stage; + return this; + }; + + this.resizeEvent = function(scale) {}; + + this.init = function() { + this._container = new createjs.Container(); + this._stage.addChild(this._container); + this._stage.setChildIndex(this._container, 0); + }; + + this.setScale = function(w, h, scale) { + this.destroy(); + this.create(w, h, scale); + }; + + this.destroy = function() { + if (this._container.children.length > 0) { + this._container.removeChild(this._container.children[0]); + } + }; + + this.offScreen = function(x, y) { + return ( + x < this.x || + x > this.x + this.dx || + y < this.y || + y > this.y + this.dy + ); + }; + + this.create = function(w, h, scale) { + this.w = w / scale; + this.x = 55 + 13; + this.dx = this.w - (110 + 26); + + this.h = h / scale; + this.y = 55 + 13; + this.dy = this.h - (55 + 26); + + let that = this; + + function __makeBoundary() { + let img = new Image(); + img.onload = function() { + bitmap = new createjs.Bitmap(img); + that._container.addChild(bitmap); + }; + + img.src = + "data:image/svg+xml;base64," + + window.btoa( + unescape( + encodeURIComponent( + BOUNDARY.replace("HEIGHT", that.h) + .replace("WIDTH", that.w) + .replace("Y", that.y) + .replace("X", that.x) + .replace("DY", that.dy) + .replace("DX", that.dx) + .replace("stroke_color", "#e08080") + ) ) - ) - ); - } + ); + } - __makeBoundary(); - }; + __makeBoundary(); + }; - this.hide = function() { - this._container.visible = false; - }; + this.hide = function() { + this._container.visible = false; + }; - this.show = function() { - this._container.visible = true; - }; + this.show = function() { + this._container.visible = true; + }; + } } From 3852e4a48ac03767c2e759953a7af7fe261b63a6 Mon Sep 17 00:00:00 2001 From: kushal khare Date: Fri, 4 Dec 2020 18:52:20 +0530 Subject: [PATCH 2/6] adding classes to boundary.js --- js/boundary.js | 150 ++++++++++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/js/boundary.js b/js/boundary.js index 74e00d4dbd..54711d20ab 100644 --- a/js/boundary.js +++ b/js/boundary.js @@ -18,84 +18,84 @@ class Boundary { constructor() { this._stage = null; this._container = null; + } - this.setStage = function(stage) { - this._stage = stage; - return this; - }; - - this.resizeEvent = function(scale) {}; - - this.init = function() { - this._container = new createjs.Container(); - this._stage.addChild(this._container); - this._stage.setChildIndex(this._container, 0); - }; - - this.setScale = function(w, h, scale) { - this.destroy(); - this.create(w, h, scale); - }; - - this.destroy = function() { - if (this._container.children.length > 0) { - this._container.removeChild(this._container.children[0]); - } - }; - - this.offScreen = function(x, y) { - return ( - x < this.x || - x > this.x + this.dx || - y < this.y || - y > this.y + this.dy - ); - }; - - this.create = function(w, h, scale) { - this.w = w / scale; - this.x = 55 + 13; - this.dx = this.w - (110 + 26); - - this.h = h / scale; - this.y = 55 + 13; - this.dy = this.h - (55 + 26); - - let that = this; - - function __makeBoundary() { - let img = new Image(); - img.onload = function() { - bitmap = new createjs.Bitmap(img); - that._container.addChild(bitmap); - }; - - img.src = - "data:image/svg+xml;base64," + - window.btoa( - unescape( - encodeURIComponent( - BOUNDARY.replace("HEIGHT", that.h) - .replace("WIDTH", that.w) - .replace("Y", that.y) - .replace("X", that.x) - .replace("DY", that.dy) - .replace("DX", that.dx) - .replace("stroke_color", "#e08080") - ) + setStage = (stage) => { + this._stage = stage; + return this; + }; + + resizeEvent = (scale) => {}; + + init = () => { + this._container = new createjs.Container(); + this._stage.addChild(this._container); + this._stage.setChildIndex(this._container, 0); + }; + + setScale = (w, h, scale) => { + this.destroy(); + this.create(w, h, scale); + }; + + destroy = () => { + if (this._container.children.length > 0) { + this._container.removeChild(this._container.children[0]); + } + }; + + offScreen = (x, y) => { + return ( + x < this.x || + x > this.x + this.dx || + y < this.y || + y > this.y + this.dy + ); + }; + + create = (w, h, scale) => { + this.w = w / scale; + this.x = 55 + 13; + this.dx = this.w - (110 + 26); + + this.h = h / scale; + this.y = 55 + 13; + this.dy = this.h - (55 + 26); + + let that = this; + + const __makeBoundary = () => { + let img = new Image(); + img.onload = function() { + bitmap = new createjs.Bitmap(img); + that._container.addChild(bitmap); + }; + + img.src = + "data:image/svg+xml;base64," + + window.btoa( + unescape( + encodeURIComponent( + BOUNDARY.replace("HEIGHT", that.h) + .replace("WIDTH", that.w) + .replace("Y", that.y) + .replace("X", that.x) + .replace("DY", that.dy) + .replace("DX", that.dx) + .replace("stroke_color", "#e08080") ) - ); - } + ) + ); + } - __makeBoundary(); - }; + __makeBoundary(); + }; - this.hide = function() { - this._container.visible = false; - }; + hide = () => { + this._container.visible = false; + }; - this.show = function() { - this._container.visible = true; - }; - } + show = () => { + this._container.visible = true; + }; } From eced39a98e556418a84415ebab5f21414ccf3089 Mon Sep 17 00:00:00 2001 From: kushal khare Date: Fri, 4 Dec 2020 19:12:09 +0530 Subject: [PATCH 3/6] converting onload to arrow function --- js/boundary.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/boundary.js b/js/boundary.js index 54711d20ab..07eebb0e24 100644 --- a/js/boundary.js +++ b/js/boundary.js @@ -66,7 +66,7 @@ class Boundary { const __makeBoundary = () => { let img = new Image(); - img.onload = function() { + img.onload = () => { bitmap = new createjs.Bitmap(img); that._container.addChild(bitmap); }; From 6fbf4fc658091e956094e2a396cf81f9b127ea56 Mon Sep 17 00:00:00 2001 From: kushal khare Date: Fri, 4 Dec 2020 19:17:31 +0530 Subject: [PATCH 4/6] semantic cleanup --- js/boundary.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/js/boundary.js b/js/boundary.js index 07eebb0e24..1c1ee2f557 100644 --- a/js/boundary.js +++ b/js/boundary.js @@ -23,7 +23,7 @@ class Boundary { setStage = (stage) => { this._stage = stage; return this; - }; + } resizeEvent = (scale) => {}; @@ -31,18 +31,18 @@ class Boundary { this._container = new createjs.Container(); this._stage.addChild(this._container); this._stage.setChildIndex(this._container, 0); - }; + } setScale = (w, h, scale) => { this.destroy(); this.create(w, h, scale); - }; + } destroy = () => { if (this._container.children.length > 0) { this._container.removeChild(this._container.children[0]); } - }; + } offScreen = (x, y) => { return ( @@ -51,7 +51,7 @@ class Boundary { y < this.y || y > this.y + this.dy ); - }; + } create = (w, h, scale) => { this.w = w / scale; @@ -89,13 +89,13 @@ class Boundary { } __makeBoundary(); - }; + } hide = () => { this._container.visible = false; - }; + } show = () => { this._container.visible = true; - }; + } } From 226c76e03af9abb54e6e6dc5fb7e9d1b0b6fc115 Mon Sep 17 00:00:00 2001 From: Anindya Kundu Date: Fri, 4 Dec 2020 19:42:30 +0530 Subject: [PATCH 5/6] Semantic improvements --- js/activity.js | 9 +++------ js/boundary.js | 53 +++++++++++++++++--------------------------------- 2 files changed, 21 insertions(+), 41 deletions(-) diff --git a/js/activity.js b/js/activity.js index 3c1a92df0c..952b45c1fe 100644 --- a/js/activity.js +++ b/js/activity.js @@ -4391,8 +4391,7 @@ function Activity() { .setRefreshCanvas(refreshCanvas) .init(); - // Put the boundary in the turtles container so it scrolls - // with the blocks. + // Put the boundary in the turtles container so it scrolls with the blocks. turtles = new Turtles(); turtles.masterStage = stage; turtles.stage = turtleContainer; @@ -4403,11 +4402,9 @@ function Activity() { turtles.doGrid = _doCartesianPolar; turtles.refreshCanvas = refreshCanvas; - // Put the boundary in the blocks container so it scrolls - // with the blocks. + // Put the boundary in the blocks container so it scrolls with the blocks. - boundary = new Boundary(); - boundary.setStage(blocksContainer).init(); + boundary = new Boundary(blocksContainer); blocks = new Blocks(this); blocks diff --git a/js/boundary.js b/js/boundary.js index 1c1ee2f557..d75e199eb7 100644 --- a/js/boundary.js +++ b/js/boundary.js @@ -15,45 +15,31 @@ // restore trash. class Boundary { - constructor() { - this._stage = null; - this._container = null; - } - - setStage = (stage) => { - this._stage = stage; - return this; - } - - resizeEvent = (scale) => {}; - - init = () => { + constructor(stage) { this._container = new createjs.Container(); + this._stage = stage; this._stage.addChild(this._container); this._stage.setChildIndex(this._container, 0); } - setScale = (w, h, scale) => { + // resizeEvent(scale) {}; + + setScale(w, h, scale) { this.destroy(); this.create(w, h, scale); } - destroy = () => { + destroy() { if (this._container.children.length > 0) { this._container.removeChild(this._container.children[0]); } } - offScreen = (x, y) => { - return ( - x < this.x || - x > this.x + this.dx || - y < this.y || - y > this.y + this.dy - ); + offScreen(x, y) { + return (x < this.x || x > this.x + this.dx || y < this.y || y > this.y + this.dy); } - create = (w, h, scale) => { + create(w, h, scale) { this.w = w / scale; this.x = 55 + 13; this.dx = this.w - (110 + 26); @@ -62,26 +48,23 @@ class Boundary { this.y = 55 + 13; this.dy = this.h - (55 + 26); - let that = this; - const __makeBoundary = () => { let img = new Image(); img.onload = () => { bitmap = new createjs.Bitmap(img); - that._container.addChild(bitmap); + this._container.addChild(bitmap); }; - img.src = "data:image/svg+xml;base64," + window.btoa( unescape( encodeURIComponent( - BOUNDARY.replace("HEIGHT", that.h) - .replace("WIDTH", that.w) - .replace("Y", that.y) - .replace("X", that.x) - .replace("DY", that.dy) - .replace("DX", that.dx) + BOUNDARY.replace("HEIGHT", this.h) + .replace("WIDTH", this.w) + .replace("Y", this.y) + .replace("X", this.x) + .replace("DY", this.dy) + .replace("DX", this.dx) .replace("stroke_color", "#e08080") ) ) @@ -91,11 +74,11 @@ class Boundary { __makeBoundary(); } - hide = () => { + hide() { this._container.visible = false; } - show = () => { + show() { this._container.visible = true; } } From 5c6fb898384d7db575fd7c10468708db4529da17 Mon Sep 17 00:00:00 2001 From: Anindya Kundu Date: Fri, 4 Dec 2020 19:46:59 +0530 Subject: [PATCH 6/6] Format code --- js/boundary.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/boundary.js b/js/boundary.js index d75e199eb7..0a06511193 100644 --- a/js/boundary.js +++ b/js/boundary.js @@ -36,7 +36,7 @@ class Boundary { } offScreen(x, y) { - return (x < this.x || x > this.x + this.dx || y < this.y || y > this.y + this.dy); + return x < this.x || x > this.x + this.dx || y < this.y || y > this.y + this.dy; } create(w, h, scale) { @@ -69,7 +69,7 @@ class Boundary { ) ) ); - } + }; __makeBoundary(); }