@houstonp/rubiks-cube 1.5.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +280 -170
  2. package/package.json +33 -3
  3. package/src/camera/cameraState.js +81 -0
  4. package/src/core.js +447 -0
  5. package/src/cube/animationSlice.js +205 -0
  6. package/src/cube/animationState.js +96 -0
  7. package/src/cube/cubeSettings.js +19 -0
  8. package/src/cube/cubeState.js +285 -139
  9. package/src/cube/stickerState.js +188 -0
  10. package/src/debouncer.js +16 -0
  11. package/src/globals.ts +9 -0
  12. package/src/index.js +621 -0
  13. package/src/settings.js +138 -0
  14. package/src/three/centerPiece.js +44 -0
  15. package/src/three/cornerPiece.js +60 -0
  16. package/src/three/cube.js +492 -0
  17. package/src/three/edgePiece.js +50 -0
  18. package/src/three/sticker.js +37 -0
  19. package/tests/common.js +27 -0
  20. package/tests/cube.five.test.js +126 -0
  21. package/tests/cube.four.test.js +126 -0
  22. package/tests/cube.seven.test.js +126 -0
  23. package/tests/cube.six.test.js +126 -0
  24. package/tests/cube.three.test.js +151 -0
  25. package/tests/cube.two.test.js +125 -0
  26. package/tests/setup.js +36 -0
  27. package/types/camera/cameraState.d.ts +19 -0
  28. package/types/core.d.ts +454 -0
  29. package/types/cube/animationSlice.d.ts +26 -0
  30. package/types/cube/animationState.d.ts +41 -0
  31. package/types/cube/cubeSettings.d.ts +17 -0
  32. package/types/cube/cubeState.d.ts +47 -0
  33. package/types/cube/stickerState.d.ts +21 -0
  34. package/types/debouncer.d.ts +13 -0
  35. package/types/globals.d.ts +7 -0
  36. package/types/index.d.ts +87 -0
  37. package/types/settings.d.ts +38 -0
  38. package/types/three/centerPiece.d.ts +15 -0
  39. package/types/three/cornerPiece.d.ts +24 -0
  40. package/types/three/cube.d.ts +130 -0
  41. package/types/three/edgePiece.d.ts +16 -0
  42. package/types/three/sticker.d.ts +15 -0
  43. package/.prettierrc +0 -7
  44. package/index.js +0 -274
  45. package/src/cube/cube.js +0 -276
  46. package/src/cube/cubeRotation.js +0 -63
  47. package/src/threejs/materials.js +0 -42
  48. package/src/threejs/pieces.js +0 -103
  49. package/src/threejs/stickers.js +0 -48
  50. package/src/utils/debouncer.js +0 -7
  51. package/src/utils/rotation.js +0 -53
