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 b91e281
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
49 changes: 48 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,53 @@ export class App {
initialConfig.viewerLink = "none";
this.twistyPlayer = new TwistyPlayer(initialConfig);
this.puzzlePane.appendChild(this.twistyPlayer);
const originalPuzzleID = initialConfig.puzzle ?? "3x3x3";
(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();
this.element
.querySelector(".auto-notation-undo")!
.addEventListener("click", () => {
this.controlPane.puzzleSelect.value = originalPuzzleID;
this.controlPane.puzzleSelectChanged();
this.element.querySelector(
".auto-notation-changed-back",
)!.textContent =
`This has been changed back to ${puzzles[originalPuzzleID].fullName}.`;
});
return;
}
} catch {}
}
}
})();
}

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

private puzzleSelectChanged(): void {
puzzleSelectChanged(): void {
const option = this.puzzleSelect.selectedOptions[0];
this.twistyPlayer.puzzle = option.value as PuzzleID;
}
Expand Down
7 changes: 7 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,13 @@
<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. (<span class="auto-notation-changed-back">Want to <a href="#" class="auto-notation-undo">change it
back</a>?</span>)
</p>
</div>
<expand-button for="setup" expanded="true" exclusive="false">
<a href="#">
<h2>
Expand Down

0 comments on commit b91e281

Please sign in to comment.