From b6583e4133f4e6ecf1cb4b916336640e10be4d32 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Fri, 2 Aug 2024 21:32:53 +0300 Subject: [PATCH] Fix two bugs with palettes, see description 1) `Palettes`'s `reindex_colors_on_width_increase()` was not changing the `index` of `PaletteColors`, thus resulting in the opened palette itself and the saved file having different indices, which could've caused conflicts with multiple colors sharing the same index, if the user re-arranged the palette after resizing it. 2) If the width was increased but the height increased, the positions of the colors remained the same, which resulted in the colors being in the columns that were removed, to be removed themselves. Now, the colors are taking advantage of the empty space, in order to remove as less as colors as possible. No colors will be removed if the width times the height is equal to or greater than it was before. --- src/Palette/Palette.gd | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Palette/Palette.gd b/src/Palette/Palette.gd index 7062dfade..5d4a969d7 100644 --- a/src/Palette/Palette.gd +++ b/src/Palette/Palette.gd @@ -56,6 +56,7 @@ func _init( func edit(new_name: String, new_width: int, new_height: int, new_comment: String) -> void: var old_width := width + var old_height := height width = new_width height = new_height name = new_name @@ -68,7 +69,7 @@ func edit(new_name: String, new_width: int, new_height: int, new_comment: String # If size was reduced colors must be reindexed to fit into new smaller size reindex_colors_on_size_reduce(true) - if old_width < new_width and colors_max > old_colors_max: + if old_width < new_width and height >= old_height: # If width increases colors have to be reindexed so they keep same grid positions # unless the height has become smaller and we have to re-position the colors # so that they won't get erased @@ -158,12 +159,13 @@ func reindex_colors_on_size_reduce(remove_trailing: bool) -> void: ## Adds difference of old and new width to color indexes ## so they remain on the same position as before resize func reindex_colors_on_width_increase(old_width: int) -> void: - var sorted_colors_indexes := colors.keys() - sorted_colors_indexes.sort() + var sorted_colors_indices := colors.keys() + sorted_colors_indices.sort() var new_colors := {} - for old_index: int in sorted_colors_indexes: + for old_index: int in sorted_colors_indices: var new_index := old_index + (width - old_width) * (old_index / old_width) new_colors[new_index] = colors[old_index] + new_colors[new_index].index = new_index colors = new_colors