@@ -1,103 +0,0 @@
1
- import { Group, BoxGeometry, Mesh, SphereGeometry, Material } from 'three';
2
- import Stickers from './stickers';
3
- import Materials from './materials';
4
-
5
- /**
6
- * @param {Geometry} sticker
7
- * @param {Material} frontMaterial
8
- * @param {Material} rightMaterial
9
- * @param {Material} topMaterial
10
- * @param {Material} coreMaterial
11
- * @returns {Group}
12
- */
13
- export function createCornerGroup(frontMaterial, rightMaterial, topMaterial, coreMaterial) {
14
- const group = new Group();
15
- const boxGeom = new BoxGeometry(1, 1, 1);
16
- const boxMesh = new Mesh(boxGeom, coreMaterial);
17
- boxMesh.userData = { type: 'piece' };
18
- group.add(boxMesh);
19
-
20
- // front
21
- const frontSticker = new Mesh(Stickers.corner, frontMaterial);
22
- frontSticker.userData = { type: 'sticker' };
23
- frontSticker.position.set(0, 0, 0.5);
24
- frontSticker.rotation.set(0, 0, 0);
25
- group.add(frontSticker);
26
-
27
- //right
28
- const rightSticker = new Mesh(Stickers.corner, rightMaterial);
29
- rightSticker.userData = { type: 'sticker' };
30
- rightSticker.position.set(0.5, 0, 0);
31
- rightSticker.rotation.set(Math.PI / 2, Math.PI / 2, 0);
32
- group.add(rightSticker);
33
-
34
- //white/yellow
35
- const topSticker = new Mesh(Stickers.corner, topMaterial);
36
- topSticker.userData = { type: 'sticker' };
37
- topSticker.position.set(0, 0.5, 0);
38
- topSticker.rotation.set(-Math.PI / 2, 0, -Math.PI / 2);
39
- group.add(topSticker);
40
-
41
- return group;
42
- }
43
-
44
- /**
45
- * @param {Geometry} sticker
46
- * @param {Material} frontMaterial
47
- * @param {Material} topMaterial
48
- * @param {Material} coreMaterial
49
- * @returns {Group}
50
- */
51
- export function createEdgeGroup(frontMaterial, topMaterial, coreMaterial) {
52
- const group = new Group();
53
- const boxGeom = new BoxGeometry(1, 1, 1);
54
- const boxMesh = new Mesh(boxGeom, coreMaterial);
55
- boxMesh.userData = { type: 'piece' };
56
- group.add(boxMesh);
57
-
58
- // front
59
- const frontSticker = new Mesh(Stickers.edge, frontMaterial);
60
- frontSticker.userData = { type: 'sticker' };
61
- frontSticker.position.set(0, 0, 0.5);
62
- frontSticker.rotation.set(0, 0, 0);
63
- group.add(frontSticker);
64
-
65
- // top
66
- const topSticker = new Mesh(Stickers.edge, topMaterial);
67
- topSticker.userData = { type: 'sticker' };
68
- topSticker.position.set(0, 0.5, 0);
69
- topSticker.rotation.set(-Math.PI / 2, 0, Math.PI);
70
- group.add(topSticker);
71
-
72
- return group;
73
- }
74
-
75
- /**
76
- * @param {Geometry} sticker
77
- * @param {Material} frontMaterial
78
- * @param {Material} topMaterial
79
- * @param {Material} coreMaterial
80
- * @returns {Group}
81
- */
82
- export function createCenterGroup(frontMaterial, coreMaterial) {
83
- const group = new Group();
84
- const boxGeom = new BoxGeometry(1, 1, 1);
85
- const boxMesh = new Mesh(boxGeom, coreMaterial);
86
- boxMesh.userData = { type: 'piece' };
87
- group.add(boxMesh);
88
-
89
- const frontSticker = new Mesh(Stickers.center, frontMaterial);
90
- frontSticker.userData = { type: 'sticker' };
91
- frontSticker.position.set(0, 0, 0.5);
92
- frontSticker.rotation.set(0, 0, 0);
93
- group.add(frontSticker);
94
-
95
- return group;
96
- }
97
-
98
- /**
99
- * @returns {Mesh}
100
- */
101
- export function createCoreMesh() {
102
- return new Mesh(new SphereGeometry(1.53), Materials.core);
103
- }
@@ -1,48 +0,0 @@
1
- import { SVGLoader } from "three/examples/jsm/Addons.js";
2
- import { ExtrudeGeometry } from "three";
3
-
4
- const loader = new SVGLoader();
5
- const cornerSVG = loader.parse(`
6
- <svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg" xmlns:bx="https://boxy-svg.com">
7
- <path d="M 25 0 H 500 V 500 H 0 V 25 A 25 25 0 0 1 25 0 Z" bx:shape="rect 0 0 500 500 25 0 0 0 1@a864c1ee"/>
8
- </svg>
9
- `);
10
- const edgeSVG = loader.parse(`
11
- <svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
12
- <path d="M 150 0 L 350 0 C 450 0 500 50 500 120 L 500 500 L 0 500 L 0 120 C 0 50 50 0 150 0 Z"></path>
13
- </svg>
14
- `);
15
- const centerSVG = loader.parse(`
16
- <svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
17
- <path d="M 120 0 L 380 0 C 450 0 500 50 500 120 L 500 380 C 500 450 450 500 380 500 L 120 500 C 50 500 0 450 0 380 L 0 120 C 0 50 50 0 120 0 Z"></path>
18
- </svg>
19
- `);
20
-
21
- export default class Stickers {
22
- static center = new ExtrudeGeometry(
23
- SVGLoader.createShapes(centerSVG.paths[0])[0],
24
- {
25
- depth: 15,
26
- }
27
- )
28
- .scale(0.002, 0.002, 0.002)
29
- .translate(-0.5, -0.5, 0);
30
-
31
- static edge = new ExtrudeGeometry(
32
- SVGLoader.createShapes(edgeSVG.paths[0])[0],
33
- {
34
- depth: 15,
35
- }
36
- )
37
- .scale(0.002, 0.002, 0.002)
38
- .translate(-0.5, -0.5, 0);
39
-
40
- static corner = new ExtrudeGeometry(
41
- SVGLoader.createShapes(cornerSVG.paths[0])[0],
42
- {
43
- depth: 15,
44
- }
45
- )
46
- .scale(0.002, 0.002, 0.002)
47
- .translate(-0.5, -0.5, 0);
48
- }
@@ -1,7 +0,0 @@
1
- export function debounce(f, delay) {
2
- let timer = 0;
3
- return function (...args) {
4
- clearTimeout(timer);
5
- timer = setTimeout(() => f.apply(this, args), delay);
6
- };
7
- }
@@ -1,53 +0,0 @@
1
- /**
2
- * @param {string} action
3
- * @returns {{axis: "x"|"y"|"z", layers: (0|1|-1)[], direction: (1|-1|2|-2)}}
4
- */
5
- export default function getRotationDetailsFromNotation(action) {
6
- if (!action) return;
7
- const reverse = action.includes("'") ? -1 : 1;
8
- action = action.replace("'", '');
9
- const multiplier = action.includes('2') ? 2 : 1;
10
- action = action.replace('2', '');
11
- if (!action) return;
12
- const move = action[0];
13
-
14
- if (move === 'x') {
15
- return { axis: 'x', layers: [], direction: -reverse * multiplier };
16
- } else if (move === 'y') {
17
- return { axis: 'y', layers: [], direction: -reverse * multiplier };
18
- } else if (move === 'z') {
19
- return { axis: 'z', layers: [], direction: -reverse * multiplier };
20
- } else if (move === 'U') {
21
- return { axis: 'y', layers: [1], direction: -reverse * multiplier };
22
- } else if (move === 'u') {
23
- return { axis: 'y', layers: [1, 0], direction: -reverse * multiplier };
24
- } else if (move === 'R') {
25
- return { axis: 'x', layers: [1], direction: -reverse * multiplier };
26
- } else if (move === 'r') {
27
- return { axis: 'x', layers: [1, 0], direction: -reverse * multiplier };
28
- } else if (move === 'L') {
29
- return { axis: 'x', layers: [-1], direction: -reverse * multiplier };
30
- } else if (move == 'l') {
31
- return { axis: 'x', layers: [-1, 0], direction: -reverse * multiplier };
32
- } else if (move === 'D') {
33
- return { axis: 'y', layers: [-1], direction: -reverse * multiplier };
34
- } else if (move === 'd') {
35
- return { axis: 'y', layers: [-1, 0], direction: -reverse * multiplier };
36
- } else if (move === 'F') {
37
- return { axis: 'z', layers: [1], direction: -reverse * multiplier };
38
- } else if (move === 'f') {
39
- return { axis: 'z', layers: [1, 0], direction: -reverse * multiplier };
40
- } else if (move === 'B') {
41
- return { axis: 'z', layers: [-1], direction: -reverse * multiplier };
42
- } else if (move === 'b') {
43
- return { axis: 'z', layers: [-1, 0], direction: -reverse * multiplier };
44
- } else if (move === 'M') {
45
- return { axis: 'x', layers: [0], direction: -reverse * multiplier };
46
- } else if (move === 'E') {
47
- return { axis: 'y', layers: [0], direction: -reverse * multiplier };
48
- } else if (move === 'S') {
49
- return { axis: 'z', layers: [0], direction: -reverse * multiplier };
50
- }
51
- console.log(`rubiks-cube invalid Action: ${action}`);
52
- return undefined;
53
- }