Skip to content

Commit

Permalink
[twisty] Rename experimental-start-setup to setup-alg.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Jan 17, 2021
1 parent 6ddb575 commit 55677a3
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 43 deletions.
27 changes: 11 additions & 16 deletions src/cubing/twisty/dom/TwistyPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class TwistyPlayer extends ManagedCustomElement {
set alg(seq: Sequence) {
// TODO: do validation for other algs as well.
if (seq?.type !== "sequence") {
// TODO: document `.setAttribute("experimental-start-setup", "R U R'")` as a workaround.
// TODO: document `.setAttribute("setup-alg", "R U R'")` as a workaround.
console.warn(
"`alg` for a `TwistyPlayer` was set using a string. It should be set using a `Sequence`!",
);
Expand All @@ -133,23 +133,23 @@ export class TwistyPlayer extends ManagedCustomElement {
return this.#config.attributes["alg"].value;
}

set experimentalStartSetup(seq: Sequence) {
set setupAlg(seq: Sequence) {
// TODO: do validation for other algs as well.
if (seq?.type !== "sequence") {
// TODO: document `.setAttribute("experimental-start-setup", "R U R'")` as a workaround.
// TODO: document `.setAttribute("setup-alg", "R U R'")` as a workaround.
console.warn(
"`experimentalStartSetup` for a `TwistyPlayer` was set using a string. It should be set using a `Sequence`!",
"`setupAlg` for a `TwistyPlayer` was set using a string. It should be set using a `Sequence`!",
);
seq = parseAlg((seq as unknown) as string) as Sequence;
}
this.#config.attributes["experimental-start-setup"].setValue(seq);
this.#config.attributes["setup-alg"].setValue(seq);
if (this.cursor) {
this.cursor.setStartState(this.cursor.algToState(seq)); // TODO
}
}

get experimentalStartSetup(): Sequence {
return this.#config.attributes["experimental-start-setup"].value;
get setupAlg(): Sequence {
return this.#config.attributes["setup-alg"].value;
}

set puzzle(puzzle: PuzzleID) {
Expand Down Expand Up @@ -428,7 +428,7 @@ export class TwistyPlayer extends ManagedCustomElement {
}

private setCursor(cursor: AlgCursor): void {
cursor.setStartState(cursor.algToState(this.experimentalStartSetup));
cursor.setStartState(cursor.algToState(this.setupAlg));
this.timeline.addCursor(cursor);
if (this.cursor) {
this.timeline.removeCursor(this.cursor);
Expand Down Expand Up @@ -472,12 +472,7 @@ export class TwistyPlayer extends ManagedCustomElement {

let cursor: AlgCursor;
try {
cursor = new AlgCursor(
this.timeline,
def,
this.alg,
this.experimentalStartSetup,
); // TODO: validate more directly if the alg is okay for the puzzle.
cursor = new AlgCursor(this.timeline, def, this.alg, this.setupAlg); // TODO: validate more directly if the alg is okay for the puzzle.
} catch (e) {
if (initial) {
this.experimentalInvalidInitialAlgCallback(this.alg);
Expand All @@ -486,11 +481,11 @@ export class TwistyPlayer extends ManagedCustomElement {
this.timeline,
def,
new Sequence([]),
this.experimentalStartSetup,
this.setupAlg,
);
}
this.setCursor(cursor);
if (initial && this.experimentalStartSetup.nestedUnits.length === 0) {
if (initial && this.setupAlg.nestedUnits.length === 0) {
this.timeline.jumpToEnd();
}
switch (this.visualization) {
Expand Down
10 changes: 4 additions & 6 deletions src/cubing/twisty/dom/TwistyPlayerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type AnyManagedAttribute = ManagedAttribute<any>;
interface TwistyPlayerAttributes extends Record<string, AnyManagedAttribute> {
// Alg
"alg": AlgAttribute;
"experimental-start-setup": AlgAttribute;
"setup-alg": AlgAttribute;

// Puzzle
"puzzle": StringEnumAttribute<PuzzleID>;
Expand All @@ -131,7 +131,7 @@ interface TwistyPlayerAttributes extends Record<string, AnyManagedAttribute> {

export interface TwistyPlayerConfigValues {
alg: Sequence;
experimentalStartSetup: Sequence;
setupAlg: Sequence;

puzzle: PuzzleID;
visualization: VisualizationFormat;
Expand All @@ -152,7 +152,7 @@ const twistyPlayerAttributeMap: Record<
keyof TwistyPlayerConfigValues
> = {
"alg": "alg",
"experimental-start-setup": "experimentalStartSetup",
"setup-alg": "setupAlg",

"puzzle": "puzzle",
"visualization": "visualization",
Expand All @@ -175,9 +175,7 @@ export class TwistyPlayerConfig {
) {
this.attributes = {
"alg": new AlgAttribute(initialValues.alg),
"experimental-start-setup": new AlgAttribute(
initialValues.experimentalStartSetup,
),
"setup-alg": new AlgAttribute(initialValues.setupAlg),

"puzzle": new StringEnumAttribute(puzzleIDs, initialValues.puzzle),
"visualization": new StringEnumAttribute(
Expand Down
12 changes: 6 additions & 6 deletions src/demo/twisty/2d-ll-stickering.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h2>OLL</h2>
<twisty-player
visualization="experimental-2D-LL"
experimental-stickering="OLL"
experimental-start-setup="r U R' U R U2 r'"
setup-alg="r U R' U R U2 r'"
control-panel="none"
background="none"
></twisty-player>
Expand All @@ -25,7 +25,7 @@ <h2>PLL</h2>
<twisty-player
visualization="experimental-2D-LL"
experimental-stickering="PLL"
experimental-start-setup="R U R' U' R' F R2 U' R' U' R U R' F'"
setup-alg="R U R' U' R' F R2 U' R' U' R U R' F'"
control-panel="none"
background="none"
></twisty-player>
Expand All @@ -35,7 +35,7 @@ <h2>COLL</h2>
<twisty-player
visualization="experimental-2D-LL"
experimental-stickering="COLL"
experimental-start-setup="L R' U' R U L' U2 R' U2 R"
setup-alg="L R' U' R U L' U2 R' U2 R"
control-panel="none"
background="none"
></twisty-player>
Expand All @@ -45,7 +45,7 @@ <h2>OCLL</h2>
<twisty-player
visualization="experimental-2D-LL"
experimental-stickering="OCLL"
experimental-start-setup="R U2 R' U' R U' R'"
setup-alg="R U2 R' U' R U' R'"
control-panel="none"
background="none"
></twisty-player>
Expand All @@ -55,7 +55,7 @@ <h2>ELL</h2>
<twisty-player
visualization="experimental-2D-LL"
experimental-stickering="ELL"
experimental-start-setup="M U' M' U2 M U' M'"
setup-alg="M U' M' U2 M U' M'"
control-panel="none"
background="none"
></twisty-player>
Expand All @@ -65,7 +65,7 @@ <h2>CLS</h2>
<twisty-player
visualization="experimental-2D-LL"
experimental-stickering="CLS"
experimental-start-setup="R U R' U2 R U R'"
setup-alg="R U R' U2 R U R'"
control-panel="none"
background="none"
></twisty-player>
Expand Down
2 changes: 1 addition & 1 deletion src/demo/twisty/2d-stickering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function demo(visualization: VisualizationFormat): void {
const div = content.appendChild(document.createElement("div"));
div.classList.add("case");
const twistyPlayer = new TwistyPlayer({
experimentalStartSetup: invert(parseAlg(s)),
setupAlg: invert(parseAlg(s)),
alg: parseAlg(s),
visualization,
experimentalStickering: stickering,
Expand Down
10 changes: 5 additions & 5 deletions src/demo/twisty/attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ <h2><code>alg=&quot;R U R' U R U2' R'&quot;</code></h2>

<div class="content">
<h2>
<code>experimental-start-setup=&quot;(R U R' U R U2' R')'&quot;</code>
<code>setup-alg=&quot;(R U R' U R U2' R')'&quot;</code>
</h2>
<div class="multi" id="experimental-start-setup">
<div class="multi" id="setup-alg">
<span>DOM attributes:</span>
<span>Constructor config object:</span>
<span>Dynamic property setter:</span>
<twisty-player
alg="R U R' U R U2' R'"
experimental-start-setup="(R U R' U R U2' R')'"
setup-alg="(R U R' U R U2' R')'"
></twisty-player>
</div>
</div>
Expand Down Expand Up @@ -170,7 +170,7 @@ <h2><code>camera-position=&quot;[-3, 4, 5]&quot;</code></h2>
<h2>
<code
>alg=&quot;R U R' U R U2' R'&quot;<br />
experimental-start-setup=&quot;(R U R' U R U2' R')'&quot;<br />
setup-alg=&quot;(R U R' U R U2' R')'&quot;<br />
experimental-stickering=&quot;OLL&quot;<br />
background=&quot;none&quot;<br />
control-panel=&quot;none&quot;</code
Expand All @@ -181,7 +181,7 @@ <h2>
<span>Dynamic property setter:</span>
<twisty-player
alg="R U R' U R U2' R'"
experimental-start-setup="(R U R' U R U2' R')'"
setup-alg="(R U R' U R U2' R')'"
experimental-stickering="OLL"
background="none"
control-panel="none"
Expand Down
12 changes: 6 additions & 6 deletions src/demo/twisty/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ experimentalSetShareAllNewRenderers(true);
}

{
document.querySelector("#experimental-start-setup")!.appendChild(
document.querySelector("#setup-alg")!.appendChild(
new TwistyPlayer({
experimentalStartSetup: parseAlg("(R U R' U R U2' R')'"),
setupAlg: parseAlg("(R U R' U R U2' R')'"),
}),
);
const tw = new TwistyPlayer();
document.querySelector("#experimental-start-setup")!.appendChild(tw);
tw.experimentalStartSetup = parseAlg("(R U R' U R U2' R')'");
document.querySelector("#setup-alg")!.appendChild(tw);
tw.setupAlg = parseAlg("(R U R' U R U2' R')'");
}

{
Expand Down Expand Up @@ -144,7 +144,7 @@ experimentalSetShareAllNewRenderers(true);
new TwistyPlayer({
alg: parseAlg("R U R' U R U2' R'"),
experimentalStickering: "OLL",
experimentalStartSetup: parseAlg("(R U R' U R U2' R')'"),
setupAlg: parseAlg("(R U R' U R U2' R')'"),
background: "none",
controlPanel: "none",
}),
Expand All @@ -153,7 +153,7 @@ experimentalSetShareAllNewRenderers(true);
document.querySelector("#multiple-attributes")!.appendChild(tw);
tw.alg = parseAlg("R U R' U R U2' R'");
tw.experimentalStickering = "OLL";
tw.experimentalStartSetup = parseAlg("(R U R' U R U2' R')'");
tw.setupAlg = parseAlg("(R U R' U R U2' R')'");
tw.background = "none";
tw.controlPanel = "none";
}
2 changes: 1 addition & 1 deletion src/demo/twisty/cube3d-stickering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function demo(visualization: VisualizationFormat): void {
const div = content.appendChild(document.createElement("div"));
div.classList.add("case");
const twistyPlayer = new TwistyPlayer({
experimentalStartSetup: invert(parseAlg(s)),
setupAlg: invert(parseAlg(s)),
alg: parseAlg(s),
visualization,
experimentalStickering: stickering,
Expand Down
2 changes: 1 addition & 1 deletion src/demo/twisty/simultaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import supercubeSprite from "url:./supercube-sprite.png";
{
const player = new TwistyPlayer({
alg: parseAlg("M' R' U' D' M R"),
experimentalStartSetup: parseAlg("(M' R' U' D' M R)'"),
setupAlg: parseAlg("(M' R' U' D' M R)'"),
});
player.experimentalSetCursorIndexer("simultaneous");
document.querySelector(".demo2")!.appendChild(player);
Expand Down
2 changes: 1 addition & 1 deletion src/demo/twisty/twisty-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const table = contentElem.appendChild(document.createElement("table"));

const algOptions: [string, string, Sequence][] = [
["alg", "alg", parseAlg("R U R'")],
["experimentalStartSetup", "experimental-start-setup", parseAlg("")],
["setupAlg", "setup-alg", parseAlg("")],
];

for (const [propName, attrName, alg] of algOptions) {
Expand Down

0 comments on commit 55677a3

Please sign in to comment.