Skip to content

Commit

Permalink
sync sample with new api
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanlundberg committed Dec 31, 2024
1 parent 117bbf8 commit 1e2ff42
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 36 deletions.
32 changes: 16 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ <h3 class="font-bold mb-5">Sample usage</h3>
const CE = window.CubeEngine;

const movesMap = {
f: { move: () => CE.rotateU(false), notation: "U'" },
j: { move: () => CE.rotateU(true), notation: "U" },
g: { move: () => CE.rotateF(false), notation: "F'" },
h: { move: () => CE.rotateF(true), notation: "F" },
i: { move: () => CE.rotateR(true), notation: "R" },
k: { move: () => CE.rotateR(false), notation: "R'" },
d: { move: () => CE.rotateL(true), notation: "L" },
e: { move: () => CE.rotateL(false), notation: "L'" },
t: { move: () => CE.rotateX(true), notation: "x" },
y: { move: () => CE.rotateX(true), notation: "x" },
b: { move: () => CE.rotateX(false), notation: "x'" },
n: { move: () => CE.rotateX(false), notation: "x'" },
ñ: { move: () => CE.rotateY(true), notation: "y" },
a: { move: () => CE.rotateY(false), notation: "y'" },
s: { move: () => CE.rotateD(true), notation: "D" },
l: { move: () => CE.rotateD(false), notation: "D'" },
f: { move: () => CE.rotateU(false) },
j: { move: () => CE.rotateU(true) },
g: { move: () => CE.rotateF(false) },
h: { move: () => CE.rotateF(true) },
i: { move: () => CE.rotateR(true) },
k: { move: () => CE.rotateR(false) },
d: { move: () => CE.rotateL(true) },
e: { move: () => CE.rotateL(false) },
t: { move: () => CE.rotateX(true) },
y: { move: () => CE.rotateX(true) },
b: { move: () => CE.rotateX(false) },
n: { move: () => CE.rotateX(false) },
ñ: { move: () => CE.rotateY(true) },
a: { move: () => CE.rotateY(false) },
s: { move: () => CE.rotateD(true) },
l: { move: () => CE.rotateD(false) },
};

setInterval(() => {
Expand Down
35 changes: 17 additions & 18 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@ window.CubeEngine = new CubeEngine();
render();

const player = document.querySelector("twisty-player");
const moves = [];

const CE = window.CubeEngine;

const movesMap = {
f: { move: () => CE.rotateU(false), notation: "U'" },
j: { move: () => CE.rotateU(true), notation: "U" },
g: { move: () => CE.rotateF(false), notation: "F'" },
h: { move: () => CE.rotateF(true), notation: "F" },
i: { move: () => CE.rotateR(true), notation: "R" },
k: { move: () => CE.rotateR(false), notation: "R'" },
d: { move: () => CE.rotateL(true), notation: "L" },
e: { move: () => CE.rotateL(false), notation: "L'" },
t: { move: () => CE.rotateX(true), notation: "x" },
y: { move: () => CE.rotateX(true), notation: "x" },
b: { move: () => CE.rotateX(false), notation: "x'" },
n: { move: () => CE.rotateX(false), notation: "x'" },
ñ: { move: () => CE.rotateY(true), notation: "y" },
a: { move: () => CE.rotateY(false), notation: "y'" },
s: { move: () => CE.rotateD(true), notation: "D" },
l: { move: () => CE.rotateD(false), notation: "D'" },
f: { move: () => CE.rotateU(false) },
j: { move: () => CE.rotateU(true) },
g: { move: () => CE.rotateF(false) },
h: { move: () => CE.rotateF(true) },
i: { move: () => CE.rotateR(true) },
k: { move: () => CE.rotateR(false) },
d: { move: () => CE.rotateL(true) },
e: { move: () => CE.rotateL(false) },
t: { move: () => CE.rotateX(true) },
y: { move: () => CE.rotateX(true) },
b: { move: () => CE.rotateX(false) },
n: { move: () => CE.rotateX(false) },
ñ: { move: () => CE.rotateY(true) },
a: { move: () => CE.rotateY(false) },
s: { move: () => CE.rotateD(true) },
l: { move: () => CE.rotateD(false) },
};

/**
Expand All @@ -37,7 +36,7 @@ function executeMove(key) {
if (moveObj) {
// Execute the movement
moveObj.move();
moves.push(moveObj.notation);
const moves = CE.getMoves(false);

// Update the user interface
document.querySelector("#total").textContent = moves.length;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cube-state-engine",
"version": "1.0.4",
"version": "1.0.5",
"description": "An efficient representation in memory for tracking the Rubik's cube state on each movement.",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export class CubeEngine {
* @returns {string|array} The history of movements as an array or string.
*/
getMoves(asString = true) {
return asString ? this.MOVES : this.MOVES.join(" ");
return asString ? this.MOVES.join(" ") : this.MOVES;
}
}

Expand Down

0 comments on commit 1e2ff42

Please sign in to comment.