mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
const Settings = (() => {
|
|
let settings;
|
|
let settingsFromCookie;
|
|
|
|
//on clicking the save button in the settings dialog
|
|
Events.on('click', 'save-settings', saveSettings);
|
|
|
|
init();
|
|
|
|
function init() {
|
|
if (!Cookies.enabled) {
|
|
document.getElementById('cookies-disabled-warning').style.display = 'block';
|
|
}
|
|
settingsFromCookie = Cookies.get('pixelEditorSettings');
|
|
|
|
if(!settingsFromCookie) {
|
|
console.log('settings cookie not found');
|
|
|
|
settings = {
|
|
switchToChangedColor: true,
|
|
enableDynamicCursorOutline: true, //unused - performance
|
|
enableBrushPreview: true, //unused - performance
|
|
enableEyedropperPreview: true, //unused - performance
|
|
numberOfHistoryStates: 256,
|
|
maxColorsOnImportedImage: 128,
|
|
pixelGridColour: '#000000',
|
|
hAxisGridColour: '#FF0000',
|
|
vAxisGridColour: '#0000FF',
|
|
};
|
|
}
|
|
else{
|
|
console.log('settings cookie found');
|
|
console.log(settingsFromCookie);
|
|
|
|
settings = JSON.parse(settingsFromCookie);
|
|
}
|
|
}
|
|
|
|
function saveSettings() {
|
|
//check if values are valid
|
|
if (isNaN(Util.getValue('setting-numberOfHistoryStates'))) {
|
|
alert('Invalid value for numberOfHistoryStates');
|
|
return;
|
|
}
|
|
|
|
//save new settings to settings object
|
|
settings.numberOfHistoryStates = Util.getValue('setting-numberOfHistoryStates');
|
|
settings.pixelGridColour = Util.getValue('setting-pixelGridColour');
|
|
settings.hAxisGridColour = Util.getValue('setting-hSymmetryColor');
|
|
settings.vAxisGridColour = Util.getValue('setting-vSymmetryColor');
|
|
// Filling pixel grid again if colour changed
|
|
Events.emit("refreshPixelGrid");
|
|
// Filling symmetric axes again if colour changed
|
|
Events.emit("refreshHorizontalAxis");
|
|
Events.emit("refreshVerticalAxis");
|
|
|
|
//save settings object to cookie
|
|
let cookieValue = JSON.stringify(settings);
|
|
Cookies.set('pixelEditorSettings', cookieValue, { expires: Infinity });
|
|
|
|
//close window
|
|
Dialogue.closeDialogue();
|
|
}
|
|
|
|
function getCurrSettings() {
|
|
return settings;
|
|
}
|
|
|
|
return {
|
|
getCurrSettings
|
|
}
|
|
|
|
})(); |