Spaces:
Sleeping
Sleeping
add reset feature
Browse files
src/components/rotation-controller.ts
CHANGED
|
@@ -86,15 +86,15 @@ export class RotationController {
|
|
| 86 |
maxFace = face as Mesh;
|
| 87 |
}
|
| 88 |
}
|
| 89 |
-
if (!maxFace)
|
| 90 |
const worldPosition = new Vector3();
|
| 91 |
maxFace.getWorldPosition(worldPosition);
|
| 92 |
const axis2 = ['x', 'y', 'z'].filter((x) => x !== axis) as Array<'x' | 'y' | 'z'>;
|
| 93 |
const rank = worldPosition[axis2[0]] * 100 + worldPosition[axis2[1]] * 10;
|
| 94 |
return {
|
| 95 |
-
|
| 96 |
-
worldPosition
|
| 97 |
-
rank
|
| 98 |
};
|
| 99 |
}
|
| 100 |
|
|
@@ -142,12 +142,25 @@ export class RotationController {
|
|
| 142 |
}
|
| 143 |
}
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
getStatus() {
|
|
|
|
| 146 |
return ['front', 'back', 'right', 'left', 'top', 'bottom'].map((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);
|
| 150 |
-
|
|
|
|
| 151 |
});
|
| 152 |
}
|
| 153 |
|
|
|
|
| 86 |
maxFace = face as Mesh;
|
| 87 |
}
|
| 88 |
}
|
| 89 |
+
if (!maxFace) throw new Error('maxFace is null'); // this should never happen
|
| 90 |
const worldPosition = new Vector3();
|
| 91 |
maxFace.getWorldPosition(worldPosition);
|
| 92 |
const axis2 = ['x', 'y', 'z'].filter((x) => x !== axis) as Array<'x' | 'y' | 'z'>;
|
| 93 |
const rank = worldPosition[axis2[0]] * 100 + worldPosition[axis2[1]] * 10;
|
| 94 |
return {
|
| 95 |
+
face: maxFace,
|
| 96 |
+
worldPosition,
|
| 97 |
+
rank,
|
| 98 |
};
|
| 99 |
}
|
| 100 |
|
|
|
|
| 142 |
}
|
| 143 |
}
|
| 144 |
|
| 145 |
+
initializeFaces() {
|
| 146 |
+
['front', 'back', 'right', 'left', 'top', 'bottom'].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);
|
| 150 |
+
indices.forEach((i, index) => {
|
| 151 |
+
i.face.userData.name = `${faceDirection[0].toUpperCase()}${index}`;
|
| 152 |
+
});
|
| 153 |
+
});
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
getStatus() {
|
| 157 |
+
console.log('Current Face Positions:');
|
| 158 |
return ['front', 'back', 'right', 'left', 'top', 'bottom'].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);
|
| 162 |
+
console.log(indices.map((i) => i.face.userData.name));
|
| 163 |
+
return indices.map((i) => i.face.userData.faceColorIndex);
|
| 164 |
});
|
| 165 |
}
|
| 166 |
|
src/components/rubiks-cube.tsx
CHANGED
|
@@ -37,12 +37,15 @@ export const RubiksCube = forwardRef<RubiksCubeRef, RubiksCubeProps>(({ cubeRoug
|
|
| 37 |
cubePieceRefs.current.forEach((cubePieceRef) => {
|
| 38 |
cubePieceRef.resetPosition();
|
| 39 |
});
|
|
|
|
| 40 |
});
|
| 41 |
},
|
| 42 |
}));
|
| 43 |
|
| 44 |
useEffect(() => {
|
| 45 |
-
if (cubeGroupRef.current)
|
|
|
|
|
|
|
| 46 |
}, [cubeGroupRef]);
|
| 47 |
|
| 48 |
return (
|
|
|
|
| 37 |
cubePieceRefs.current.forEach((cubePieceRef) => {
|
| 38 |
cubePieceRef.resetPosition();
|
| 39 |
});
|
| 40 |
+
rotationController.initializeFaces();
|
| 41 |
});
|
| 42 |
},
|
| 43 |
}));
|
| 44 |
|
| 45 |
useEffect(() => {
|
| 46 |
+
if (!cubeGroupRef.current) return;
|
| 47 |
+
rotationController.setCubeGroup(cubeGroupRef.current);
|
| 48 |
+
rotationController.initializeFaces();
|
| 49 |
}, [cubeGroupRef]);
|
| 50 |
|
| 51 |
return (
|