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() {
|
2022-02-23 19:16:23 +03:00
|
|
|
//console.info("Initializing presets..");
|
2021-06-29 02:54:54 +03:00
|
|
|
// 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', () => {
|
2022-02-23 19:16:23 +03:00
|
|
|
////console.log("Preset: " + presetName);
|
2021-06-29 02:54:54 +03:00
|
|
|
//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
|
2021-07-10 12:05:56 +03:00
|
|
|
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
|
2021-07-10 12:05:56 +03:00
|
|
|
Util.deselect('palette-button');
|
|
|
|
Util.deselect('palette-menu');
|
2021-06-29 02:54:54 +03:00
|
|
|
|
|
|
|
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
|
|
|
})();
|