Merge pull request #17 from liamortiz/master

IIFE and CSS Fixes
This commit is contained in:
Nicola
2021-06-30 11:23:33 +02:00
committed by GitHub
8 changed files with 2157 additions and 8508 deletions

View File

@@ -1611,22 +1611,38 @@ div#pb-options {
} }
#sp-quickstart-container { #sp-quickstart-container {
height:100%; max-height: 500px;
width:70%; width:70%;
float:right; float:right;
position:relative;
padding:40px; padding:40px;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */ -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */ -moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */ box-sizing: border-box; /* Opera/IE 8+ */
overflow-y: scroll;
&::-webkit-scrollbar {
background: #232125;
width: 0.5em;
}
&::-webkit-scrollbar-track {
margin-top: -0.125em;
width: 0.5em;
}
&::-webkit-scrollbar-thumb {
background: #332f35;
border-radius: 0.25em;
border: solid 0.125em #232125; //same color as scrollbar back to fake padding
}
&::-webkit-scrollbar-corner {
background: #232125;
}
} }
#sp-quickstart { #sp-quickstart {
display:flex; display:flex;
flex-direction: row; flex-direction: row;
flex-wrap: wrap; flex-wrap: wrap;
overflow-y:scroll;
height:100%; height:100%;
// Fancy scrollbar // Fancy scrollbar
@@ -1658,13 +1674,12 @@ div#pb-options {
display: flex; display: flex;
align-items: center; align-items: center;
text-transform: uppercase; text-transform: uppercase;
position:relative;
width:16%; width:16%;
min-width: 100px;
border-radius:5%; border-radius:5%;
margin-right:4%; margin-right:4%;
margin-top:4%; margin-top:4%;
background-color:$basecolor; background-color:$basecolor;
float:left;
font-size: 18px; font-size: 18px;
text-align:center; text-align:center;

35
js/Util.js Normal file
View File

@@ -0,0 +1,35 @@
// Acts as a public static class
class Util {
static getElement(elementOrElementId) {
return typeof elementOrElementId
? document.getElementById(elementOrElementId)
: elementOrElementId;
}
static getText(elementId) {
return this.getElement(elementId).textContent;
}
static setText(elementId, text) {
this.getElement(elementId).textContent = text;
}
static getValue(elementId) {
return this.getElement(elementId).value;
}
static setValue(elementId, value) {
this.getElement(elementId).value = value;
}
//add class .selected to specified element
static select(elementId) {
this.getElement(elementId).classList.add('selected');
}
//remove .selected class from specified element
static deselect(elementId) {
this.getElement(elementId).classList.remove('selected');
}
//toggle the status of the .selected class on the specified element
static toggle(elementId) {
this.getElement(elementId).classList.toggle('selected');
}
}

View File

