From 1e2ff420139a91e7642b752b5cfed01a382aeff0 Mon Sep 17 00:00:00 2001 From: Bryan Lundberg Date: Tue, 31 Dec 2024 07:52:55 -0600 Subject: [PATCH] sync sample with new api --- index.html | 32 ++++++++++++++++---------------- main.js | 35 +++++++++++++++++------------------ package.json | 2 +- src/index.js | 2 +- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/index.html b/index.html index b172a42..476089a 100644 --- a/index.html +++ b/index.html @@ -67,22 +67,22 @@

Sample usage

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(() => { diff --git a/main.js b/main.js index 6a5401d..ae3647b 100644 --- a/main.js +++ b/main.js @@ -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) }, }; /** @@ -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; diff --git a/package.json b/package.json index 4288cd9..b1db74a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js index b0b459a..b315cd2 100644 --- a/src/index.js +++ b/src/index.js @@ -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; } }