Spaces:
Sleeping
Sleeping
use up down to avoid conflict
Browse files
src/components/consts.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
export type FacingDirection = 'front' | 'back' | 'right' | 'left' | '
|
| 2 |
|
| 3 |
export type RotationDirection = 'clockwise' | 'counter-clockwise';
|
| 4 |
|
|
@@ -7,8 +7,8 @@ export const CubeColors: Record<FacingDirection, string> = {
|
|
| 7 |
back: '#ff00ff', // Purple
|
| 8 |
right: '#0000ff', // Blue
|
| 9 |
left: '#00ff00', // Green
|
| 10 |
-
|
| 11 |
-
|
| 12 |
};
|
| 13 |
|
| 14 |
export const Color2Index: Record<string, number> = {
|
|
@@ -34,8 +34,8 @@ export const Rotations: Record<FacingDirection, [number, number, number]> = {
|
|
| 34 |
back: [0, Math.PI, 0],
|
| 35 |
right: [0, Math.PI / 2, 0],
|
| 36 |
left: [0, -Math.PI / 2, 0],
|
| 37 |
-
|
| 38 |
-
|
| 39 |
};
|
| 40 |
|
| 41 |
export type RotationStep = {
|
|
@@ -52,8 +52,8 @@ export const Actions: Array<RotationStep> = [
|
|
| 52 |
{ faceDirection: 'right', direction: 'counter-clockwise' },
|
| 53 |
{ faceDirection: 'left', direction: 'clockwise' },
|
| 54 |
{ faceDirection: 'left', direction: 'counter-clockwise' },
|
| 55 |
-
{ faceDirection: '
|
| 56 |
-
{ faceDirection: '
|
| 57 |
-
{ faceDirection: '
|
| 58 |
-
{ faceDirection: '
|
| 59 |
];
|
|
|
|
| 1 |
+
export type FacingDirection = 'front' | 'back' | 'right' | 'left' | 'up' | 'down';
|
| 2 |
|
| 3 |
export type RotationDirection = 'clockwise' | 'counter-clockwise';
|
| 4 |
|
|
|
|
| 7 |
back: '#ff00ff', // Purple
|
| 8 |
right: '#0000ff', // Blue
|
| 9 |
left: '#00ff00', // Green
|
| 10 |
+
up: '#ffff00', // Yellow
|
| 11 |
+
down: '#ffffff', // White
|
| 12 |
};
|
| 13 |
|
| 14 |
export const Color2Index: Record<string, number> = {
|
|
|
|
| 34 |
back: [0, Math.PI, 0],
|
| 35 |
right: [0, Math.PI / 2, 0],
|
| 36 |
left: [0, -Math.PI / 2, 0],
|
| 37 |
+
up: [-Math.PI / 2, 0, 0],
|
| 38 |
+
down: [Math.PI / 2, 0, 0],
|
| 39 |
};
|
| 40 |
|
| 41 |
export type RotationStep = {
|
|
|
|
| 52 |
{ faceDirection: 'right', direction: 'counter-clockwise' },
|
| 53 |
{ faceDirection: 'left', direction: 'clockwise' },
|
| 54 |
{ faceDirection: 'left', direction: 'counter-clockwise' },
|
| 55 |
+
{ faceDirection: 'up', direction: 'clockwise' },
|
| 56 |
+
{ faceDirection: 'up', direction: 'counter-clockwise' },
|
| 57 |
+
{ faceDirection: 'down', direction: 'clockwise' },
|
| 58 |
+
{ faceDirection: 'down', direction: 'counter-clockwise' },
|
| 59 |
];
|
src/components/cube-piece.tsx
CHANGED
|
@@ -38,16 +38,16 @@ export const CubePiece = forwardRef<CubePieceRef, CubePieceProps>(({ roughness,
|
|
| 38 |
back: z < 0,
|
| 39 |
left: x < 0,
|
| 40 |
right: x > 0,
|
| 41 |
-
|
| 42 |
-
|
| 43 |
};
|
| 44 |
const positions: Record<FacingDirection, [number, number, number]> = {
|
| 45 |
front: [0, 0, 0.48],
|
| 46 |
back: [0, 0, -0.48],
|
| 47 |
right: [0.48, 0, 0],
|
| 48 |
left: [-0.48, 0, 0],
|
| 49 |
-
|
| 50 |
-
|
| 51 |
};
|
| 52 |
|
| 53 |
return (
|
|
|
|
| 38 |
back: z < 0,
|
| 39 |
left: x < 0,
|
| 40 |
right: x > 0,
|
| 41 |
+
up: y > 0,
|
| 42 |
+
down: y < 0,
|
| 43 |
};
|
| 44 |
const positions: Record<FacingDirection, [number, number, number]> = {
|
| 45 |
front: [0, 0, 0.48],
|
| 46 |
back: [0, 0, -0.48],
|
| 47 |
right: [0.48, 0, 0],
|
| 48 |
left: [-0.48, 0, 0],
|
| 49 |
+
up: [0, 0.48, 0],
|
| 50 |
+
down: [0, -0.48, 0],
|
| 51 |
};
|
| 52 |
|
| 53 |
return (
|
src/components/rotation-controller.ts
CHANGED
|
@@ -40,11 +40,11 @@ export class RotationController {
|
|
| 40 |
sign = step.direction === 'clockwise' ? -1 : 1;
|
| 41 |
axis = 'x';
|
| 42 |
break;
|
| 43 |
-
case '
|
| 44 |
sign = step.direction === 'clockwise' ? -1 : 1;
|
| 45 |
axis = 'y';
|
| 46 |
break;
|
| 47 |
-
case '
|
| 48 |
sign = step.direction === 'clockwise' ? 1 : -1;
|
| 49 |
axis = 'y';
|
| 50 |
break;
|
|
@@ -70,8 +70,8 @@ export class RotationController {
|
|
| 70 |
case 'left':
|
| 71 |
axis = 'x';
|
| 72 |
break;
|
| 73 |
-
case '
|
| 74 |
-
case '
|
| 75 |
axis = 'y';
|
| 76 |
break;
|
| 77 |
}
|
|
@@ -135,15 +135,15 @@ export class RotationController {
|
|
| 135 |
return this.cubes.filter((m) => m.position.x > 0);
|
| 136 |
case 'left':
|
| 137 |
return this.cubes.filter((m) => m.position.x < 0);
|
| 138 |
-
case '
|
| 139 |
return this.cubes.filter((m) => m.position.y > 0);
|
| 140 |
-
case '
|
| 141 |
return this.cubes.filter((m) => m.position.y < 0);
|
| 142 |
}
|
| 143 |
}
|
| 144 |
|
| 145 |
initializeFaces() {
|
| 146 |
-
['front', 'back', 'right', 'left', '
|
| 147 |
const faceDirection = f as FacingDirection;
|
| 148 |
const cubes = this.getCubes(faceDirection);
|
| 149 |
const indices = cubes.map((cube) => this.getCubeFaceData(cube, faceDirection)).sort((a, b) => a.rank - b.rank);
|
|
@@ -155,7 +155,7 @@ export class RotationController {
|
|
| 155 |
|
| 156 |
getStatus() {
|
| 157 |
const rotationsPy: Array<string> = [];
|
| 158 |
-
const status = ['front', 'back', 'right', 'left', '
|
| 159 |
const faceDirection = f as FacingDirection;
|
| 160 |
const cubes = this.getCubes(faceDirection);
|
| 161 |
const indices = cubes.map((cube) => this.getCubeFaceData(cube, faceDirection)).sort((a, b) => a.rank - b.rank);
|
|
|
|
| 40 |
sign = step.direction === 'clockwise' ? -1 : 1;
|
| 41 |
axis = 'x';
|
| 42 |
break;
|
| 43 |
+
case 'up':
|
| 44 |
sign = step.direction === 'clockwise' ? -1 : 1;
|
| 45 |
axis = 'y';
|
| 46 |
break;
|
| 47 |
+
case 'down':
|
| 48 |
sign = step.direction === 'clockwise' ? 1 : -1;
|
| 49 |
axis = 'y';
|
| 50 |
break;
|
|
|
|
| 70 |
case 'left':
|
| 71 |
axis = 'x';
|
| 72 |
break;
|
| 73 |
+
case 'up':
|
| 74 |
+
case 'down':
|
| 75 |
axis = 'y';
|
| 76 |
break;
|
| 77 |
}
|
|
|
|
| 135 |
return this.cubes.filter((m) => m.position.x > 0);
|
| 136 |
case 'left':
|
| 137 |
return this.cubes.filter((m) => m.position.x < 0);
|
| 138 |
+
case 'up':
|
| 139 |
return this.cubes.filter((m) => m.position.y > 0);
|
| 140 |
+
case 'down':
|
| 141 |
return this.cubes.filter((m) => m.position.y < 0);
|
| 142 |
}
|
| 143 |
}
|
| 144 |
|
| 145 |
initializeFaces() {
|
| 146 |
+
['front', 'back', 'right', 'left', 'up', 'down'].forEach((f) => {
|
| 147 |
const faceDirection = f as FacingDirection;
|
| 148 |
const cubes = this.getCubes(faceDirection);
|
| 149 |
const indices = cubes.map((cube) => this.getCubeFaceData(cube, faceDirection)).sort((a, b) => a.rank - b.rank);
|
|
|
|
| 155 |
|
| 156 |
getStatus() {
|
| 157 |
const rotationsPy: Array<string> = [];
|
| 158 |
+
const status = ['front', 'back', 'right', 'left', 'up', 'down'].map((f) => {
|
| 159 |
const faceDirection = f as FacingDirection;
|
| 160 |
const cubes = this.getCubes(faceDirection);
|
| 161 |
const indices = cubes.map((cube) => this.getCubeFaceData(cube, faceDirection)).sort((a, b) => a.rank - b.rank);
|
src/components/rotation-panel.tsx
CHANGED
|
@@ -25,8 +25,8 @@ export const RotationPanel = ({ facingDirection, direction, onClick }: RotationP
|
|
| 25 |
back: clockwise ? [-0.5, 0, -1.01] : [0.5, 0, -1.01],
|
| 26 |
left: clockwise ? [-1.01, 0, 0.5] : [-1.01, 0, -0.5],
|
| 27 |
right: clockwise ? [1.01, 0, -0.5] : [1.01, 0, 0.5],
|
| 28 |
-
|
| 29 |
-
|
| 30 |
};
|
| 31 |
|
| 32 |
const handleClick = () => onClick?.({ faceDirection: facingDirection, direction });
|
|
|
|
| 25 |
back: clockwise ? [-0.5, 0, -1.01] : [0.5, 0, -1.01],
|
| 26 |
left: clockwise ? [-1.01, 0, 0.5] : [-1.01, 0, -0.5],
|
| 27 |
right: clockwise ? [1.01, 0, -0.5] : [1.01, 0, 0.5],
|
| 28 |
+
up: clockwise ? [0.5, 1.01, 0] : [-0.5, 1.01, 0],
|
| 29 |
+
down: clockwise ? [0.5, -1.01, 0] : [-0.5, -1.01, 0],
|
| 30 |
};
|
| 31 |
|
| 32 |
const handleClick = () => onClick?.({ faceDirection: facingDirection, direction });
|
src/components/rotator.tsx
CHANGED
|
@@ -24,7 +24,7 @@ export const Rotator = forwardRef<RotatorRef, RotatorProps>(({ cubeSpeed }: Rota
|
|
| 24 |
|
| 25 |
return (
|
| 26 |
<>
|
| 27 |
-
{['front', 'back', 'left', 'right', '
|
| 28 |
<Fragment key={facingDirection}>
|
| 29 |
<RotationPanel
|
| 30 |
direction="clockwise"
|
|
|
|
| 24 |
|
| 25 |
return (
|
| 26 |
<>
|
| 27 |
+
{['front', 'back', 'left', 'right', 'up', 'down'].map((facingDirection) => (
|
| 28 |
<Fragment key={facingDirection}>
|
| 29 |
<RotationPanel
|
| 30 |
direction="clockwise"
|
src/components/state-modal.tsx
CHANGED
|
@@ -55,12 +55,12 @@ export const StateModal = forwardRef<StateModalRef, unknown>((_, ref) => {
|
|
| 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">
|
| 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">
|
| 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>
|
|
|
|
| 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>
|