@@ -209,12 +209,12 @@ function newPixel (width, height, editorMode, fileContent = null) {
function newFromTemplate(preset, x, y) { function newFromTemplate(preset, x, y) {
if (preset != '') { if (preset != '') {
setText('palette-button-splash', presets[preset].palette); const presetProperties = PresetModule.propertiesOf(preset);
setText('palette-button', presets[preset].palette); Util.setText('palette-button-splash', presetProperties.palette);
Util.setText('palette-button', presetProperties.palette);
x = presets[preset].width; x = presetProperties.width;
y = presets[preset].height; y = presetProperties.height;
} }
newPixel(x, y, pixelEditorMode == 'Advanced' ? 'Basic' : 'Advanced'); newPixel(x, y, pixelEditorMode == 'Advanced' ? 'Basic' : 'Advanced');
} }

View File

@@ -1,93 +1,91 @@
//populate palettes list in new pixel menu //populate palettes list in new pixel menu
Object.keys(palettes).forEach(function(paletteName,index) { (() => {
const palettesMenu = document.getElementById('palette-menu');
const splashPalettes = document.getElementById('palette-menu-splash');
const noPaletteButton = document.getElementById('no-palette-button');
const newPixelElement = document.getElementById('new-pixel');
const paletteButton = document.getElementById('palette-button');
const paletteButtonSplash = document.getElementById('palette-button-splash');
const loadPaletteButton = document.getElementById('load-palette-button');
const loadPaletteButtonSplash = document.getElementById('load-palette-button-splash');
var palettesMenu = document.getElementById('palette-menu'); Object.keys(palettes).forEach((paletteName,) => {
var splashPalettes = document.getElementById('palette-menu-splash');
//create button const button = document.createElement('button');
var button = document.createElement('button');
button.appendChild(document.createTextNode(paletteName)); button.appendChild(document.createTextNode(paletteName));
//if the palette was specified by the user, change the dropdown to it //if the palette was specified by the user, change the dropdown to it
if (palettes[paletteName].specified == true) { if (palettes[paletteName].specified) {
setText('palette-button', paletteName); Util.setText('palette-button', paletteName);
setText('palette-button-splash', paletteName) Util.setText('palette-button-splash', paletteName)
//Show empty palette option //Show empty palette option
document.getElementById('no-palette-button').style.display = 'block'; noPaletteButton.style.display = 'block';
} }
var buttonEvent = function() { const buttonEvent = () => {
//hide the dropdown menu //hide the dropdown menu
deselect('palette-menu'); Util.deselect('palette-menu');
deselect('palette-button'); Util.deselect('palette-button');
deselect('palette-menu-splash'); Util.deselect('palette-menu-splash');
deselect('palette-button-splash'); Util.deselect('palette-button-splash');
//show empty palette option //show empty palette option
document.getElementById('no-palette-button').style.display = 'block'; noPaletteButton.style.display = 'block';
//set the text of the dropdown to the newly selected preset //set the text of the dropdown to the newly selected preset
setText('palette-button', paletteName); Util.setText('palette-button', paletteName);
setText('palette-button-splash', paletteName); Util.setText('palette-button-splash', paletteName);
}; }
on('click', button, buttonEvent);
//insert new element
palettesMenu.appendChild(button);
// Making a copy for the splash page too // Making a copy for the splash page too
var copyButton = button.cloneNode(true); const copyButton = button.cloneNode(true);
// Attaching the same event copyButton.addEventListener('click', buttonEvent);
on('click', copyButton, buttonEvent); button.addEventListener('click', buttonEvent);
// Appending it to the splash palette menu // Appending it to the splash palette menu
splashPalettes.appendChild(copyButton); splashPalettes.appendChild(copyButton);
}); palettesMenu.appendChild(button);
});
var noPaletteButtonClickEvent = function () {
document.getElementById('no-palette-button').style.display = 'none';
setText('palette-button', 'Choose a palette...');
}
var loadPaletteButtonEvent = function () { const loadPaletteButtonEvent = () => {
document.getElementById('load-palette-browse-holder').click(); document.getElementById('load-palette-browse-holder').click();
} }
const clickPaletteButtonEvent = (e) => {
Util.toggle('palette-button');
Util.toggle('palette-menu');
var clickPaletteButtonEvent = function (e){ Util.deselect('preset-button');
toggle('palette-button'); Util.deselect('preset-menu');
toggle('palette-menu');
deselect('preset-button');
deselect('preset-menu');
// Splash version // Splash version
toggle('palette-button-splash'); Util.toggle('palette-button-splash');
toggle('palette-menu-splash'); Util.toggle('palette-menu-splash');
e.stopPropagation(); e.stopPropagation();
} }
// Load Palettes
loadPaletteButton.addEventListener('click', loadPaletteButtonEvent);
loadPaletteButtonSplash.addEventListener('click', loadPaletteButtonEvent);
//select no palette // Palette menu click
on('click', 'no-palette-button', noPaletteButtonClickEvent); paletteButtonSplash.addEventListener('click', clickPaletteButtonEvent);
paletteButton.addEventListener('click', clickPaletteButtonEvent);
//select load palette noPaletteButton.addEventListener('click', () => {
on('click', 'load-palette-button', loadPaletteButtonEvent); noPaletteButton.style.display = 'none';
//select load palette Util.setText('palette-button', 'Choose a palette...');
on('click', 'load-palette-button-splash', loadPaletteButtonEvent); })
// Palette menu click newPixelElement.addEventListener('click', () => {
on('click', 'palette-button', clickPaletteButtonEvent); Util.deselect('editor-mode-menu');
on('click', 'palette-button-splash', clickPaletteButtonEvent); Util.deselect('preset-button');
Util.deselect('preset-menu');
on('click', 'new-pixel', function (){ Util.deselect('palette-button');
deselect('editor-mode-menu'); Util.deselect('palette-menu');
deselect('preset-button');
deselect('preset-menu');
deselect('palette-button');
deselect('palette-menu');
// Splash version // Splash version
deselect('palette-button-splash'); Util.deselect('palette-button-splash');
deselect('palette-menu-splash'); Util.deselect('palette-menu-splash');
}); })
})();

