From da7ae65eadaead38ad2ea7037fb9cea85f82299b Mon Sep 17 00:00:00 2001 From: unsettledgames <47360416+unsettledgames@users.noreply.github.com> Date: Fri, 23 Jul 2021 19:05:33 +0200 Subject: [PATCH] Removed global documentCreated --- js/Dialogue.js | 2 +- js/EditorState.js | 2 +- js/FileManager.js | 4 ++-- js/Input.js | 2 +- js/Startup.js | 7 +++---- js/TopMenuModule.js | 2 +- js/_mouseEvents.js | 9 ++++++--- js/_variables.js | 5 ++--- 8 files changed, 17 insertions(+), 16 deletions(-) diff --git a/js/Dialogue.js b/js/Dialogue.js index 726d7f8..19d7386 100644 --- a/js/Dialogue.js +++ b/js/Dialogue.js @@ -42,7 +42,7 @@ const Dialogue = (() => { document.getElementById(dialogueName).style.display = 'block'; // If I'm opening the palette window, I initialize the colour picker - if (dialogueName == 'palette-block' && documentCreated) { + if (dialogueName == 'palette-block' && Startup.documentCreated()) { cpInit(); pbInit(); } diff --git a/js/EditorState.js b/js/EditorState.js index 5dd7f46..b6bfdbb 100644 --- a/js/EditorState.js +++ b/js/EditorState.js @@ -1,6 +1,6 @@ const EditorState = (() => { let pixelEditorMode = "Basic"; - + Events.on('click', 'switch-editor-mode-splash', function (e) {toggleMode();}); Events.on('click', 'switch-mode-button', function (e) {toggleMode();}); diff --git a/js/FileManager.js b/js/FileManager.js index d1a3c28..c3582b9 100644 --- a/js/FileManager.js +++ b/js/FileManager.js @@ -36,7 +36,7 @@ const FileManager = (() => { } function exportProject() { - if (documentCreated) { + if (Startup.documentCreated()) { //create name var selectedPalette = Util.getText('palette-button'); if (selectedPalette != 'Choose a palette...'){ @@ -93,7 +93,7 @@ const FileManager = (() => { function open() { //if a document exists - if (documentCreated) { + if (Startup.documentCreated()) { //check if the user wants to overwrite if (confirm('Opening a pixel will discard your current one. Are you sure you want to do that?')) //open file selection dialog diff --git a/js/Input.js b/js/Input.js index 91f9349..059467d 100644 --- a/js/Input.js +++ b/js/Input.js @@ -61,7 +61,7 @@ const Input = (() => { //if no document has been created yet, //orthere is a dialog box open //ignore hotkeys - if (!documentCreated || Dialogue.isOpen()) return; + if (!Startup.documentCreated() || Dialogue.isOpen()) return; // if (e.key === "Escape") { diff --git a/js/Startup.js b/js/Startup.js index 1e159aa..49b54d3 100644 --- a/js/Startup.js +++ b/js/Startup.js @@ -56,7 +56,6 @@ const Startup = (() => { // The user is now able to export the Pixel document.getElementById('export-button').classList.remove('disabled'); - documentCreated = true; // This is not the first Pixel anymore firstPixel = false; @@ -243,14 +242,14 @@ const Startup = (() => { newPixel(x, y); } - function createdFirstPixel() { - return firstPixel; + function documentCreated() { + return !firstPixel; } return { create, newPixel, newFromTemplate, - createdFirstPixel + documentCreated } })(); \ No newline at end of file diff --git a/js/TopMenuModule.js b/js/TopMenuModule.js index ed4a0f8..5f324c2 100644 --- a/js/TopMenuModule.js +++ b/js/TopMenuModule.js @@ -42,7 +42,7 @@ const TopMenuModule = (() => { break; case 'Exit': //if a document exists, make sure they want to delete it - if (documentCreated) { + if (Startup.documentCreated()) { //ask user if they want to leave if (confirm('Exiting will discard your current pixel. Are you sure you want to do that?')) //skip onbeforeunload prompt diff --git a/js/_mouseEvents.js b/js/_mouseEvents.js index 5eb2e23..963d17f 100644 --- a/js/_mouseEvents.js +++ b/js/_mouseEvents.js @@ -8,7 +8,8 @@ window.addEventListener("mousedown", function (mouseEvent) { canDraw = true; //if no document has been created yet, or this is a dialog open, or the currentLayer is locked - if (!documentCreated || Dialogue.isOpen() || currentLayer.isLocked || !currentLayer.isVisible) return; + if (!Startup.documentCreated() || Dialogue.isOpen() || currentLayer.isLocked || + !currentLayer.isVisible) return; //prevent right mouse clicks and such, which will open unwanted menus //mouseEvent.preventDefault(); @@ -82,7 +83,8 @@ window.addEventListener("mouseup", function (mouseEvent) { tmpContext.clearRect(0, 0, tmpCanvas.width, tmpCanvas.height); } - if (!documentCreated || Dialogue.isOpen() || !currentLayer.isVisible || currentLayer.isLocked) return; + if (!Startup.documentCreated() || Dialogue.isOpen() || !currentLayer.isVisible || + currentLayer.isLocked) return; if (currentTool.name == 'eyedropper' && mouseEvent.target.className == 'drawingCanvas') { var cursorLocation = Input.getCursorPosition(mouseEvent); @@ -205,7 +207,8 @@ function draw (mouseEvent) { var cursorLocation = lastMouseMovePos; //if a document hasnt yet been created or the current layer is locked, exit this function - if (!documentCreated || Dialogue.isOpen() || !currentLayer.isVisible || currentLayer.isLocked) return; + if (!Startup.documentCreated() || Dialogue.isOpen() || !currentLayer.isVisible || + currentLayer.isLocked) return; // Moving brush preview currentTool.moveBrushPreview(cursorLocation); diff --git a/js/_variables.js b/js/_variables.js index 2315591..6fa2220 100644 --- a/js/_variables.js +++ b/js/_variables.js @@ -1,8 +1,7 @@ //init variables var canvasSize; // REFACTOR: Canvas class / getCanvasSize method -var zoom = 7; // REFACTOR: EditorState class/IIFE? +var zoom = 7; // REFACTOR: EditorState class/IIFE? Leave this one for later var lastMouseClickPos = [0,0]; // REFACTOR: Input IIFE via getter? <- probably editor state as it is changed by tools -var documentCreated = false; // REFACTOR: EditorState //common elements // REFACTOR: put brush and eyedropper preview in the respective tool implementations @@ -15,7 +14,7 @@ var canvasView = document.getElementById("canvas-view"); // Layers // REFACTOR: File class / IIFE? var layers = []; -// REFACTOR: EditorState / File class? +// REFACTOR: File class? var currentLayer; // VFX layer used to draw previews of the selection and things like that