2021-07-23 19:54:09 +03:00
|
|
|
const EditorState = (() => {
|
|
|
|
let pixelEditorMode = "Basic";
|
2021-12-07 14:11:40 +03:00
|
|
|
let firstFile = true;
|
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;
|
|
|
|
}
|
|
|
|
|
2022-02-23 19:16:23 +03:00
|
|
|
function switchMode(newMode, skipConfirm = false) {
|
|
|
|
////console.trace();
|
|
|
|
const switchText = 'Switching to basic mode will flatten all the visible layers. Are you sure you want to continue?';
|
|
|
|
if (!firstFile && newMode == "Basic" && !skipConfirm && !confirm(switchText)) {
|
2021-12-08 01:01:49 +03:00
|
|
|
return;
|
|
|
|
}
|
2021-07-23 19:54:09 +03:00
|
|
|
//switch to advanced mode
|
2021-07-24 13:37:34 +03:00
|
|
|
if (newMode == 'Advanced') {
|
2021-12-07 14:11:40 +03:00
|
|
|
Events.emit("switchedToAdvanced");
|
2021-07-23 19:54:09 +03:00
|
|
|
|
|
|
|
pixelEditorMode = 'Advanced';
|
2021-11-12 01:13:15 +03:00
|
|
|
document.getElementById("switch-mode-button").innerHTML = 'Switch to basic mode';
|
2021-07-23 19:54:09 +03:00
|
|
|
}
|
|
|
|
//switch to basic mode
|
2021-12-07 14:11:40 +03:00
|
|
|
else {
|
|
|
|
Events.emit("switchedToBasic");
|
2021-07-23 19:54:09 +03:00
|
|
|
// 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-11-12 01:13:15 +03:00
|
|
|
document.getElementById("switch-mode-button").innerHTML = 'Switch to advanced mode';
|
2021-07-23 19:54:09 +03:00
|
|
|
}
|
|
|
|
}
|
2021-07-24 13:37:34 +03:00
|
|
|
|
|
|
|
function chooseMode() {
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2021-12-07 14:11:40 +03:00
|
|
|
function documentCreated() {
|
|
|
|
return !firstFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
function firstPixel() {
|
|
|
|
return firstFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
function created() {
|
|
|
|
firstFile = false;
|
|
|
|
}
|
|
|
|
|
2021-07-23 19:54:09 +03:00
|
|
|
return {
|
|
|
|
getCurrentMode,
|
2021-12-07 14:11:40 +03:00
|
|
|
switchMode,
|
|
|
|
documentCreated,
|
|
|
|
created,
|
|
|
|
firstPixel
|
2021-07-23 19:54:09 +03:00
|
|
|
}
|
|
|
|
})();
|