From beeab42b2670fe2c9bbc2a4b1348c509bac249a8 Mon Sep 17 00:00:00 2001 From: Lucas Garron Date: Wed, 18 Dec 2024 00:40:05 -0800 Subject: [PATCH] [twisty] Ignore comments and newlines when determining simultaneous moves. Allows the following to work: https://alpha.twizzle.net/edit/?alg=%28R+%2F%2F+this+is+a+comment%0A%2F%2F+hi+there%0AL%29 --- .../indexer/simultaneous-moves/simul-move.spec.ts | 14 ++++++++++++++ .../indexer/simultaneous-moves/simul-moves.ts | 14 ++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 src/cubing/twisty/controllers/indexer/simultaneous-moves/simul-move.spec.ts diff --git a/src/cubing/twisty/controllers/indexer/simultaneous-moves/simul-move.spec.ts b/src/cubing/twisty/controllers/indexer/simultaneous-moves/simul-move.spec.ts new file mode 100644 index 000000000..937285bce --- /dev/null +++ b/src/cubing/twisty/controllers/indexer/simultaneous-moves/simul-move.spec.ts @@ -0,0 +1,14 @@ +import { expect, test } from "bun:test"; +import { Alg } from "../../../../alg"; +import { simulMoves } from "./simul-moves"; + +test("can be modified", () => { + const leavesWithRanges = simulMoves( + new Alg(`(R // this is a comment +// this too +L)`), + ); + expect(leavesWithRanges.length).toEqual(2); + expect(leavesWithRanges[0].end).toEqual(1000); + expect(leavesWithRanges[1].end).toEqual(1000); +}); diff --git a/src/cubing/twisty/controllers/indexer/simultaneous-moves/simul-moves.ts b/src/cubing/twisty/controllers/indexer/simultaneous-moves/simul-moves.ts index d23b90af9..acd553ae3 100644 --- a/src/cubing/twisty/controllers/indexer/simultaneous-moves/simul-moves.ts +++ b/src/cubing/twisty/controllers/indexer/simultaneous-moves/simul-moves.ts @@ -1,13 +1,13 @@ import { + LineComment, Move, + Newline, TraversalUp, functionFromTraversal, type Alg, type Commutator, type Conjugate, type Grouping, - type LineComment, - type Newline, type Pause, } from "../../../../alg"; import type { MillisecondTimestamp } from "../../AnimationTypes"; @@ -64,14 +64,20 @@ export class LocalSimulMoves extends TraversalUp { return []; } + const moves: Move[] = []; for (const algNode of alg.childAlgNodes()) { - if (!algNode.is(Move)) { + if ( + !(algNode.is(Move) || algNode.is(LineComment) || algNode.is(Newline)) + ) { // TODO: define the type statically on the class? return this.traverseAlg(alg); } + const asMove = algNode.as(Move); + if (asMove) { + moves.push(asMove); + } } - const moves = Array.from(alg.childAlgNodes()) as Move[]; let maxSimulDur = defaultDurationForAmount(moves[0].amount); for (let i = 0; i < moves.length - 1; i++) { for (let j = 1; j < moves.length; j++) {