diff --git a/1 - Blockcode/index.html b/1 - Blockcode/index.html index 0a532ea..9dba151 100644 --- a/1 - Blockcode/index.html +++ b/1 - Blockcode/index.html @@ -40,6 +40,7 @@ + diff --git a/1 - Blockcode/resources/js/canvas-controller.js b/1 - Blockcode/resources/js/canvas-controller.js new file mode 100644 index 0000000..1ce907e --- /dev/null +++ b/1 - Blockcode/resources/js/canvas-controller.js @@ -0,0 +1,31 @@ +const resetCanvasState = () => { + resetRotation(); + resetCanvasBrush(); + clearCanvas(); +} + +const resetRotation = () => { Painter.rotation = 0; } +const clearCanvas = () => { Painter.canvasContext.clearRect(0, 0, canvas.width, canvas.height); } + +const resetCanvasBrush = () => { + setDefaultBrushSize(); + setDefaultBrushColor(); + setBrushToCenter(); +} + +const setDefaultBrushSize = () => { + Painter.brushSize = BRUSH_SIZE; + Painter.canvasContext.lineWidth = BRUSH_SIZE; +} + +const setDefaultBrushColor = () => { + Painter.brushColor = BRUSH_COLOR; + Painter.canvasContext.fillStyle = BRUSH_COLOR; + Painter.canvasContext.strokeStyle = BRUSH_COLOR; +} + +const setBrushToCenter = () => { + Painter.x1 = Painter.canvas.width / 2 + Painter.y1 = Painter.canvas.height / 2 + Painter.canvasContext.moveTo( Painter.x1, Painter.y1 ); +} diff --git a/1 - Blockcode/resources/js/elements.js b/1 - Blockcode/resources/js/elements.js index 4642be0..0ee3d27 100644 --- a/1 - Blockcode/resources/js/elements.js +++ b/1 - Blockcode/resources/js/elements.js @@ -3,11 +3,7 @@ class BaseScriptElement extends HTMLElement { constructor() { super(); } connectedCallback() { - this.innerHTML = ` -
  • - -
  • - `; + this.innerHTML = `
  • `; } action(...args) { console.log("Hello, World!"); } @@ -56,7 +52,6 @@ class RepeatElement extends BaseInputScriptElement { action(Painter) { for (let i = 0; i < this.value; i++) { - console.log(Painter.rotation) for (const elm of this.children) { elm.action(Painter); } diff --git a/1 - Blockcode/resources/js/events.js b/1 - Blockcode/resources/js/events.js index 639d58d..78a2bd3 100644 --- a/1 - Blockcode/resources/js/events.js +++ b/1 - Blockcode/resources/js/events.js @@ -1,6 +1,5 @@ const dragStartHandler = (eve) => { draggedElm = eve.target; - console.debug("Node: ", draggedElm); eve.dataTransfer.setData("text", eve.target.tagName.toLowerCase()); } @@ -38,15 +37,6 @@ clearBttn.onclick = (eve) => { clearCanvas(); } -saveBttn.onclick = (eve) => { - console.log("Save"); -} - -loadBttn.onclick = (eve) => { - console.log("Load"); -} - -runBttn.onclick = (eve) => { - console.log("Run"); - runScript(); -} +saveBttn.onclick = (eve) => { saveScript(); } +loadBttn.onclick = (eve) => { loadScript; } +runBttn.onclick = (eve) => { runScript(); } diff --git a/1 - Blockcode/resources/js/script-runner.js b/1 - Blockcode/resources/js/script-runner.js index 6b8f283..5a49c18 100644 --- a/1 - Blockcode/resources/js/script-runner.js +++ b/1 - Blockcode/resources/js/script-runner.js @@ -4,46 +4,17 @@ const setupScriptRunner = () => { Painter.canvasContext = canvasContext; } +const saveScript = () => { + console.log("Save"); +} + +const loadScript = () => { + console.log("Load"); +} + const runScript = () => { resetCanvasState(); for (const elm of script.children) { elm.action(Painter); } } - -const resetCanvasState = () => { - resetRotation(); - resetCanvasBrush(); - clearCanvas(); -} - -const resetCanvasBrush = () => { - setDefaultBrushSize(); - setDefaultBrushColor(); - setBrushToCenter(); -} - -const setDefaultBrushSize = () => { - Painter.brushSize = BRUSH_SIZE; - Painter.canvasContext.lineWidth = BRUSH_SIZE; -} - -const setDefaultBrushColor = () => { - Painter.brushColor = BRUSH_COLOR; - Painter.canvasContext.fillStyle = BRUSH_COLOR; - Painter.canvasContext.strokeStyle = BRUSH_COLOR; -} - -const setBrushToCenter = () => { - Painter.x1 = Painter.canvas.width / 2 - Painter.y1 = Painter.canvas.height / 2 - Painter.canvasContext.moveTo( Painter.x1, Painter.y1 ); -} - -const clearCanvas = () => { - Painter.canvasContext.clearRect(0, 0, canvas.width, canvas.height); -} - -const resetRotation = () => { - Painter.rotation = 0; -}