From 9f3f96b301fba0328263a244d4216037318bea5d Mon Sep 17 00:00:00 2001 From: Tyson Decker Date: Wed, 23 Feb 2022 23:22:15 -0700 Subject: [PATCH] fix square 1 alg parsing --- README.md | 6 ++++++ package.json | 2 +- src/algorithms/square1.ts | 6 +++--- src/visualizer/puzzleCreator.ts | 34 +++++++++++++++++++++++---------- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b19dd06..f0ba9a8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,12 @@ PuzzleGen is a javascript library intended to render [WCA puzzles](https://www.w PuzzleGen is built to be customizable, so if desired functionality can be extended to use cases other than embedding scramble previews in web pages. +## Demonstration + +Check out the library in action [HERE](https://tdecker91.github.io/puzzlegen-demo/) + +## Docs + See the [docs](https://tdecker91.github.io/puzzle-gen/) for more information ## Examples diff --git a/package.json b/package.json index 07f1b77..ff588e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sr-puzzlegen", - "version": "1.0.3-beta.12", + "version": "1.0.3-beta.13", "description": "", "main": "dist/lib/index.js", "types": "dist/lib/index.d.ts", diff --git a/src/algorithms/square1.ts b/src/algorithms/square1.ts index 2e4dd25..9af137c 100644 --- a/src/algorithms/square1.ts +++ b/src/algorithms/square1.ts @@ -2,7 +2,7 @@ import { Square1Move } from "./../simulator/square1/square1Simulator"; import { Square1Turns } from "../simulator/square1/square1Simulator"; import { Turn } from "./algorithm"; -const square1TurnRegex = /(\/|\((-?\d),(-?\d)\))/g; +const square1TurnRegex = /((\()?(-?\d)\s*,\s*(-?\d)(\))?)|(\/)/g; export function parseSquare1Algorithm(algorithm: string): Square1Move[] { let turns: Square1Move[] = []; @@ -13,8 +13,8 @@ export function parseSquare1Algorithm(algorithm: string): Square1Move[] { turns.push({ slice: true }); } else { turns.push({ - top: parseInt(match[2]), - bottom: parseInt(match[3]), + top: parseInt(match[3]), + bottom: parseInt(match[4]), }); } } diff --git a/src/visualizer/puzzleCreator.ts b/src/visualizer/puzzleCreator.ts index 79902ba..6deec11 100644 --- a/src/visualizer/puzzleCreator.ts +++ b/src/visualizer/puzzleCreator.ts @@ -44,17 +44,21 @@ const geometryCache: { [VisualizerType.SKEWB]: {}, [VisualizerType.SKEWB_NET]: {}, [VisualizerType.SQUARE1]: {}, - [VisualizerType.SQUARE1_NET]: {} + [VisualizerType.SQUARE1_NET]: {}, }; export function createCube( options: CubeOptions = {} ): [RubiksCube, RubiksCubeSimulator] { if (!geometryCache[VisualizerType.CUBE][options.size]) { - geometryCache[VisualizerType.CUBE][options.size] = new RubiksCube(options.size); + geometryCache[VisualizerType.CUBE][options.size] = new RubiksCube( + options.size + ); } - const geometry = geometryCache[VisualizerType.CUBE][options.size] as RubiksCube; + const geometry = geometryCache[VisualizerType.CUBE][ + options.size + ] as RubiksCube; const simulator = new RubiksCubeSimulator(options.size); return [geometry, simulator]; @@ -69,7 +73,9 @@ export function createCubeNet( ); } - const geometry = geometryCache[VisualizerType.CUBE_NET][options.size] as RubiksCubeNet; + const geometry = geometryCache[VisualizerType.CUBE_NET][ + options.size + ] as RubiksCubeNet; const simulator = new RubiksCubeSimulator(options.size); return [geometry, simulator]; @@ -79,9 +85,9 @@ export function createCubeTop( options: CubeOptions = {} ): [RubiksCubeTopLayer, RubiksCubeSimulator] { if (!geometryCache[VisualizerType.CUBE_TOP][options.size]) { - geometryCache[VisualizerType.CUBE_TOP][options.size] = new RubiksCubeTopLayer( + geometryCache[VisualizerType.CUBE_TOP][ options.size - ); + ] = new RubiksCubeTopLayer(options.size); } const geometry = geometryCache[VisualizerType.CUBE_TOP][ @@ -96,10 +102,14 @@ export function createMegaminx( options: MegaminxOptions = {} ): [Megaminx, MegaminxSimulator] { if (!geometryCache[VisualizerType.MEGAMINX][options.size]) { - geometryCache[VisualizerType.MEGAMINX][options.size] = new Megaminx(options.size); + geometryCache[VisualizerType.MEGAMINX][options.size] = new Megaminx( + options.size + ); } - const geometry = geometryCache[VisualizerType.MEGAMINX][options.size] as Megaminx; + const geometry = geometryCache[VisualizerType.MEGAMINX][ + options.size + ] as Megaminx; const simulator = new MegaminxSimulator(); return [geometry, simulator]; @@ -140,10 +150,14 @@ export function createPyraminx( options: PyraminxOptions = {} ): [Pyraminx, PyraminxSimulator] { if (!geometryCache[VisualizerType.PYRAMINX][options.size]) { - geometryCache[VisualizerType.PYRAMINX][options.size] = new Pyraminx(options.size); + geometryCache[VisualizerType.PYRAMINX][options.size] = new Pyraminx( + options.size + ); } - const geometry = geometryCache[VisualizerType.PYRAMINX][options.size] as Pyraminx; + const geometry = geometryCache[VisualizerType.PYRAMINX][ + options.size + ] as Pyraminx; const simulator = new PyraminxSimulator(); return [geometry, simulator];