Spaces:
Sleeping
Sleeping
show color name
Browse files- src/components/consts.tsx +16 -7
- src/components/cube-piece.tsx +2 -2
- src/components/state-modal.tsx +9 -1
src/components/consts.tsx
CHANGED
|
@@ -11,13 +11,22 @@ export const CubeColors: Record<FacingDirection, string> = {
|
|
| 11 |
bottom: '#ffffff', // White
|
| 12 |
};
|
| 13 |
|
| 14 |
-
export const
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
};
|
| 22 |
|
| 23 |
export const Rotations: Record<FacingDirection, [number, number, number]> = {
|
|
|
|
| 11 |
bottom: '#ffffff', // White
|
| 12 |
};
|
| 13 |
|
| 14 |
+
export const Color2Index: Record<string, number> = {
|
| 15 |
+
'#ff0000': 0,
|
| 16 |
+
'#ff00ff': 1,
|
| 17 |
+
'#0000ff': 2,
|
| 18 |
+
'#00ff00': 3,
|
| 19 |
+
'#ffff00': 4,
|
| 20 |
+
'#ffffff': 5,
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
export const Index2Color: Record<number, string> = {
|
| 24 |
+
0: 'R',
|
| 25 |
+
1: 'P',
|
| 26 |
+
2: 'B',
|
| 27 |
+
3: 'G',
|
| 28 |
+
4: 'Y',
|
| 29 |
+
5: 'W',
|
| 30 |
};
|
| 31 |
|
| 32 |
export const Rotations: Record<FacingDirection, [number, number, number]> = {
|
src/components/cube-piece.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { RoundedBox } from '@react-three/drei';
|
|
| 4 |
import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
| 5 |
import { Mesh } from 'three';
|
| 6 |
|
| 7 |
-
import {
|
| 8 |
import { rotationController } from './rotation-controller';
|
| 9 |
|
| 10 |
export type CubePieceRef = {
|
|
@@ -67,7 +67,7 @@ export const CubePiece = forwardRef<CubePieceRef, CubePieceProps>(({ roughness,
|
|
| 67 |
userData={{
|
| 68 |
isFace: true,
|
| 69 |
faceColor: color,
|
| 70 |
-
faceColorIndex:
|
| 71 |
}}
|
| 72 |
>
|
| 73 |
<planeGeometry args={[0.8, 0.8]} />
|
|
|
|
| 4 |
import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
| 5 |
import { Mesh } from 'three';
|
| 6 |
|
| 7 |
+
import { Color2Index, CubeColors, FacingDirection, Rotations } from './consts';
|
| 8 |
import { rotationController } from './rotation-controller';
|
| 9 |
|
| 10 |
export type CubePieceRef = {
|
|
|
|
| 67 |
userData={{
|
| 68 |
isFace: true,
|
| 69 |
faceColor: color,
|
| 70 |
+
faceColorIndex: Color2Index[color],
|
| 71 |
}}
|
| 72 |
>
|
| 73 |
<planeGeometry args={[0.8, 0.8]} />
|
src/components/state-modal.tsx
CHANGED
|
@@ -5,6 +5,8 @@ import { Modal, ModalBody, ModalContent, ModalFooter, ModalHeader } from '@herou
|
|
| 5 |
import { useDisclosure } from '@heroui/use-disclosure';
|
| 6 |
import { forwardRef, useImperativeHandle, useState } from 'react';
|
| 7 |
|
|
|
|
|
|
|
| 8 |
export type StateModalRef = {
|
| 9 |
open: (status: Array<Array<number>>) => void;
|
| 10 |
};
|
|
@@ -25,7 +27,7 @@ export const StateModal = forwardRef<StateModalRef, unknown>((_, ref) => {
|
|
| 25 |
};
|
| 26 |
|
| 27 |
return (
|
| 28 |
-
<Modal isOpen={isOpen} onOpenChange={onOpenChange}>
|
| 29 |
<ModalContent>
|
| 30 |
{(onClose) => (
|
| 31 |
<>
|
|
@@ -35,26 +37,32 @@ export const StateModal = forwardRef<StateModalRef, unknown>((_, ref) => {
|
|
| 35 |
<div className="flex gap-2 items-center">
|
| 36 |
<div className="text-sm w-24 font-mont">Front</div>
|
| 37 |
<div className="font-mono">{JSON.stringify(state[0])}</div>
|
|
|
|
| 38 |
</div>
|
| 39 |
<div className="flex gap-2 items-center">
|
| 40 |
<div className="text-sm w-24 font-mont">Back</div>
|
| 41 |
<div className="font-mono">{JSON.stringify(state[1])}</div>
|
|
|
|
| 42 |
</div>
|
| 43 |
<div className="flex gap-2 items-center">
|
| 44 |
<div className="text-sm w-24 font-mont">Right</div>
|
| 45 |
<div className="font-mono">{JSON.stringify(state[2])}</div>
|
|
|
|
| 46 |
</div>
|
| 47 |
<div className="flex gap-2 items-center">
|
| 48 |
<div className="text-sm w-24 font-mont">Left</div>
|
| 49 |
<div className="font-mono">{JSON.stringify(state[3])}</div>
|
|
|
|
| 50 |
</div>
|
| 51 |
<div className="flex gap-2 items-center">
|
| 52 |
<div className="text-sm w-24 font-mont">Up</div>
|
| 53 |
<div className="font-mono">{JSON.stringify(state[4])}</div>
|
|
|
|
| 54 |
</div>
|
| 55 |
<div className="flex gap-2 items-center">
|
| 56 |
<div className="text-sm w-24 font-mont">Down</div>
|
| 57 |
<div className="font-mono">{JSON.stringify(state[5])}</div>
|
|
|
|
| 58 |
</div>
|
| 59 |
</div>
|
| 60 |
</ModalBody>
|
|
|
|
| 5 |
import { useDisclosure } from '@heroui/use-disclosure';
|
| 6 |
import { forwardRef, useImperativeHandle, useState } from 'react';
|
| 7 |
|
| 8 |
+
import { Index2Color } from './consts';
|
| 9 |
+
|
| 10 |
export type StateModalRef = {
|
| 11 |
open: (status: Array<Array<number>>) => void;
|
| 12 |
};
|
|
|
|
| 27 |
};
|
| 28 |
|
| 29 |
return (
|
| 30 |
+
<Modal isOpen={isOpen} onOpenChange={onOpenChange} placement="center">
|
| 31 |
<ModalContent>
|
| 32 |
{(onClose) => (
|
| 33 |
<>
|
|
|
|
| 37 |
<div className="flex gap-2 items-center">
|
| 38 |
<div className="text-sm w-24 font-mont">Front</div>
|
| 39 |
<div className="font-mono">{JSON.stringify(state[0])}</div>
|
| 40 |
+
<div className="font-mono">[{state[0].map((index) => Index2Color[index]).join(', ')}]</div>
|
| 41 |
</div>
|
| 42 |
<div className="flex gap-2 items-center">
|
| 43 |
<div className="text-sm w-24 font-mont">Back</div>
|
| 44 |
<div className="font-mono">{JSON.stringify(state[1])}</div>
|
| 45 |
+
<div className="font-mono">[{state[1].map((index) => Index2Color[index]).join(', ')}]</div>
|
| 46 |
</div>
|
| 47 |
<div className="flex gap-2 items-center">
|
| 48 |
<div className="text-sm w-24 font-mont">Right</div>
|
| 49 |
<div className="font-mono">{JSON.stringify(state[2])}</div>
|
| 50 |
+
<div className="font-mono">[{state[2].map((index) => Index2Color[index]).join(', ')}]</div>
|
| 51 |
</div>
|
| 52 |
<div className="flex gap-2 items-center">
|
| 53 |
<div className="text-sm w-24 font-mont">Left</div>
|
| 54 |
<div className="font-mono">{JSON.stringify(state[3])}</div>
|
| 55 |
+
<div className="font-mono">[{state[3].map((index) => Index2Color[index]).join(', ')}]</div>
|
| 56 |
</div>
|
| 57 |
<div className="flex gap-2 items-center">
|
| 58 |
<div className="text-sm w-24 font-mont">Up</div>
|
| 59 |
<div className="font-mono">{JSON.stringify(state[4])}</div>
|
| 60 |
+
<div className="font-mono">[{state[4].map((index) => Index2Color[index]).join(', ')}]</div>
|
| 61 |
</div>
|
| 62 |
<div className="flex gap-2 items-center">
|
| 63 |
<div className="text-sm w-24 font-mont">Down</div>
|
| 64 |
<div className="font-mono">{JSON.stringify(state[5])}</div>
|
| 65 |
+
<div className="font-mono">[{state[5].map((index) => Index2Color[index]).join(', ')}]</div>
|
| 66 |
</div>
|
| 67 |
</div>
|
| 68 |
</ModalBody>
|