Skip to content

Commit

Permalink
[twisty] Ignore comments and newlines when determining simultaneous m…
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Dec 18, 2024
1 parent 1131959 commit beeab42
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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);
});
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -64,14 +64,20 @@ export class LocalSimulMoves extends TraversalUp<LocalAnimLeavesWithRange[]> {
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++) {
Expand Down

0 comments on commit beeab42

Please sign in to comment.