moved logic to canvas-controller.js; log cleanup; prep for load/save logic
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user