Implement loading a palette from the menu.

This commit is contained in:
Theo Cavignac 2022-12-27 18:18:38 +01:00 committed by Théo Cavignac
parent c08c7f2d0b
commit a36281935b
4 changed files with 31 additions and 12 deletions

View File

@ -388,10 +388,12 @@ const ColorModule = (() => {
*
* @param {*} paletteColors The colours of the palette
*/
function createColorPalette(paletteColors) {
function createColorPalette(paletteColors, clearCurrent=true) {
//remove current palette
if (clearCurrent) {
while (colorsMenu.childElementCount > 1)
colorsMenu.children[0].remove();
}
var lightestColor = new Color("hex", '#000000');
var darkestColor = new Color("hex", '#ffffff');

View File

@ -293,6 +293,13 @@ const FileManager = (() => {
return JSON.stringify(dictionary);
}
let fromMenu = false;
function openImportPaletteWindow() {
fromMenu = true;
document.getElementById('load-palette-browse-holder').click();
}
function loadPalette() {
if (browsePaletteHolder.files && browsePaletteHolder.files[0]) {
let file = browsePaletteHolder.files[0];
@ -326,13 +333,18 @@ const FileManager = (() => {
}
function addPalette(colors) {
//add to palettes so that it can be loaded when they click okay
if (fromMenu) {
ColorModule.createColorPalette(colors, clearCurrent=false);
} else {
// From splash screen
// add to palettes so that it can be loaded when they click okay
palettes['Loaded palette'] = {};
palettes['Loaded palette'].colors = colors;
Util.setText('palette-button', 'Loaded palette');
Util.setText('palette-button-splash', 'Loaded palette');
Util.toggle('palette-menu-splash');
}
}
function loadPaletteFromImage(e) {
var img = new Image();
@ -587,6 +599,7 @@ const FileManager = (() => {
openPixelExportWindow,
openSaveProjectWindow,
openImportImageWindow,
openImportPaletteWindow,
open
}

View File

@ -46,6 +46,9 @@ const TopMenuModule = (() => {
case 'Import':
Events.on('click', currSubmenuButton, FileManager.openImportImageWindow);
break;
case 'Load palette':
Events.on('click', currSubmenuButton, FileManager.openImportPaletteWindow);
break;
case 'Export':
Events.on('click', currSubmenuButton, FileManager.openPixelExportWindow);
break;

View File

@ -7,6 +7,7 @@
<li><button>Save project</button></li>
<li><button>Open</button></li>
<li><button>Import</button></li>
<li><button>Load palette</button></li>
<li><button id="export-button" class="disabled">Export</button></li>
<li><a href="https://lospec.com/pixel-editor">Exit</a></li>
</ul>