2019-03-27 02:20:54 +03:00
|
|
|
//prests
|
|
|
|
var presets = {
|
2020-04-04 10:41:56 +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'
|
|
|
|
}
|
2019-03-27 02:20:54 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
//populate preset list in new pixel menu
|
|
|
|
Object.keys(presets).forEach(function(presetName,index) {
|
2020-04-04 10:41:56 +03:00
|
|
|
|
|
|
|
var presetsMenu = document.getElementById('preset-menu');
|
2019-03-27 02:20:54 +03:00
|
|
|
|
|
|
|
//create button
|
2020-04-04 10:41:56 +03:00
|
|
|
var button = document.createElement('button');
|
2019-03-27 02:20:54 +03:00
|
|
|
button.appendChild(document.createTextNode(presetName));
|
|
|
|
|
2020-04-04 10:41:56 +03:00
|
|
|
//insert new element
|
|
|
|
presetsMenu.appendChild(button);
|
|
|
|
|
|
|
|
//add click event listener
|
|
|
|
on('click', button, function() {
|
|
|
|
|
|
|
|
//change dimentions on new pixel form
|
|
|
|
setValue('size-width', presets[presetName].width);
|
|
|
|
setValue('size-height', presets[presetName].height);
|
2019-03-27 02:20:54 +03:00
|
|
|
|
2020-04-04 10:41:56 +03:00
|
|
|
//set the text of the dropdown to the newly selected preset
|
|
|
|
setText('palette-button', presets[presetName].palette);
|
2019-03-27 02:20:54 +03:00
|
|
|
|
2020-04-04 10:41:56 +03:00
|
|
|
//hide the dropdown menu
|
|
|
|
deselect('preset-menu');
|
|
|
|
deselect('preset-button');
|
2019-03-27 02:20:54 +03:00
|
|
|
|
2020-04-04 10:41:56 +03:00
|
|
|
//set the text of the dropdown to the newly selected preset
|
|
|
|
setText('preset-button', presetName);
|
|
|
|
});
|
2019-03-27 02:20:54 +03:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
on('click', 'preset-button', function (e){
|
2020-04-04 10:41:56 +03:00
|
|
|
//open or close the preset menu
|
|
|
|
toggle('preset-button');
|
|
|
|
toggle('preset-menu');
|
|
|
|
|
|
|
|
//close the palette menu
|
|
|
|
deselect('palette-button');
|
|
|
|
deselect('palette-menu');
|
|
|
|
|
|
|
|
//stop the click from propogating to the parent element
|
|
|
|
e.stopPropagation();
|
2019-03-27 02:20:54 +03:00
|
|
|
});
|