-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable tempo conjugates #177
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ class DataDown { | |
earliestMoveIndex: number; | ||
twistyAlgViewer: TwistyAlgViewer; | ||
direction: ExperimentalIterationDirection; | ||
type?: string; | ||
} | ||
|
||
class DataUp { | ||
|
@@ -91,6 +92,10 @@ class TwistyAlgWrapperElem extends HTMLElementShim { | |
this.classList.add(className); | ||
} | ||
|
||
addClass(className: string) { | ||
this.classList.add(className); | ||
} | ||
|
||
addString(str: string) { | ||
this.queue.push(document.createTextNode(str)); | ||
} | ||
|
@@ -149,6 +154,9 @@ class AlgToDOMTree extends TraversalDownUp<DataDown, DataUp, DataUp> { | |
public traverseAlg(alg: Alg, dataDown: DataDown): DataUp { | ||
let moveCount = 0; | ||
const element = new TwistyAlgWrapperElem("twisty-alg-alg", alg); // TODO: pick a better class name. | ||
if (dataDown.type) { | ||
element.addClass(dataDown.type); | ||
} | ||
let first = true; | ||
for (const unit of experimentalDirect(alg.units(), dataDown.direction)) { | ||
if (!first) { | ||
|
@@ -293,6 +301,7 @@ class AlgToDOMTree extends TraversalDownUp<DataDown, DataUp, DataUp> { | |
earliestMoveIndex: dataDown.earliestMoveIndex + moveCount, | ||
twistyAlgViewer: dataDown.twistyAlgViewer, | ||
direction: dataDown.direction, | ||
type: "setup", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open to alternate names for this and "execution" (unsure if there are technical terms for the different parts of a conjugate) |
||
}), | ||
); | ||
moveCount += aLen; | ||
|
@@ -302,6 +311,7 @@ class AlgToDOMTree extends TraversalDownUp<DataDown, DataUp, DataUp> { | |
earliestMoveIndex: dataDown.earliestMoveIndex + moveCount, | ||
twistyAlgViewer: dataDown.twistyAlgViewer, | ||
direction: dataDown.direction, | ||
type: "execution", | ||
}), | ||
); | ||
element.addString("]"); | ||
|
@@ -366,13 +376,18 @@ class MoveHighlighter { | |
this.moveCharIndexMap.set(charIndex, elem); | ||
} | ||
|
||
set(move: Parsed<Move> | null): void { | ||
set(move: Parsed<Move> | null, twistyPlayer: TwistyPlayer): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find a way to access twistyPlayer from here, but I also didn't try very hard :P |
||
const newElem = move | ||
? this.moveCharIndexMap.get(move.startCharIndex) ?? null | ||
: null; | ||
if (this.currentElem === newElem) { | ||
return; | ||
} | ||
if (newElem?.parentElement?.classList.contains('execution')) { | ||
twistyPlayer.tempoScale = 10; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded for now. This is where I think implementation details would need sorting out. How would one pass in these values? Presumably something on DataDown? |
||
} else { | ||
twistyPlayer.tempoScale = 1; | ||
} | ||
this.currentElem?.classList.remove("twisty-alg-current-move"); | ||
this.currentElem?.setCurrentMove(false); | ||
newElem?.classList.add("twisty-alg-current-move"); | ||
|
@@ -434,10 +449,10 @@ export class TwistyAlgViewer extends HTMLElementShim { | |
moveInfo ??= currentMoveInfo.movesStarting[0]; | ||
moveInfo ??= currentMoveInfo.movesFinishing[0]; | ||
if (!moveInfo) { | ||
this.highlighter.set(null); | ||
this.highlighter.set(null, twistyPlayer); | ||
} else { | ||
const mainCurrentMove = moveInfo.move; // TODO | ||
this.highlighter.set(mainCurrentMove as Parsed<Move>); | ||
this.highlighter.set(mainCurrentMove as Parsed<Move>, twistyPlayer); | ||
} | ||
}, | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,9 @@ <h1 style="text-align: center"> | |
</h1> | ||
<twisty-player | ||
id="main-player" | ||
alg="([R, U])3 (U L)2' [M2': U2]" | ||
alg="[R2: R U' R' U' R U R' F' R U R' U' R' F R] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: revert back. This alg just made it easier to see my changes being applied. |
||
[F2: R U' R' U' R U R' F' R U R' U' R' F R] | ||
" | ||
></twisty-player> | ||
<div class="alg-example"> | ||
<twisty-alg-viewer for="main-player"></twisty-alg-viewer> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love having the state stored in class but it was at least the easiest way I could find for POC. Still figuring out the code base so there may be a better way already that I'm just not aware of.