cube-state-engine 1.1.0 → 1.2.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.
- package/README.md +6 -0
- package/dist/index.d.mts +40 -1
- package/dist/index.d.ts +40 -1
- package/dist/index.js +39 -1
- package/dist/index.mjs +39 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ A core state manager designed to integrate with custom 3D cube models. This engi
|
|
|
18
18
|
| `isSolved()` | Checks if the cube is solved. | `boolean` |
|
|
19
19
|
| `state()` | Returns the current state of the cube as an object representing each face. | `object` |
|
|
20
20
|
| `getMoves(asString?: boolean)` | Returns the history of all movements; as string if `true` (default), or as array if `false`. | `string / string[]` |
|
|
21
|
+
| `reset()` | Resets the cube to the solved state and clears the move history. | `void` |
|
|
21
22
|
| `applyMoves(sequence: string, options?: {record?: boolean})` | Applies a sequence of moves (supports U, D, L, R, F, x, y, z, M, Dw, Uw, Rw, Lw with ', 2). | `void` |
|
|
22
23
|
| `rotateU(clockwise?: boolean)` | Rotates the **Upper** layer clockwise or counterclockwise. | `void` |
|
|
23
24
|
| `rotateD(clockwise?: boolean)` | Rotates the **Down** layer clockwise or counterclockwise. | `void` |
|
|
@@ -74,6 +75,11 @@ console.log(cube.state());
|
|
|
74
75
|
console.log(cube.getMoves(true)); // "U Dw Dw' M2 ..."
|
|
75
76
|
console.log(cube.getMoves(false)); // ["U", "Dw", "Dw'", "M", "M"]
|
|
76
77
|
|
|
78
|
+
// Reset the cube to solved state and clear history
|
|
79
|
+
cube.reset();
|
|
80
|
+
console.log(cube.isSolved()); // true
|
|
81
|
+
console.log(cube.getMoves(false)); // []
|
|
82
|
+
|
|
77
83
|
// Rotate the cube along the Y-axis
|
|
78
84
|
cube.rotateY(false);
|
|
79
85
|
```
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class CubeEngine {
|
|
2
2
|
MOVES = [];
|
|
3
3
|
|
|
4
|
-
constructor(initialScramble) {
|
|
4
|
+
constructor(initialScramble = "") {
|
|
5
5
|
// If an initial scramble string is provided, apply it without recording moves
|
|
6
6
|
if (typeof initialScramble === "string" && initialScramble.trim().length > 0) {
|
|
7
7
|
this.#applyMovesFromString(initialScramble, false);
|
|
@@ -513,6 +513,45 @@ class CubeEngine {
|
|
|
513
513
|
return asString ? this.MOVES.join(" ") : this.MOVES;
|
|
514
514
|
}
|
|
515
515
|
|
|
516
|
+
/**
|
|
517
|
+
* Resets the cube to the solved state and clears the move history.
|
|
518
|
+
*/
|
|
519
|
+
reset() {
|
|
520
|
+
this.STATES = {
|
|
521
|
+
UPPER: [
|
|
522
|
+
[COLOR.W[0], COLOR.W[1], COLOR.W[2]],
|
|
523
|
+
[COLOR.W[3], COLOR.W[4], COLOR.W[5]],
|
|
524
|
+
[COLOR.W[6], COLOR.W[7], COLOR.W[8]],
|
|
525
|
+
],
|
|
526
|
+
LEFT: [
|
|
527
|
+
[COLOR.O[0], COLOR.O[1], COLOR.O[2]],
|
|
528
|
+
[COLOR.O[3], COLOR.O[4], COLOR.O[5]],
|
|
529
|
+
[COLOR.O[6], COLOR.O[7], COLOR.O[8]],
|
|
530
|
+
],
|
|
531
|
+
FRONT: [
|
|
532
|
+
[COLOR.G[0], COLOR.G[1], COLOR.G[2]],
|
|
533
|
+
[COLOR.G[3], COLOR.G[4], COLOR.G[5]],
|
|
534
|
+
[COLOR.G[6], COLOR.G[7], COLOR.G[8]],
|
|
535
|
+
],
|
|
536
|
+
RIGHT: [
|
|
537
|
+
[COLOR.R[0], COLOR.R[1], COLOR.R[2]],
|
|
538
|
+
[COLOR.R[3], COLOR.R[4], COLOR.R[5]],
|
|
539
|
+
[COLOR.R[6], COLOR.R[7], COLOR.R[8]],
|
|
540
|
+
],
|
|
541
|
+
BACK: [
|
|
542
|
+
[COLOR.B[0], COLOR.B[1], COLOR.B[2]],
|
|
543
|
+
[COLOR.B[3], COLOR.B[4], COLOR.B[5]],
|
|
544
|
+
[COLOR.B[6], COLOR.B[7], COLOR.B[8]],
|
|
545
|
+
],
|
|
546
|
+
DOWN: [
|
|
547
|
+
[COLOR.Y[0], COLOR.Y[1], COLOR.Y[2]],
|
|
548
|
+
[COLOR.Y[3], COLOR.Y[4], COLOR.Y[5]],
|
|
549
|
+
[COLOR.Y[6], COLOR.Y[7], COLOR.Y[8]],
|
|
550
|
+
],
|
|
551
|
+
};
|
|
552
|
+
this.MOVES = [];
|
|
553
|
+
}
|
|
554
|
+
|
|
516
555
|
/**
|
|
517
556
|
* Applies a sequence of moves provided as a string.
|
|
518
557
|
* Supports: U, D, L, R, F, x, y, z; slice moves: M; and wide moves: Dw, Uw, Rw, Lw with optional ' for counterclockwise and 2 for double turns.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class CubeEngine {
|
|
2
2
|
MOVES = [];
|
|
3
3
|
|
|
4
|
-
constructor(initialScramble) {
|
|
4
|
+
constructor(initialScramble = "") {
|
|
5
5
|
// If an initial scramble string is provided, apply it without recording moves
|
|
6
6
|
if (typeof initialScramble === "string" && initialScramble.trim().length > 0) {
|
|
7
7
|
this.#applyMovesFromString(initialScramble, false);
|
|
@@ -513,6 +513,45 @@ class CubeEngine {
|
|
|
513
513
|
return asString ? this.MOVES.join(" ") : this.MOVES;
|
|
514
514
|
}
|
|
515
515
|
|
|
516
|
+
/**
|
|
517
|
+
* Resets the cube to the solved state and clears the move history.
|
|
518
|
+
*/
|
|
519
|
+
reset() {
|
|
520
|
+
this.STATES = {
|
|
521
|
+
UPPER: [
|
|
522
|
+
[COLOR.W[0], COLOR.W[1], COLOR.W[2]],
|
|
523
|
+
[COLOR.W[3], COLOR.W[4], COLOR.W[5]],
|
|
524
|
+
[COLOR.W[6], COLOR.W[7], COLOR.W[8]],
|
|
525
|
+
],
|
|
526
|
+
LEFT: [
|
|
527
|
+
[COLOR.O[0], COLOR.O[1], COLOR.O[2]],
|
|
528
|
+
[COLOR.O[3], COLOR.O[4], COLOR.O[5]],
|
|
529
|
+
[COLOR.O[6], COLOR.O[7], COLOR.O[8]],
|
|
530
|
+
],
|
|
531
|
+
FRONT: [
|
|
532
|
+
[COLOR.G[0], COLOR.G[1], COLOR.G[2]],
|
|
533
|
+
[COLOR.G[3], COLOR.G[4], COLOR.G[5]],
|
|
534
|
+
[COLOR.G[6], COLOR.G[7], COLOR.G[8]],
|
|
535
|
+
],
|
|
536
|
+
RIGHT: [
|
|
537
|
+
[COLOR.R[0], COLOR.R[1], COLOR.R[2]],
|
|
538
|
+
[COLOR.R[3], COLOR.R[4], COLOR.R[5]],
|
|
539
|
+
[COLOR.R[6], COLOR.R[7], COLOR.R[8]],
|
|
540
|
+
],
|
|
541
|
+
BACK: [
|
|
542
|
+
[COLOR.B[0], COLOR.B[1], COLOR.B[2]],
|
|
543
|
+
[COLOR.B[3], COLOR.B[4], COLOR.B[5]],
|
|
544
|
+
[COLOR.B[6], COLOR.B[7], COLOR.B[8]],
|
|
545
|
+
],
|
|
546
|
+
DOWN: [
|
|
547
|
+
[COLOR.Y[0], COLOR.Y[1], COLOR.Y[2]],
|
|
548
|
+
[COLOR.Y[3], COLOR.Y[4], COLOR.Y[5]],
|
|
549
|
+
[COLOR.Y[6], COLOR.Y[7], COLOR.Y[8]],
|
|
550
|
+
],
|
|
551
|
+
};
|
|
552
|
+
this.MOVES = [];
|
|
553
|
+
}
|
|
554
|
+
|
|
516
555
|
/**
|
|
517
556
|
* Applies a sequence of moves provided as a string.
|
|
518
557
|
* Supports: U, D, L, R, F, x, y, z; slice moves: M; and wide moves: Dw, Uw, Rw, Lw with optional ' for counterclockwise and 2 for double turns.
|
package/dist/index.js
CHANGED
|
@@ -47,7 +47,7 @@ __export(src_exports, {
|
|
|
47
47
|
module.exports = __toCommonJS(src_exports);
|
|
48
48
|
var _CubeEngine_instances, rotateU_fn, rotateF_fn, rotateR_fn, rotateL_fn, rotateD_fn, rotateDw_fn, rotateUw_fn, rotateRw_fn, rotateLw_fn, rotateM_fn, rotateX_fn, rotateZ_fn, rotateY_fn, switchMatrix_fn, specialFlip_fn, applyMovesFromString_fn;
|
|
49
49
|
var CubeEngine = class {
|
|
50
|
-
constructor(initialScramble) {
|
|
50
|
+
constructor(initialScramble = "") {
|
|
51
51
|
__privateAdd(this, _CubeEngine_instances);
|
|
52
52
|
__publicField(this, "MOVES", []);
|
|
53
53
|
// States object for the rotation
|
|
@@ -281,6 +281,44 @@ var CubeEngine = class {
|
|
|
281
281
|
getMoves(asString = true) {
|
|
282
282
|
return asString ? this.MOVES.join(" ") : this.MOVES;
|
|
283
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Resets the cube to the solved state and clears the move history.
|
|
286
|
+
*/
|
|
287
|
+
reset() {
|
|
288
|
+
this.STATES = {
|
|
289
|
+
UPPER: [
|
|
290
|
+
[COLOR.W[0], COLOR.W[1], COLOR.W[2]],
|
|
291
|
+
[COLOR.W[3], COLOR.W[4], COLOR.W[5]],
|
|
292
|
+
[COLOR.W[6], COLOR.W[7], COLOR.W[8]]
|
|
293
|
+
],
|
|
294
|
+
LEFT: [
|
|
295
|
+
[COLOR.O[0], COLOR.O[1], COLOR.O[2]],
|
|
296
|
+
[COLOR.O[3], COLOR.O[4], COLOR.O[5]],
|
|
297
|
+
[COLOR.O[6], COLOR.O[7], COLOR.O[8]]
|
|
298
|
+
],
|
|
299
|
+
FRONT: [
|
|
300
|
+
[COLOR.G[0], COLOR.G[1], COLOR.G[2]],
|
|
301
|
+
[COLOR.G[3], COLOR.G[4], COLOR.G[5]],
|
|
302
|
+
[COLOR.G[6], COLOR.G[7], COLOR.G[8]]
|
|
303
|
+
],
|
|
304
|
+
RIGHT: [
|
|
305
|
+
[COLOR.R[0], COLOR.R[1], COLOR.R[2]],
|
|
306
|
+
[COLOR.R[3], COLOR.R[4], COLOR.R[5]],
|
|
307
|
+
[COLOR.R[6], COLOR.R[7], COLOR.R[8]]
|
|
308
|
+
],
|
|
309
|
+
BACK: [
|
|
310
|
+
[COLOR.B[0], COLOR.B[1], COLOR.B[2]],
|
|
311
|
+
[COLOR.B[3], COLOR.B[4], COLOR.B[5]],
|
|
312
|
+
[COLOR.B[6], COLOR.B[7], COLOR.B[8]]
|
|
313
|
+
],
|
|
314
|
+
DOWN: [
|
|
315
|
+
[COLOR.Y[0], COLOR.Y[1], COLOR.Y[2]],
|
|
316
|
+
[COLOR.Y[3], COLOR.Y[4], COLOR.Y[5]],
|
|
317
|
+
[COLOR.Y[6], COLOR.Y[7], COLOR.Y[8]]
|
|
318
|
+
]
|
|
319
|
+
};
|
|
320
|
+
this.MOVES = [];
|
|
321
|
+
}
|
|
284
322
|
/**
|
|
285
323
|
* Applies a sequence of moves provided as a string.
|
|
286
324
|
* Supports: U, D, L, R, F, x, y, z; slice moves: M; and wide moves: Dw, Uw, Rw, Lw with optional ' for counterclockwise and 2 for double turns.
|
package/dist/index.mjs
CHANGED
|
@@ -25,7 +25,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
25
25
|
// src/index.js
|
|
26
26
|
var _CubeEngine_instances, rotateU_fn, rotateF_fn, rotateR_fn, rotateL_fn, rotateD_fn, rotateDw_fn, rotateUw_fn, rotateRw_fn, rotateLw_fn, rotateM_fn, rotateX_fn, rotateZ_fn, rotateY_fn, switchMatrix_fn, specialFlip_fn, applyMovesFromString_fn;
|
|
27
27
|
var CubeEngine = class {
|
|
28
|
-
constructor(initialScramble) {
|
|
28
|
+
constructor(initialScramble = "") {
|
|
29
29
|
__privateAdd(this, _CubeEngine_instances);
|
|
30
30
|
__publicField(this, "MOVES", []);
|
|
31
31
|
// States object for the rotation
|
|
@@ -259,6 +259,44 @@ var CubeEngine = class {
|
|
|
259
259
|
getMoves(asString = true) {
|
|
260
260
|
return asString ? this.MOVES.join(" ") : this.MOVES;
|
|
261
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Resets the cube to the solved state and clears the move history.
|
|
264
|
+
*/
|
|
265
|
+
reset() {
|
|
266
|
+
this.STATES = {
|
|
267
|
+
UPPER: [
|
|
268
|
+
[COLOR.W[0], COLOR.W[1], COLOR.W[2]],
|
|
269
|
+
[COLOR.W[3], COLOR.W[4], COLOR.W[5]],
|
|
270
|
+
[COLOR.W[6], COLOR.W[7], COLOR.W[8]]
|
|
271
|
+
],
|
|
272
|
+
LEFT: [
|
|
273
|
+
[COLOR.O[0], COLOR.O[1], COLOR.O[2]],
|
|
274
|
+
[COLOR.O[3], COLOR.O[4], COLOR.O[5]],
|
|
275
|
+
[COLOR.O[6], COLOR.O[7], COLOR.O[8]]
|
|
276
|
+
],
|
|
277
|
+
FRONT: [
|
|
278
|
+
[COLOR.G[0], COLOR.G[1], COLOR.G[2]],
|
|
279
|
+
[COLOR.G[3], COLOR.G[4], COLOR.G[5]],
|
|
280
|
+
[COLOR.G[6], COLOR.G[7], COLOR.G[8]]
|
|
281
|
+
],
|
|
282
|
+
RIGHT: [
|
|
283
|
+
[COLOR.R[0], COLOR.R[1], COLOR.R[2]],
|
|
284
|
+
[COLOR.R[3], COLOR.R[4], COLOR.R[5]],
|
|
285
|
+
[COLOR.R[6], COLOR.R[7], COLOR.R[8]]
|
|
286
|
+
],
|
|
287
|
+
BACK: [
|
|
288
|
+
[COLOR.B[0], COLOR.B[1], COLOR.B[2]],
|
|
289
|
+
[COLOR.B[3], COLOR.B[4], COLOR.B[5]],
|
|
290
|
+
[COLOR.B[6], COLOR.B[7], COLOR.B[8]]
|
|
291
|
+
],
|
|
292
|
+
DOWN: [
|
|
293
|
+
[COLOR.Y[0], COLOR.Y[1], COLOR.Y[2]],
|
|
294
|
+
[COLOR.Y[3], COLOR.Y[4], COLOR.Y[5]],
|
|
295
|
+
[COLOR.Y[6], COLOR.Y[7], COLOR.Y[8]]
|
|
296
|
+
]
|
|
297
|
+
};
|
|
298
|
+
this.MOVES = [];
|
|
299
|
+
}
|
|
262
300
|
/**
|
|
263
301
|
* Applies a sequence of moves provided as a string.
|
|
264
302
|
* Supports: U, D, L, R, F, x, y, z; slice moves: M; and wide moves: Dw, Uw, Rw, Lw with optional ' for counterclockwise and 2 for double turns.
|
package/package.json
CHANGED