Removed a few dependencies, refactored pixel-editor.js

This commit is contained in:
unsettledgames
2021-12-07 12:11:40 +01:00
parent 21dd47c2b0
commit 05beab6929
15 changed files with 94 additions and 121 deletions

View File

@ -1,5 +1,6 @@
const EditorState = (() => {
let pixelEditorMode = "Basic";
let firstFile = true;
Events.on('click', 'switch-editor-mode-splash', chooseMode);
Events.on('click', 'switch-mode-button', toggleMode);
@ -11,35 +12,16 @@ const EditorState = (() => {
function switchMode(newMode) {
//switch to advanced mode
if (newMode == 'Advanced') {
// Show the layer menus
LayerList.getLayerListEntries().style.display = "inline-block";
document.getElementById('layer-button').style.display = 'inline-block';
Events.emit("switchedToAdvanced");
// Hide the palette menu
document.getElementById('colors-menu').style.right = '200px'
pixelEditorMode = 'Advanced';
document.getElementById("switch-mode-button").innerHTML = 'Switch to basic mode';
//turn pixel grid off
currFile.pixelGrid.togglePixelGrid('off');
}
//switch to basic mode
else {
//if there is a current layer (a document is active)
if (Startup.documentCreated()) {
if (!confirm('Switching to basic mode will flatten all the visible layers. Are you sure you want to continue?')) {
return;
}
// Selecting the current layer
currFile.currentLayer.selectLayer();
// Flatten the layers
LayerList.flatten(true);
}
// Hide the layer menus
LayerList.getLayerListEntries().style.display = 'none';
document.getElementById('layer-button').style.display = 'none';
else {
Events.emit("switchedToBasic");
// Show the palette menu
document.getElementById('colors-menu').style.display = 'flex';
// Move the palette menu
@ -47,7 +29,6 @@ const EditorState = (() => {
pixelEditorMode = 'Basic';
document.getElementById("switch-mode-button").innerHTML = 'Switch to advanced mode';
currFile.pixelGrid.togglePixelGrid('on');
}
}
@ -73,8 +54,23 @@ const EditorState = (() => {
switchMode('Advanced');
}
function documentCreated() {
return !firstFile;
}
function firstPixel() {
return firstFile;
}
function created() {
firstFile = false;
}
return {
getCurrentMode,
switchMode
switchMode,
documentCreated,
created,
firstPixel
}
})();