diff --git a/src/components/ColourPicker.js b/src/components/ColourPicker.js
new file mode 100644
index 0000000..704165e
--- /dev/null
+++ b/src/components/ColourPicker.js
@@ -0,0 +1,72 @@
+import { useState, useEffect } from 'react';
+import {
+ Popover,
+ PopoverButton,
+ CloseButton,
+ PopoverPanel,
+} from '@headlessui/react';
+import ColourSwatch from './ColourSwatch';
+import { digitalPrimeFbxPalette as colourPalette } from '../lib/palettes';
+import { XMarkIcon } from '@heroicons/react/16/solid';
+import { clsx } from 'clsx';
+import { getLuminosity } from '../lib/paletteUtils';
+
+// ColourPicker uses shades of `neutral` instead of the usual `slate`.
+// This is to avoid the frame to visually pollute the colours.
+
+const ColourPicker = ({ colourId, onPick, children }) => {
+ const [selectedColour, setSelectedColour] = useState(colourId);
+
+ useEffect(() => {
+ setSelectedColour(colourId);
+ }, [colourId]);
+
+ return (
+
+ {children}
+
+
+
+ Close menu
+
+
+
+
+
+ {colourPalette.map((c, i) =>
+ i % 16 <= 13 ? (
+ {
+ setSelectedColour(i);
+ onPick(i);
+ }}
+ />
+ ) : null,
+ )}
+
+
+
+ );
+};
+
+export default ColourPicker;
diff --git a/src/components/ColourSwatch.js b/src/components/ColourSwatch.js
index 8e8c9a4..c3e0113 100644
--- a/src/components/ColourSwatch.js
+++ b/src/components/ColourSwatch.js
@@ -1,6 +1,12 @@
-const ColourSwatch = ({ colour }) => (
+import { clsx } from 'clsx';
+
+const ColourSwatch = ({ colour, className, ...props }) => (
);
diff --git a/src/components/Palettes.js b/src/components/Palettes.js
index 63cf1f4..e91c6b1 100644
--- a/src/components/Palettes.js
+++ b/src/components/Palettes.js
@@ -1,17 +1,13 @@
+import ColourPicker from './ColourPicker';
import ColourSwatch from './ColourSwatch';
import { getPalette } from '../lib/paletteUtils';
-const Palettes = ({ nametable }) => {
+const Palettes = ({ palette, onUpdate }) => {
const colourSwatches = [];
for (let i = 0; i < 16; i += 4) {
- const palette = getPalette(
- [
- nametable.palette[i],
- nametable.palette[i + 1],
- nametable.palette[i + 2],
- nametable.palette[i + 3],
- ],
+ const colours = getPalette(
+ [palette[i], palette[i + 1], palette[i + 2], palette[i + 3]],
true,
);
@@ -19,10 +15,29 @@ const Palettes = ({ nametable }) => {
-
-
-
-
+ onUpdate(i, newColour)}>
+
+
+
+ onUpdate(i + 1, newColour)}>
+
+
+
+ onUpdate(i + 2, newColour)}>
+
+
+
+ onUpdate(i + 3, newColour)}>
+
+
,
);
}
diff --git a/src/containers/RoomsContainer.js b/src/containers/RoomsContainer.js
index 22ad6ac..242e145 100644
--- a/src/containers/RoomsContainer.js
+++ b/src/containers/RoomsContainer.js
@@ -54,6 +54,12 @@ const RoomsContainer = ({ rooms, roomgfx, globdata }) => {
setSelectedObjects(newSelectedObjects);
};
+ const updatePalette = (i, colourId) => {
+ const newRoom = structuredClone(room);
+ newRoom.nametable.palette[i] = colourId;
+ setRoom(newRoom);
+ };
+
if (room && !room.header) {
return null;
}
@@ -106,7 +112,10 @@ const RoomsContainer = ({ rooms, roomgfx, globdata }) => {
setCurrentTab={setCurrentTab}
/>
{currentTab === 'Palettes' && (
-
+
)}
{currentTab === 'Tilesets' && (
{
return m[0] * 0.299 + m[1] * 0.587 + m[2] * 0.114;
};
-export { getPalette };
+export { getPalette, getLuminosity };
diff --git a/tailwind.config.js b/tailwind.config.js
index f845233..a726528 100644
--- a/tailwind.config.js
+++ b/tailwind.config.js
@@ -10,6 +10,9 @@ const config = {
primary: colors.sky,
gray: colors.slate,
},
+ gridTemplateColumns: {
+ 14: 'repeat(14, minmax(0, 1fr))',
+ },
},
// prettier-ignore
// https://github.com/system-fonts/modern-font-stacks