View File

@@ -1,63 +1,60 @@
//presets const PresetModule = (() => {
var presets = { const presets = {
'Gameboy Color': { 'Gameboy Color': {width: 240, height: 203, palette: 'Gameboy Color'},
width: 240, 'PICO-8': {width: 128, height: 128, palette: 'PICO-8'},
height: 203, 'Commodore 64': {width: 40, height: 80, palette: 'Commodore 64'}
palette: 'Gameboy Color' };
},
'PICO-8': {
width: 128,
height: 128,
palette: 'PICO-8'
},
'Commodore 64': {
width: 40,
height: 80,
palette: 'Commodore 64'
}
};
//populate preset list in new pixel menu function instrumentPresetMenu() {
Object.keys(presets).forEach(function(presetName,index) { console.info("Initializing presets..");
// Add a button for all the presets available
const presetsMenu = document.getElementById('preset-menu');
Object.keys(presets).forEach((presetName,) => {
var presetsMenu = document.getElementById('preset-menu'); const button = document.createElement('button');
//create button
var button = document.createElement('button');
button.appendChild(document.createTextNode(presetName)); button.appendChild(document.createTextNode(presetName));
//insert new element
presetsMenu.appendChild(button); presetsMenu.appendChild(button);
//add click event listener button.addEventListener('click', () => {
on('click', button, function() {
//change dimentions on new pixel form //change dimentions on new pixel form
setValue('size-width', presets[presetName].width); Util.setValue('size-width', presets[presetName].width);
setValue('size-height', presets[presetName].height); Util.setValue('size-height', presets[presetName].height);
//set the text of the dropdown to the newly selected preset //set the text of the dropdown to the newly selected preset
setText('palette-button', presets[presetName].palette); Util.setText('palette-button', presets[presetName].palette);
//hide the dropdown menu //hide the dropdown menu
deselect('preset-menu'); Util.deselect('preset-menu');
deselect('preset-button'); Util.deselect('preset-button');
//set the text of the dropdown to the newly selected preset //set the text of the dropdown to the newly selected preset
setText('preset-button', presetName); Util.setText('preset-button', presetName);
});
}); });
}); const presetButton = document.getElementById('preset-button');
presetButton.addEventListener('click', (e) => {
on('click', 'preset-button', function (e){
//open or close the preset menu //open or close the preset menu
toggle('preset-button'); Util.toggle('preset-button');
toggle('preset-menu'); Util.toggle('preset-menu');
//close the palette menu //close the palette menu
deselect('palette-button'); Util.deselect('palette-button');
deselect('palette-menu'); Util.deselect('palette-menu');
//stop the click from propogating to the parent element
e.stopPropagation(); e.stopPropagation();
}); });
}
function propertiesOf(presetId) {
return presets[presetId];
}
return {
propertiesOf,
instrumentPresetMenu
};
})();

View File

@@ -14,6 +14,7 @@
//=include _pixelEditorUtility.js //=include _pixelEditorUtility.js
//=include sortable.js //=include sortable.js
//=include _algorithms.js //=include _algorithms.js
//=include Util.js
/**init**/ /**init**/
//=include _consts.js //=include _consts.js
@@ -82,3 +83,6 @@
/**feature toggles**/ /**feature toggles**/
//=include _featureToggles.js //=include _featureToggles.js
// Controls execution of this preset module
PresetModule.instrumentPresetMenu();

10312
package-lock.json generated

File diff suppressed because it is too large Load Diff