Skip to content

Commit

Permalink
fix square 1 alg parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tdecker91 committed Feb 24, 2022
1 parent c38369a commit 9f3f96b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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": "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",
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/square1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand All @@ -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]),
});
}
}
Expand Down
34 changes: 24 additions & 10 deletions src/visualizer/puzzleCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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][
Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 9f3f96b

Please sign in to comment.