Skip to content

Commit a362819

Browse files
committed
Implement loading a palette from the menu.
1 parent c08c7f2 commit a362819

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

js/ColorModule.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,12 @@ const ColorModule = (() => {
388388
*
389389
* @param {*} paletteColors The colours of the palette
390390
*/
391-
function createColorPalette(paletteColors) {
391+
function createColorPalette(paletteColors, clearCurrent=true) {
392392
//remove current palette
393-
while (colorsMenu.childElementCount > 1)
394-
colorsMenu.children[0].remove();
393+
if (clearCurrent) {
394+
while (colorsMenu.childElementCount > 1)
395+
colorsMenu.children[0].remove();
396+
}
395397

396398
var lightestColor = new Color("hex", '#000000');
397399
var darkestColor = new Color("hex", '#ffffff');
@@ -527,4 +529,4 @@ const ColorModule = (() => {
527529
updateCurrentColor,
528530
getSelectedColor,
529531
}
530-
})();
532+
})();

js/FileManager.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ const FileManager = (() => {
293293
return JSON.stringify(dictionary);
294294
}
295295

296+
let fromMenu = false;
297+
298+
function openImportPaletteWindow() {
299+
fromMenu = true;
300+
document.getElementById('load-palette-browse-holder').click();
301+
}
302+
296303
function loadPalette() {
297304
if (browsePaletteHolder.files && browsePaletteHolder.files[0]) {
298305
let file = browsePaletteHolder.files[0];
@@ -326,12 +333,17 @@ const FileManager = (() => {
326333
}
327334

328335
function addPalette(colors) {
329-
//add to palettes so that it can be loaded when they click okay
330-
palettes['Loaded palette'] = {};
331-
palettes['Loaded palette'].colors = colors;
332-
Util.setText('palette-button', 'Loaded palette');
333-
Util.setText('palette-button-splash', 'Loaded palette');
334-
Util.toggle('palette-menu-splash');
336+
if (fromMenu) {
337+
ColorModule.createColorPalette(colors, clearCurrent=false);
338+
} else {
339+
// From splash screen
340+
// add to palettes so that it can be loaded when they click okay
341+
palettes['Loaded palette'] = {};
342+
palettes['Loaded palette'].colors = colors;
343+
Util.setText('palette-button', 'Loaded palette');
344+
Util.setText('palette-button-splash', 'Loaded palette');
345+
Util.toggle('palette-menu-splash');
346+
}
335347
}
336348

337349
function loadPaletteFromImage(e) {
@@ -587,6 +599,7 @@ const FileManager = (() => {
587599
openPixelExportWindow,
588600
openSaveProjectWindow,
589601
openImportImageWindow,
602+
openImportPaletteWindow,
590603
open
591604
}
592605

js/TopMenuModule.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ const TopMenuModule = (() => {
4646
case 'Import':
4747
Events.on('click', currSubmenuButton, FileManager.openImportImageWindow);
4848
break;
49+
case 'Load palette':
50+
Events.on('click', currSubmenuButton, FileManager.openImportPaletteWindow);
51+
break;
4952
case 'Export':
5053
Events.on('click', currSubmenuButton, FileManager.openPixelExportWindow);
5154
break;
@@ -139,4 +142,4 @@ const TopMenuModule = (() => {
139142
addInfoElement,
140143
resetInfos
141144
}
142-
})();
145+
})();

views/main-menu.hbs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<li><button>Save project</button></li>
88
<li><button>Open</button></li>
99
<li><button>Import</button></li>
10+
<li><button>Load palette</button></li>
1011
<li><button id="export-button" class="disabled">Export</button></li>
1112
<li><a href="https://lospec.com/pixel-editor">Exit</a></li>
1213
</ul>
@@ -74,4 +75,4 @@
7475
<li>{{> checkbox}}</li>
7576
</ul>
7677
</li>
77-
</ul>
78+
</ul>

0 commit comments

Comments
 (0)