Removed global documentCreated

This commit is contained in:
unsettledgames 2021-07-23 19:05:33 +02:00
parent 404b1c56c1
commit da7ae65ead
8 changed files with 17 additions and 16 deletions

View File

@ -42,7 +42,7 @@ const Dialogue = (() => {
document.getElementById(dialogueName).style.display = 'block'; document.getElementById(dialogueName).style.display = 'block';
// If I'm opening the palette window, I initialize the colour picker // If I'm opening the palette window, I initialize the colour picker
if (dialogueName == 'palette-block' && documentCreated) { if (dialogueName == 'palette-block' && Startup.documentCreated()) {
cpInit(); cpInit();
pbInit(); pbInit();
} }

View File

@ -1,6 +1,6 @@
const EditorState = (() => { const EditorState = (() => {
let pixelEditorMode = "Basic"; let pixelEditorMode = "Basic";
Events.on('click', 'switch-editor-mode-splash', function (e) {toggleMode();}); Events.on('click', 'switch-editor-mode-splash', function (e) {toggleMode();});
Events.on('click', 'switch-mode-button', function (e) {toggleMode();}); Events.on('click', 'switch-mode-button', function (e) {toggleMode();});

View File

@ -36,7 +36,7 @@ const FileManager = (() => {
} }
function exportProject() { function exportProject() {
if (documentCreated) { if (Startup.documentCreated()) {
//create name //create name
var selectedPalette = Util.getText('palette-button'); var selectedPalette = Util.getText('palette-button');
if (selectedPalette != 'Choose a palette...'){ if (selectedPalette != 'Choose a palette...'){
@ -93,7 +93,7 @@ const FileManager = (() => {
function open() { function open() {
//if a document exists //if a document exists
if (documentCreated) { if (Startup.documentCreated()) {
//check if the user wants to overwrite //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?')) if (confirm('Opening a pixel will discard your current one. Are you sure you want to do that?'))
//open file selection dialog //open file selection dialog

View File

@ -61,7 +61,7 @@ const Input = (() => {
//if no document has been created yet, //if no document has been created yet,
//orthere is a dialog box open //orthere is a dialog box open
//ignore hotkeys //ignore hotkeys
if (!documentCreated || Dialogue.isOpen()) return; if (!Startup.documentCreated() || Dialogue.isOpen()) return;
// //
if (e.key === "Escape") { if (e.key === "Escape") {

View File

@ -56,7 +56,6 @@ const Startup = (() => {
// The user is now able to export the Pixel // The user is now able to export the Pixel
document.getElementById('export-button').classList.remove('disabled'); document.getElementById('export-button').classList.remove('disabled');
documentCreated = true;
// This is not the first Pixel anymore // This is not the first Pixel anymore
firstPixel = false; firstPixel = false;
@ -243,14 +242,14 @@ const Startup = (() => {
newPixel(x, y); newPixel(x, y);
} }
function createdFirstPixel() { function documentCreated() {
return firstPixel; return !firstPixel;
} }
return { return {
create, create,
newPixel, newPixel,
newFromTemplate, newFromTemplate,
createdFirstPixel documentCreated
} }
})(); })();

View File

@ -42,7 +42,7 @@ const TopMenuModule = (() => {
break; break;
case 'Exit': case 'Exit':
//if a document exists, make sure they want to delete it //if a document exists, make sure they want to delete it
if (documentCreated) { if (Startup.documentCreated()) {
//ask user if they want to leave //ask user if they want to leave
if (confirm('Exiting will discard your current pixel. Are you sure you want to do that?')) if (confirm('Exiting will discard your current pixel. Are you sure you want to do that?'))
//skip onbeforeunload prompt //skip onbeforeunload prompt

View File

@ -8,7 +8,8 @@ window.addEventListener("mousedown", function (mouseEvent) {
canDraw = true; canDraw = true;
//if no document has been created yet, or this is a dialog open, or the currentLayer is locked //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 //prevent right mouse clicks and such, which will open unwanted menus
//mouseEvent.preventDefault(); //mouseEvent.preventDefault();
@ -82,7 +83,8 @@ window.addEventListener("mouseup", function (mouseEvent) {
tmpContext.clearRect(0, 0, tmpCanvas.width, tmpCanvas.height); 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') { if (currentTool.name == 'eyedropper' && mouseEvent.target.className == 'drawingCanvas') {
var cursorLocation = Input.getCursorPosition(mouseEvent); var cursorLocation = Input.getCursorPosition(mouseEvent);
@ -205,7 +207,8 @@ function draw (mouseEvent) {
var cursorLocation = lastMouseMovePos; var cursorLocation = lastMouseMovePos;
//if a document hasnt yet been created or the current layer is locked, exit this function //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 // Moving brush preview
currentTool.moveBrushPreview(cursorLocation); currentTool.moveBrushPreview(cursorLocation);

View File

@ -1,8 +1,7 @@
//init variables //init variables
var canvasSize; // REFACTOR: Canvas class / getCanvasSize method 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 lastMouseClickPos = [0,0]; // REFACTOR: Input IIFE via getter? <- probably editor state as it is changed by tools
var documentCreated = false; // REFACTOR: EditorState
//common elements //common elements
// REFACTOR: put brush and eyedropper preview in the respective tool implementations // REFACTOR: put brush and eyedropper preview in the respective tool implementations
@ -15,7 +14,7 @@ var canvasView = document.getElementById("canvas-view");
// Layers // Layers
// REFACTOR: File class / IIFE? // REFACTOR: File class / IIFE?
var layers = []; var layers = [];
// REFACTOR: EditorState / File class? // REFACTOR: File class?
var currentLayer; var currentLayer;
// VFX layer used to draw previews of the selection and things like that // VFX layer used to draw previews of the selection and things like that