pixel-editor/js/_presets.js

60 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-06-29 15:35:17 +03:00
const PresetModule = (() => {
2021-06-27 19:45:32 +03:00
const presets = {
2021-06-29 02:54:54 +03:00
'Gameboy Color': {width: 240, height: 203, palette: 'Gameboy Color'},
'PICO-8': {width: 128, height: 128, palette: 'PICO-8'},
'Commodore 64': {width: 40, height: 80, palette: 'Commodore 64'}
2021-06-27 19:45:32 +03:00
};
2021-06-29 02:54:54 +03:00
function instrumentPresetMenu() {
console.info("Initializing presets..");
// Add a button for all the presets available
const presetsMenu = document.getElementById('preset-menu');
Object.keys(presets).forEach((presetName,) => {
2021-06-27 19:45:32 +03:00
2021-06-29 02:54:54 +03:00
const button = document.createElement('button');
button.appendChild(document.createTextNode(presetName));
2021-06-27 19:45:32 +03:00
2021-06-29 02:54:54 +03:00
presetsMenu.appendChild(button);
2021-06-27 19:45:32 +03:00
2021-06-29 02:54:54 +03:00
button.addEventListener('click', () => {
//change dimentions on new pixel form
Util.setValue('size-width', presets[presetName].width);
Util.setValue('size-height', presets[presetName].height);
2021-06-27 19:45:32 +03:00
2021-06-29 02:54:54 +03:00
//set the text of the dropdown to the newly selected preset
Util.setText('palette-button', presets[presetName].palette);
2021-06-27 19:45:32 +03:00
2021-06-29 02:54:54 +03:00
//hide the dropdown menu
Util.deselect('preset-menu');
Util.deselect('preset-button');
2021-06-27 19:45:32 +03:00
2021-06-29 02:54:54 +03:00
//set the text of the dropdown to the newly selected preset
Util.setText('preset-button', presetName);
});
});
const presetButton = document.getElementById('preset-button');
presetButton.addEventListener('click', (e) => {
//open or close the preset menu
Util.toggle('preset-button');
Util.toggle('preset-menu');
//close the palette menu
Util.deselect('palette-button');
Util.deselect('palette-menu');
e.stopPropagation();
2021-06-27 19:45:32 +03:00
});
2021-06-29 02:54:54 +03:00
}
function propertiesOf(presetId) {
return presets[presetId];
}
return {
propertiesOf,
instrumentPresetMenu
};
2021-06-27 19:45:32 +03:00
})();