diff --git a/frontend/src/sections/Palette.svelte b/frontend/src/sections/Palette.svelte
index 843a34b..14d9d27 100644
--- a/frontend/src/sections/Palette.svelte
+++ b/frontend/src/sections/Palette.svelte
@@ -1,6 +1,6 @@
{#if file}
{#each file.canvas.palette as palette, paletteIndex}
-
-
-
-
+ {#if paletteIndex === hoveringIndex || (paletteIndex === hoveringIndex-1 && paletteIndex === file.canvas.palette.length-2)}
+
+
+
+
+ {/if}
+ {#if paletteIndex !== draggingIndex}
+
+
+
+
+ {/if}
{/each}
{/if}
@@ -76,6 +139,7 @@
main {
background-color: var(--cds-background-selected);
text-align: left;
+ user-select: none;
}
.entry {
position: relative;
@@ -86,6 +150,9 @@
padding: 2px;
border: 2px solid transparent;
}
+ .entry.hide {
+ display: none;
+ }
.entry.primary {
border: 2px dashed white;
}
diff --git a/frontend/src/types/canvas.ts b/frontend/src/types/canvas.ts
index c4a0efc..81ce1bf 100644
--- a/frontend/src/types/canvas.ts
+++ b/frontend/src/types/canvas.ts
@@ -181,6 +181,24 @@ export class Canvas {
}
return false
}
+ swapPaletteColors(index1: number, index2: number) {
+ let temp = this.palette[index1]
+ this.palette[index1] = this.palette[index2]
+ this.palette[index2] = temp
+ }
+ movePaletteColor(from: number, to: number) {
+ let temp = this.palette[from]
+ if (from < to) {
+ for (let i = from; i < to; i++) {
+ this.palette[i] = this.palette[i + 1]
+ }
+ } else {
+ for (let i = from; i > to; i--) {
+ this.palette[i] = this.palette[i - 1]
+ }
+ }
+ this.palette[to] = temp
+ }
refreshImageData() {
for (let i = 0; i < this.pixels.length; i++) {
let color = this.palette[this.pixels[i]]
diff --git a/frontend/src/types/file.ts b/frontend/src/types/file.ts
index ba62c32..81edf69 100644
--- a/frontend/src/types/file.ts
+++ b/frontend/src/types/file.ts
@@ -239,4 +239,42 @@ export class AddSwatchUndoable implements Undoable {
unapply(file: LoadedFile) {
file.canvas.removePaletteColor(-1)
}
+}
+
+export class SwapSwatchUndoable implements Undoable {
+ private index1: number
+ private index2: number
+ constructor(index1: number, index2: number) {
+ this.index1 = index1
+ this.index2 = index2
+ }
+ apply(file: LoadedFile) {
+ file.canvas.swapPaletteColors(this.index1, this.index2)
+ file.canvas.refreshImageData()
+ file.canvas.refreshCanvas()
+ }
+ unapply(file: LoadedFile) {
+ file.canvas.swapPaletteColors(this.index2, this.index1)
+ file.canvas.refreshImageData()
+ file.canvas.refreshCanvas()
+ }
+}
+
+export class MoveSwatchUndoable implements Undoable {
+ private index: number
+ private newIndex: number
+ constructor(index: number, newIndex: number) {
+ this.index = index
+ this.newIndex = newIndex
+ }
+ apply(file: LoadedFile) {
+ file.canvas.movePaletteColor(this.index, this.newIndex)
+ file.canvas.refreshImageData()
+ file.canvas.refreshCanvas()
+ }
+ unapply(file: LoadedFile) {
+ file.canvas.movePaletteColor(this.newIndex, this.index)
+ file.canvas.refreshImageData()
+ file.canvas.refreshCanvas()
+ }
}
\ No newline at end of file