Skip to content

Commit

Permalink
Merge pull request #245 from NicDoesCode/244-palette-doesnt-disappear…
Browse files Browse the repository at this point in the history
…-when-you-delete-it

Fixes
  • Loading branch information
NicDoesCode committed Sep 19, 2023
2 parents f6c3d59 + 2298b08 commit fc73524
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions wwwroot/modules/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2115,11 +2115,17 @@ function getPaletteListToSuitTileMapOrTileSetSelection() {
// when we exceed the amount of allowed palettes in the tile map, instead just repeat
// the last selected palette.
const capability = SystemUtil.getGraphicsCapability(getProject().systemType, getTileMap().isSprite ? 'sprite' : 'background');
const tileMap = getTileMap();
const palettes = new Array(capability.totalPaletteSlots);
const paletteList = PaletteListFactory.create();
for (let i = 0; i < palettes.length; i++) {
paletteList.addPalette(getPaletteList().getPaletteById(tileMap.getPalette(i)));
let lastGoodPalette = PaletteFactory.createNewStandardColourPaletteBySystemType(getProject().systemType);
for (let i = 0; i < capability.totalPaletteSlots; i++) {
const paletteId = getTileMap().getPalette(i);
let palette = getPaletteList().getPaletteById(paletteId);
if (palette) {
lastGoodPalette = palette;
} else {
palette = PaletteFactory.createNewStandardColourPaletteBySystemType(getProject().systemType);
}
paletteList.addPalette(palette);
}
return paletteList;
} else {
Expand Down Expand Up @@ -2390,7 +2396,7 @@ function formatForProject() {
enabled: true
});
paletteEditor.setState({
paletteList: PaletteListFactory.create(),
paletteList: project.paletteList,
selectedColourIndex: 0,
displayNative: getUIState().displayNativeColour,
enabled: false
Expand Down Expand Up @@ -3691,6 +3697,7 @@ function paletteDelete(paletteIndex) {
try {

getPaletteList().removeAt(paletteIndex);

if (getPaletteList().length === 0) {
const newPalette = PaletteFactory.createNewStandardColourPalette('New palette', getDefaultPaletteSystemType());
getPaletteList().addPalette(newPalette);
Expand All @@ -3701,6 +3708,13 @@ function paletteDelete(paletteIndex) {

state.saveToLocalStorage();

paletteEditor.setState({
paletteList: getPaletteList()
});
tileManager.setState({
paletteList: getPaletteList()
});

const palette = getPaletteList().getPalette(paletteIndex);
changePalette(palette.paletteId);

Expand Down Expand Up @@ -4816,7 +4830,6 @@ function changePalette(paletteId) {
function changePaletteIndex(index) {
if (index < 0) index = getPaletteList().length - 1;
if (index >= getPaletteList().length) index = 0;
if (index === getProjectUIState().paletteIndex) return;

getProjectUIState().paletteIndex = index;
state.saveToLocalStorage();
Expand All @@ -4832,8 +4845,6 @@ function changePaletteIndex(index) {
paletteList: getPaletteListToSuitTileMapOrTileSetSelection()
});
}

// refreshProjectUI();
}

function getTransparencyIndicies() {
Expand Down

0 comments on commit fc73524

Please sign in to comment.