pixel-editor/js/Settings.js

70 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-07-23 19:45:23 +03:00
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
2021-12-11 14:48:12 +03:00
numberOfHistoryStates: 256,
2021-07-23 19:45:23 +03:00
maxColorsOnImportedImage: 128,
pixelGridColour: '#000000',
hAxisGridColour: '#FF0000'
2021-07-23 19:45:23 +03:00
};
}
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');
2021-07-23 19:45:23 +03:00
// Filling pixel grid again if colour changed
Events.emit("refreshPixelGrid");
// Filling symmetric axes again if colour changed
Events.emit("refreshHorizontalAxis");
2021-07-23 19:45:23 +03:00
//save settings object to cookie
let cookieValue = JSON.stringify(settings);
2021-07-23 19:45:23 +03:00
Cookies.set('pixelEditorSettings', cookieValue, { expires: Infinity });
//close window
Dialogue.closeDialogue();
}
2021-07-26 00:26:32 +03:00
function getCurrSettings() {
return settings;
}
2021-07-23 19:45:23 +03:00
2021-07-26 00:26:32 +03:00
return {
getCurrSettings
2021-07-23 19:45:23 +03:00
}
2021-07-26 00:26:32 +03:00
2021-07-23 19:45:23 +03:00
})();