Skip to content

Commit

Permalink
[twizzle/edit] Auto-detect incompatible notation.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Oct 7, 2024
1 parent f5cec21 commit b0e7d48
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/sites/alpha.twizzle.net/edit/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,42 @@ export class App {
initialConfig.viewerLink = "none";
this.twistyPlayer = new TwistyPlayer(initialConfig);
this.puzzlePane.appendChild(this.twistyPlayer);
(async () => {
const [puzzleAlgWithIssue, puzzleSetupAlgWithIssue] = await Promise.all([
this.twistyPlayer.experimentalModel.puzzleAlg.get(),
this.twistyPlayer.experimentalModel.puzzleSetupAlg.get(),
]);
if (
puzzleAlgWithIssue.issues.errors.length > 0 ||
puzzleSetupAlgWithIssue.issues.errors.length > 0
) {
const [algWithIssue, setupAlgWithIssue] = await Promise.all([
this.twistyPlayer.experimentalModel.alg.get(),
this.twistyPlayer.experimentalModel.setupAlg.get(),
]);
for (const puzzleID of ["square1", "clock", "megaminx"]) {
const puzzleLoader = puzzles[puzzleID];
const kpuzzle = await puzzleLoader.kpuzzle();
try {
if (
algWithIssue.issues.errors.length === 0 &&
setupAlgWithIssue.issues.errors.length === 0 &&
kpuzzle.defaultPattern().applyAlg(algWithIssue.alg) &&
kpuzzle.defaultPattern().applyAlg(setupAlgWithIssue.alg) // TODO: This ignores e.g. bandaging
) {
this.element.querySelector(".auto-notation-puzzle")!.textContent =
puzzleLoader.fullName;
this.element.querySelector<HTMLSpanElement>(
".auto-notation",
)!.hidden = false;
this.controlPane.puzzleSelect.value = puzzleID;
this.controlPane.puzzleSelectChanged();
return;
}
} catch {}
}
}
})();
}

async solve(): Promise<void> {
Expand Down Expand Up @@ -545,7 +581,7 @@ class ControlPane {
);
}

private puzzleSelectChanged(): void {
puzzleSelectChanged(): void {
const option = this.puzzleSelect.selectedOptions[0];
this.twistyPlayer.puzzle = option.value as PuzzleID;
}
Expand Down
6 changes: 6 additions & 0 deletions src/sites/alpha.twizzle.net/edit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<a href="" class="metadata-url video-url"></a>
<a href="" class="metadata-url competition-url"></a>
</section>
<div class="alg-features">
<p class="auto-notation" hidden>
The puzzle has been automatically changed to <span class="auto-notation-puzzle"></span> based on the provided
notation.
</p>
</div>
<expand-button for="setup" expanded="true" exclusive="false">
<a href="#">
<h2>
Expand Down

0 comments on commit b0e7d48

Please sign in to comment.