Skip to content

Commit

Permalink
Fall back to 2D if 3D is not supported for the event.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed May 11, 2020
1 parent 8d5df2c commit 4ef6018
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/ScrambleDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,38 @@ export class ScrambleDisplay extends HTMLElement {
this.#currentAttributes.event = (this.getAttribute("event") ?? "333") as EventID;
this.#currentAttributes.visualization = (this.getAttribute("visualization") ?? "2D") as Visualization;
this.#currentAttributes.scramble = (this.getAttribute("scramble")) as string;

const render2D = () => {
if (!this.#currentAttributes.event) {
this.clearScrambleView();
throw new Error("Unspecified event.");
}
if (SVGPGScrambleView.eventImplemented(this.#currentAttributes.event)) {
const svgPGView = new SVGPGScrambleView(this.#currentAttributes.event);
this.setScrambleView(svgPGView, this.#currentAttributes.scramble);
} else if (SVG2DView.eventImplemented(this.#currentAttributes.event)) {
const svg2DView = new SVG2DView(this.#currentAttributes.event);
this.setScrambleView(svg2DView, this.#currentAttributes.scramble);
} else {
this.clearScrambleView();
throw new Error(`2D view is not implemented for this event (${this.#currentAttributes.event}).`);
}
}

switch (this.#currentAttributes.visualization) {
case "3D":
if (PG3DScrambleView.eventImplemented(this.#currentAttributes.event)) {
this.setScrambleView(new PG3DScrambleView(this.#currentAttributes.event), this.#currentAttributes.scramble);
} else if (this.#currentAttributes.event === "333") {
this.setScrambleView(new Cube3DScrambleView(), this.#currentAttributes.scramble);
} else {
this.clearScrambleView();
throw new Error(`3D view is not implemented for this event (${this.#currentAttributes.event}).`);
console.warn(`3D view is not implemented for this event yet (${this.#currentAttributes.event}). Falling back to 2D.`);
render2D();
}
break;
case "2D":
default:
if (!this.#currentAttributes.event) {
this.clearScrambleView();
throw new Error("Unspecified event.");
}
if (SVGPGScrambleView.eventImplemented(this.#currentAttributes.event)) {
const svgPGView = new SVGPGScrambleView(this.#currentAttributes.event);
this.setScrambleView(svgPGView, this.#currentAttributes.scramble);
break;
} else if (SVG2DView.eventImplemented(this.#currentAttributes.event)) {
const svg2DView = new SVG2DView(this.#currentAttributes.event);
this.setScrambleView(svg2DView, this.#currentAttributes.scramble);
break;
} else {
this.clearScrambleView();
throw new Error(`2D view is not implemented for this event (${this.#currentAttributes.event}).`);
}
render2D();
}
} else {
if (this.attributeChanged("scramble")) {
Expand Down

0 comments on commit 4ef6018

Please sign in to comment.