mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Removed global documentCreated
This commit is contained in:
parent
404b1c56c1
commit
da7ae65ead
@ -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();
|
||||
}
|
||||
|
@ -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();});
|
||||
|
||||
|
@ -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
|
||||
|
@ -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") {
|
||||
|
@ -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
|
||||
}
|
||||
})();
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user