2021-07-23 19:54:09 +03:00
|
|
|
const EditorState = (() => {
|
|
|
|
let pixelEditorMode = "Basic";
|
2021-07-23 20:05:33 +03:00
|
|
|
|
2021-07-24 13:37:34 +03:00
|
|
|
Events.on('click', 'switch-editor-mode-splash', chooseMode);
|
|
|
|
Events.on('click', 'switch-mode-button', toggleMode);
|
2021-07-23 19:54:09 +03:00
|
|
|
|
|
|
|
function getCurrentMode() {
|
|
|
|
return pixelEditorMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
function switchMode(newMode) {
|
|
|
|
//switch to advanced mode
|
2021-07-24 13:37:34 +03:00
|
|
|
if (newMode == 'Advanced') {
|
2021-07-23 19:54:09 +03:00
|
|
|
// Show the layer menus
|
|
|
|
LayerList.getLayerListEntries().style.display = "inline-block";
|
|
|
|
document.getElementById('layer-button').style.display = 'inline-block';
|
|
|
|
// Hide the palette menu
|
|
|
|
document.getElementById('colors-menu').style.right = '200px'
|
|
|
|
|
|
|
|
pixelEditorMode = 'Advanced';
|
|
|
|
|
|
|
|
//turn pixel grid off
|
|
|
|
togglePixelGrid('off');
|
|
|
|
}
|
|
|
|
//switch to basic mode
|
|
|
|
else {
|
|
|
|
//if there is a current layer (a document is active)
|
2021-07-24 13:37:34 +03:00
|
|
|
if (Startup.documentCreated()) {
|
2021-07-23 19:54:09 +03:00
|
|
|
if (!confirm('Switching to basic mode will flatten all the visible layers. Are you sure you want to continue?')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Selecting the current layer
|
|
|
|
currentLayer.selectLayer();
|
|
|
|
// Flatten the layers
|
|
|
|
LayerList.flatten(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide the layer menus
|
|
|
|
LayerList.getLayerListEntries().style.display = 'none';
|
|
|
|
document.getElementById('layer-button').style.display = 'none';
|
|
|
|
// Show the palette menu
|
|
|
|
document.getElementById('colors-menu').style.display = 'flex';
|
|
|
|
// Move the palette menu
|
|
|
|
document.getElementById('colors-menu').style.right = '0px';
|
2021-07-24 13:37:34 +03:00
|
|
|
|
2021-07-23 19:54:09 +03:00
|
|
|
pixelEditorMode = 'Basic';
|
2021-07-24 13:37:34 +03:00
|
|
|
togglePixelGrid('on');
|
2021-07-23 19:54:09 +03:00
|
|
|
}
|
|
|
|
}
|
2021-07-24 13:37:34 +03:00
|
|
|
|
|
|
|
function chooseMode() {
|
|
|
|
console.log("Here");
|
|
|
|
let prevMode = pixelEditorMode.toLowerCase();
|
|
|
|
|
|
|
|
if (pixelEditorMode === "Basic") {
|
|
|
|
pixelEditorMode = "Advanced";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pixelEditorMode = "Basic";
|
|
|
|
}
|
|
|
|
|
|
|
|
//change splash text
|
|
|
|
document.querySelector('#sp-quickstart-container .mode-switcher').classList.remove(prevMode + '-mode');
|
|
|
|
document.querySelector('#sp-quickstart-container .mode-switcher').classList.add(pixelEditorMode.toLowerCase() + '-mode');
|
|
|
|
}
|
2021-07-23 19:54:09 +03:00
|
|
|
|
|
|
|
function toggleMode() {
|
|
|
|
if (pixelEditorMode == 'Advanced')
|
|
|
|
switchMode('Basic');
|
|
|
|
else
|
|
|
|
switchMode('Advanced');
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
getCurrentMode,
|
|
|
|
switchMode
|
|
|
|
}
|
|
|
|
})();
|