Skip to content

Commit e9a01d3

Browse files
committed
[alg] Rename AlgLeafNode to AlgLeaf.
1 parent ff29062 commit e9a01d3

File tree

19 files changed

+47
-49
lines changed

19 files changed

+47
-49
lines changed

src/cubing/alg/Alg.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Grouping, Pause } from "./alg-nodes";
99
import { LineComment } from "./alg-nodes/leaves/LineComment";
1010
import { Move } from "./alg-nodes/leaves/Move";
1111
import { Newline } from "./alg-nodes/leaves/Newline";
12-
import type { AlgLeafNode, AlgNode } from "./alg-nodes/AlgNode";
12+
import type { AlgLeaf, AlgNode } from "./alg-nodes/AlgNode";
1313
import { warnOnce } from "./warnOnce";
1414

1515
export type FlexibleAlgSource = string | Iterable<AlgNode> | Alg;
@@ -153,7 +153,7 @@ export class Alg extends AlgCommon<Alg> {
153153
*experimentalExpand(
154154
iterDir: IterationDirection = IterationDirection.Forwards,
155155
depth?: number,
156-
): Generator<AlgLeafNode> {
156+
): Generator<AlgLeaf> {
157157
depth ??= Infinity;
158158
for (const algNode of direct(this.#algNodes, iterDir)) {
159159
yield* algNode.experimentalExpand(iterDir, depth);

src/cubing/alg/alg-nodes/AlgNode.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type { Move } from "./leaves/Move";
66
import type { Newline } from "./leaves/Newline";
77
import type { Pause } from "./leaves/Pause";
88

9-
// TODO: Just `AlgLeaf`?
10-
export type AlgLeafNode = Move | LineComment | Newline | Pause;
9+
export type AlgLeaf = Move | LineComment | Newline | Pause;
10+
export type AlgContainer = Grouping | Conjugate | Commutator;
1111

1212
/** @category Alg */
13-
export type AlgNode = AlgLeafNode | Grouping | Conjugate | Commutator;
13+
export type AlgNode = AlgLeaf | AlgContainer;

src/cubing/alg/alg-nodes/QuantumWithAmount.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Repeatable } from "../common";
22
import { IterationDirection, toggleDirection } from "../iteration";
33
import { MAX_INT, MAX_INT_DESCRIPTION, MIN_INT } from "../limits";
4-
import type { AlgLeafNode } from "./AlgNode";
4+
import type { AlgLeaf } from "./AlgNode";
55

66
export class QuantumWithAmount<Q extends Repeatable> {
77
readonly quantum: Q;
@@ -45,7 +45,7 @@ export class QuantumWithAmount<Q extends Repeatable> {
4545
*experimentalExpand(
4646
iterDir: IterationDirection,
4747
depth: number,
48-
): Generator<AlgLeafNode> {
48+
): Generator<AlgLeaf> {
4949
const absAmount = Math.abs(this.amount);
5050
const newIterDir = toggleDirection(iterDir, this.amount < 0);
5151
for (let i = 0; i < absAmount; i++) {

src/cubing/alg/alg-nodes/containers/Commutator.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Alg, experimentalEnsureAlg, FlexibleAlgSource } from "../../Alg";
22
import { AlgCommon, Comparable } from "../../common";
33
import { IterationDirection } from "../../iteration";
4-
import type { AlgLeafNode } from "../AlgNode";
4+
import type { AlgLeaf } from "../AlgNode";
55

66
/** @category Alg Nodes */
77
export class Commutator extends AlgCommon<Commutator> {
@@ -37,7 +37,7 @@ export class Commutator extends AlgCommon<Commutator> {
3737
*experimentalExpand(
3838
iterDir: IterationDirection = IterationDirection.Forwards,
3939
depth?: number,
40-
): Generator<AlgLeafNode> {
40+
): Generator<AlgLeaf> {
4141
depth ??= Infinity;
4242
if (depth === 0) {
4343
yield iterDir === IterationDirection.Forwards ? this : this.invert();

src/cubing/alg/alg-nodes/containers/Conjugate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Alg, experimentalEnsureAlg, FlexibleAlgSource } from "../../Alg";
22
import { AlgCommon, Comparable } from "../../common";
33
import { IterationDirection } from "../../iteration";
4-
import type { AlgLeafNode } from "../AlgNode";
4+
import type { AlgLeaf } from "../AlgNode";
55

66
/** @category Alg Nodes */
77
export class Conjugate extends AlgCommon<Conjugate> {
@@ -37,7 +37,7 @@ export class Conjugate extends AlgCommon<Conjugate> {
3737
*experimentalExpand(
3838
iterDir: IterationDirection,
3939
depth?: number,
40-
): Generator<AlgLeafNode> {
40+
): Generator<AlgLeaf> {
4141
depth ??= Infinity;
4242
if (depth === 0) {
4343
yield iterDir === IterationDirection.Forwards ? this : this.invert();

src/cubing/alg/alg-nodes/containers/Grouping.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IterationDirection } from "../../iteration";
44
import { Move, QuantumMove } from "../leaves/Move";
55
import type { Pause } from "../leaves/Pause";
66
import { QuantumWithAmount } from "../QuantumWithAmount";
7-
import type { AlgLeafNode } from "../AlgNode";
7+
import type { AlgLeaf } from "../AlgNode";
88

99
// This is a workaround for `jest`, which doesn't handle cycles of imports inside `cubing/alg`.
1010
// We need to lazy-initialize the reusable quantum moves for Square-1, so we create this wrapper for it.
@@ -86,7 +86,7 @@ export class Grouping extends AlgCommon<Grouping> {
8686
*experimentalExpand(
8787
iterDir: IterationDirection = IterationDirection.Forwards,
8888
depth?: number,
89-
): Generator<AlgLeafNode> {
89+
): Generator<AlgLeaf> {
9090
depth ??= Infinity;
9191
if (depth === 0) {
9292
yield iterDir === IterationDirection.Forwards ? this : this.invert();

src/cubing/alg/alg-nodes/leaves/LineComment.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AlgCommon, Comparable } from "../../common";
22
import { IterationDirection } from "../../iteration";
3-
import type { AlgLeafNode } from "../AlgNode";
3+
import type { AlgLeaf } from "../AlgNode";
44

55
// TODO: hash
66
// TODO: this conflicts with the HTML `LineComment` class
@@ -32,7 +32,7 @@ export class LineComment extends AlgCommon<LineComment> {
3232
*experimentalExpand(
3333
_iterDir: IterationDirection = IterationDirection.Forwards,
3434
_depth: number = Infinity,
35-
): Generator<AlgLeafNode> {
35+
): Generator<AlgLeaf> {
3636
yield this;
3737
}
3838

src/cubing/alg/alg-nodes/leaves/Move.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MAX_INT, MAX_INT_DESCRIPTION } from "../../limits";
44
import { parseMove, parseQuantumMove, transferCharIndex } from "../../parseAlg";
55
import { warnOnce } from "../../warnOnce";
66
import { QuantumWithAmount } from "../QuantumWithAmount";
7-
import type { AlgLeafNode } from "../AlgNode";
7+
import type { AlgLeaf } from "../AlgNode";
88

99
interface QuantumMoveModifications {
1010
outerLayer?: number;
@@ -108,7 +108,7 @@ export class QuantumMove extends Comparable {
108108
return this.#innerLayer;
109109
}
110110

111-
experimentalExpand(): Generator<AlgLeafNode> {
111+
experimentalExpand(): Generator<AlgLeaf> {
112112
throw new Error(
113113
"experimentalExpand() cannot be called on a `QuantumMove` directly.",
114114
);
@@ -176,7 +176,7 @@ export class Move extends AlgCommon<Move> {
176176

177177
*experimentalExpand(
178178
iterDir: IterationDirection = IterationDirection.Forwards,
179-
): Generator<AlgLeafNode> {
179+
): Generator<AlgLeaf> {
180180
if (iterDir === IterationDirection.Forwards) {
181181
yield this;
182182
} else {

src/cubing/alg/alg-nodes/leaves/Newline.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AlgCommon, Comparable } from "../../common";
22
import { IterationDirection } from "../../iteration";
3-
import type { AlgLeafNode } from "../AlgNode";
3+
import type { AlgLeaf } from "../AlgNode";
44

55
/** @category Alg Nodes */
66
export class Newline extends AlgCommon<Newline> {
@@ -19,7 +19,7 @@ export class Newline extends AlgCommon<Newline> {
1919
*experimentalExpand(
2020
_iterDir: IterationDirection = IterationDirection.Forwards,
2121
_depth: number = Infinity,
22-
): Generator<AlgLeafNode> {
22+
): Generator<AlgLeaf> {
2323
yield this;
2424
}
2525
}

src/cubing/alg/alg-nodes/leaves/Pause.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Grouping } from "..";
22
import { AlgCommon, Comparable } from "../../common";
33
import { IterationDirection } from "../../iteration";
4-
import type { AlgLeafNode } from "../AlgNode";
4+
import type { AlgLeaf } from "../AlgNode";
55

66
/** @category Alg Nodes */
77
export class Pause extends AlgCommon<Pause> {
@@ -22,7 +22,7 @@ export class Pause extends AlgCommon<Pause> {
2222
*experimentalExpand(
2323
_iterDir: IterationDirection = IterationDirection.Forwards,
2424
_depth: number = Infinity,
25-
): Generator<AlgLeafNode> {
25+
): Generator<AlgLeaf> {
2626
yield this;
2727
}
2828
}

src/cubing/alg/common.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Alg } from "./Alg";
22
import type { IterationDirection } from "./iteration";
3-
import type { AlgLeafNode, AlgNode } from "./alg-nodes/AlgNode";
3+
import type { AlgLeaf, AlgNode } from "./alg-nodes/AlgNode";
44

55
let writeAlgDebugField = false;
66
export function setAlgDebugField(debug: boolean): void {
@@ -24,7 +24,7 @@ export interface Repeatable extends Comparable {
2424
experimentalExpand(
2525
iterDir?: IterationDirection,
2626
depth?: number,
27-
): Generator<AlgLeafNode>;
27+
): Generator<AlgLeaf>;
2828
}
2929

3030
// Common to `Alg` or `AlgNode` classes.
@@ -55,7 +55,5 @@ export abstract class AlgCommon<T extends Alg | AlgNode>
5555

5656
abstract invert(): T;
5757

58-
abstract experimentalExpand(
59-
iterDir: IterationDirection,
60-
): Generator<AlgLeafNode>;
58+
abstract experimentalExpand(iterDir: IterationDirection): Generator<AlgLeaf>;
6159
}

src/cubing/alg/keyboard.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Pause } from "./alg-nodes";
2-
import type { AlgLeafNode } from "./alg-nodes/AlgNode";
2+
import type { AlgLeaf } from "./alg-nodes/AlgNode";
33
import { Move } from "./alg-nodes/leaves/Move";
44

5-
const cubeKeyMapping: { [key: number]: AlgLeafNode } = {
5+
const cubeKeyMapping: { [key: number]: AlgLeaf } = {
66
73: new Move("R"),
77
75: new Move("R'"),
88
87: new Move("B"),
@@ -43,7 +43,7 @@ const cubeKeyMapping: { [key: number]: AlgLeafNode } = {
4343
// TODO: options about whether to ignore modifier keys (e.g. alt, ctrl).
4444
// TODO: Support different mappings.
4545
// TODO: Return BaseMove instead?
46-
export function keyToMove(e: KeyboardEvent): AlgLeafNode | null {
46+
export function keyToMove(e: KeyboardEvent): AlgLeaf | null {
4747
if (e.altKey || e.ctrlKey) {
4848
return null;
4949
}

src/cubing/bluetooth/smart-puzzle/bluetooth-puzzle.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AlgLeafNode } from "../../alg/alg-nodes/AlgNode";
1+
import type { AlgLeaf } from "../../alg/alg-nodes/AlgNode";
22
import type { KState } from "../../kpuzzle/KState";
33
import { BasicRotationTransformer, StreamTransformer } from "../transformer";
44

@@ -8,7 +8,7 @@ import { BasicRotationTransformer, StreamTransformer } from "../transformer";
88
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
99
/** @category Smart Puzzles */
1010
export interface AlgLeafEvent {
11-
latestAlgLeaf: AlgLeafNode;
11+
latestAlgLeaf: AlgLeaf;
1212
timeStamp: number;
1313
debug?: Record<string, unknown>;
1414
state?: KState;

src/cubing/twisty/model/TwistyPlayerModel.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Alg, experimentalAppendMove, Move } from "../../alg";
2-
import type { AlgLeafNode } from "../../alg/alg-nodes/AlgNode";
2+
import type { AlgLeaf } from "../../alg/alg-nodes/AlgNode";
33
import { ArbitraryStringProp } from "./props/general/ArbitraryStringProp";
44
import { URLProp } from "./props/general/URLProp";
55
import { AlgProp } from "./props/puzzle/state/AlgProp";
@@ -223,17 +223,17 @@ export class TwistyPlayerModel {
223223
return url.toString();
224224
}
225225

226-
experimentalAddAlgLeafNode(
227-
algLeafNode: AlgLeafNode,
226+
experimentalAddAlgLeaf(
227+
algLeaf: AlgLeaf,
228228
options: { coalesce?: boolean; mod?: number } = {},
229229
): void {
230-
const maybeMove = algLeafNode.as(Move);
230+
const maybeMove = algLeaf.as(Move);
231231
if (maybeMove) {
232232
this.experimentalAddMove(maybeMove, options);
233233
} else {
234234
(async () => {
235235
const alg = (await this.alg.get()).alg;
236-
const newAlg = alg.concat(new Alg([algLeafNode]));
236+
const newAlg = alg.concat(new Alg([algLeaf]));
237237
this.alg.set(newAlg);
238238
this.timestampRequest.set("end");
239239
})();

src/cubing/twisty/views/TwistyPlayer.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Object3D } from "three";
22
import type { ExperimentalStickering } from "..";
33
import type { Alg, Move } from "../../alg";
4-
import type { AlgLeafNode } from "../../alg/alg-nodes/AlgNode";
4+
import type { AlgLeaf } from "../../alg/alg-nodes/AlgNode";
55
import type { PuzzleDescriptionString } from "../../puzzle-geometry/PGPuzzles";
66
import { RenderScheduler } from "../controllers/RenderScheduler";
77
import type { TwistyAnimationControllerDelegate } from "../controllers/TwistyAnimationController";
@@ -415,11 +415,11 @@ export class TwistyPlayer
415415
}
416416

417417
// TODO: Animate the new move.
418-
experimentalAddAlgLeafNode(
419-
algLeafNode: AlgLeafNode,
418+
experimentalAddAlgLeaf(
419+
algLeaf: AlgLeaf,
420420
options: { coalesce?: boolean } = {},
421421
): void {
422-
this.experimentalModel.experimentalAddAlgLeafNode(algLeafNode, options);
422+
this.experimentalModel.experimentalAddAlgLeaf(algLeaf, options);
423423
}
424424

425425
static get observedAttributes(): string[] {

src/sites/alpha.twizzle.net/explore/app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class SelectUI {
267267
? connectSmartPuzzle
268268
: debugKeyboardConnect)();
269269
inputPuzzle.addAlgLeafListener((e: MoveEvent) => {
270-
this.app.twistyPlayer.experimentalAddAlgLeafNode(e.latestAlgLeaf);
270+
this.app.twistyPlayer.experimentalAddAlgLeaf(e.latestAlgLeaf);
271271
});
272272
})();
273273
break;

src/sites/experiments.cubing.net/cubing.js/bluetooth/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function asyncSetup(twistyPlayer: TwistyPlayer): Promise<void> {
99
console.log("keyboard", twistyPlayer, keyboard);
1010
keyboard.addAlgLeafListener((e: MoveEvent) => {
1111
console.log("listener", e);
12-
twistyPlayer.experimentalAddAlgLeafNode(e.latestAlgLeaf, {
12+
twistyPlayer.experimentalAddAlgLeaf(e.latestAlgLeaf, {
1313
coalesce: true,
1414
});
1515
});
@@ -47,7 +47,7 @@ window.addEventListener("DOMContentLoaded", async () => {
4747
connectButton.disabled = true;
4848

4949
puzzle.addAlgLeafListener((e: MoveEvent) => {
50-
twistyPlayer.experimentalAddAlgLeafNode(e.latestAlgLeaf, {
50+
twistyPlayer.experimentalAddAlgLeaf(e.latestAlgLeaf, {
5151
coalesce: true,
5252
});
5353
});

src/sites/experiments.cubing.net/cubing.js/play/input/SwipeyPuzzle.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Alg, Move as AlgLeaf } from "../../../../../cubing/alg";
2-
import type { AlgLeafNode } from "../../../../../cubing/alg/alg-nodes/AlgNode";
1+
import { Alg } from "../../../../../cubing/alg";
2+
import type { AlgLeaf } from "../../../../../cubing/alg/alg-nodes/AlgNode";
33
// import { BackViewLayout } from "../../../../../cubing/twisty";
44
import {
55
BackViewLayout,
@@ -187,10 +187,10 @@ export class SwipeyPuzzle extends HTMLElement {
187187
}
188188

189189
// TODO: move this somewhere better.
190-
public addAlgLeaf(algLeaf: AlgLeafNode): void {
190+
public addAlgLeaf(algLeaf: AlgLeaf): void {
191191
try {
192192
// TODO: allow`TwistyPlayer` to handle this directly.
193-
this.twistyPlayer.experimentalAddAlgLeafNode(algLeaf, {
193+
this.twistyPlayer.experimentalAddAlgLeaf(algLeaf, {
194194
coalesce: coalesce(),
195195
});
196196
} catch (e) {

src/sites/experiments.cubing.net/cubing.js/robot/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class RobotDemo {
159159
}
160160

161161
onAlgLeaf(algLeafEvent: algLeafEvent): void {
162-
this.player.experimentalAddAlgLeafNode(algLeafEvent.latestAlgLeaf);
162+
this.player.experimentalAddAlgLeaf(algLeafEvent.latestAlgLeaf);
163163
if (this.paused) {
164164
console.log("Paused. Not sending moves.");
165165
} else {

0 commit comments

Comments
 (0)