Skip to content

Commit 64c6cf9

Browse files
committed
<twisty-player-v2>: Factor out setters.
TypeScript doesn't have `writeonly`, so we're keeping the code very explicit for now: microsoft/TypeScript#21759
1 parent 0739e90 commit 64c6cf9

File tree

2 files changed

+111
-168
lines changed

2 files changed

+111
-168
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import type { ExperimentalStickering } from "../../..";
2+
import type { Alg } from "../../../../alg";
3+
import type { MillisecondTimestamp } from "../../../animation/cursor/CursorTypes";
4+
import { ManagedCustomElement } from "../../element/ManagedCustomElement";
5+
import type { PuzzleID, SetupToLocation } from "../../TwistyPlayerConfig";
6+
import type { BackgroundThemeWithAuto } from "../props/depth-0/BackgroundProp";
7+
import type { BackViewLayoutWithAuto } from "../props/depth-0/BackViewProp";
8+
import type { ControlPanelThemeWithAuto } from "../props/depth-0/ControlPanelProp";
9+
import type { HintFaceletStyleWithAuto } from "../props/depth-0/HintFaceletProp";
10+
import type { IndexerStrategyName } from "../props/depth-0/IndexerConstructorRequestProp";
11+
import type { ViewerLinkPageWithAuto } from "../props/depth-0/ViewerLinkProp";
12+
import type { VisualizationFormatWithAuto } from "../props/depth-0/VisualizationProp";
13+
import { TwistyPlayerModel } from "../props/TwistyPlayerModel";
14+
15+
function err(propName: string): Error {
16+
return new Error(
17+
`Cannot get \`.${propName}\` directly from a \`TwistyPlayer\`.`,
18+
);
19+
}
20+
21+
// prettier-ignore
22+
export abstract class TwistyPlayerSettable extends ManagedCustomElement {
23+
model: TwistyPlayerModel = new TwistyPlayerModel();
24+
25+
set alg(newAlg: Alg | string) { this.model.algProp.set(newAlg); }
26+
get alg(): never { throw err("alg"); }
27+
28+
set setup(newSetup: Alg | string) { this.model.setupProp.set(newSetup); }
29+
get setup(): never { throw err("setup"); }
30+
31+
set experimentalSetupAnchor(anchor: SetupToLocation) { this.model.setupAnchorProp.set(anchor); }
32+
get experimentalSetupAnchor(): never { throw err("anchor"); }
33+
34+
set puzzle(puzzleID: PuzzleID) { this.model.puzzleProp.set(puzzleID); }
35+
get puzzle(): never { throw err("puzzle"); }
36+
37+
set timestamp(timestamp: MillisecondTimestamp) { this.model.timestampRequestProp.set(timestamp); }
38+
get timestamp(): never { throw err("timestamp"); }
39+
40+
set hintFacelets(hintFaceletStyle: HintFaceletStyleWithAuto) { this.model.hintFaceletProp.set(hintFaceletStyle); }
41+
get hintFacelets(): never { throw err("hintFacelets"); }
42+
43+
set experimentalStickering(stickering: ExperimentalStickering) { this.model.stickeringProp.set(stickering); }
44+
get experimentalStickering(): never { throw err("stickering"); }
45+
46+
set backView(backView: BackViewLayoutWithAuto) { this.model.backViewProp.set(backView); }
47+
get backView(): never { throw err("backView"); }
48+
49+
set background(backgroundTheme: BackgroundThemeWithAuto) { this.model.backgroundProp.set(backgroundTheme); }
50+
get background(): never { throw err("background"); }
51+
52+
set controlPanel(newControlPanel: ControlPanelThemeWithAuto) { this.model.controlPanelProp.set(newControlPanel); }
53+
get controlPanel(): never { throw new Error( "Cannot get `.controlPanel` directly from a `TwistyPlayer`."); }
54+
55+
set visualization(visualizationFormat: VisualizationFormatWithAuto) { this.model.visualizationFormatProp.set(visualizationFormat); }
56+
get visualization(): never { throw new Error( "Cannot get `.visualization` directly from a `TwistyPlayer`."); }
57+
58+
set viewerLink(viewerLinkPage: ViewerLinkPageWithAuto) { this.model.viewerLinkProp.set(viewerLinkPage); }
59+
get viewerLink(): never { throw err("viewerLink"); }
60+
61+
set cameraLatitude(latitude: number) { this.model.orbitCoordinatesRequestProp.set({ latitude }); }
62+
get cameraLatitude(): never { throw new Error( "Cannot get `.cameraLatitude` directly from a `TwistyPlayer`."); }
63+
64+
set cameraLongitude(longitude: number) { this.model.orbitCoordinatesRequestProp.set({ longitude }); }
65+
get cameraLongitude(): never { throw new Error( "Cannot get `.cameraLongitude` directly from a `TwistyPlayer`."); }
66+
67+
set cameraDistance(distance: number) { this.model.orbitCoordinatesRequestProp.set({ distance }); }
68+
get cameraDistance(): never { throw new Error( "Cannot get `.cameraDistance` directly from a `TwistyPlayer`."); }
69+
70+
set cameraLatitudeLimit(latitudeLimit: number) { this.model.latitudeLimitProp.set(latitudeLimit); }
71+
get cameraLatitudeLimit(): never { throw new Error( "Cannot get `.cameraLatitudeLimit` directly from a `TwistyPlayer`."); }
72+
73+
set indexer(indexer: IndexerStrategyName) { this.model.indexerConstructorRequestProp.set(indexer); }
74+
get indexer(): never { throw err("indexer"); }
75+
76+
set tempoScale(newTempoScale: number) { this.model.tempoScaleProp.set(newTempoScale); }
77+
get tempoScale(): never { throw err("tempoScale"); }
78+
79+
static get observedAttributes(): string[] {
80+
return ["alg"];
81+
}
82+
83+
attributeChangedCallback(
84+
attributeName: string,
85+
_oldValue: string,
86+
newValue: string,
87+
): void {
88+
switch (attributeName) {
89+
case "alg":
90+
this.alg = newValue;
91+
return;
92+
case "control-panel":
93+
this.controlPanel = newValue as ControlPanelThemeWithAuto;
94+
return;
95+
case "visualization": //"experimental-2D-LL"
96+
this.visualization = newValue as VisualizationFormatWithAuto;
97+
return;
98+
case "experimental-stickering": //"OLL"
99+
this.experimentalStickering = newValue as ExperimentalStickering;
100+
return;
101+
case "experimental-setup-anchor": //"end"
102+
this.experimentalSetupAnchor = newValue as SetupToLocation;
103+
return;
104+
case "background": //"none"
105+
this.background = newValue as BackgroundThemeWithAuto;
106+
return;
107+
}
108+
}
109+
}

src/cubing/twisty/dom/twisty-player-model/controllers/TwistyPlayerV2.ts

+2-168
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { ExperimentalStickering } from "../../..";
2-
import type { Alg } from "../../../../alg";
3-
import type { MillisecondTimestamp } from "../../../animation/cursor/CursorTypes";
42
import { ClassListManager } from "../../element/ClassListManager";
5-
import { ManagedCustomElement } from "../../element/ManagedCustomElement";
63
import { customElementsShim } from "../../element/node-custom-element-shims";
74
import { twistyPlayerCSS } from "../../TwistyPlayer.css_";
85
import {
@@ -11,11 +8,7 @@ import {
118
SetupToLocation,
129
} from "../../TwistyPlayerConfig";
1310
import type { BackgroundThemeWithAuto } from "../props/depth-0/BackgroundProp";
14-
import type { BackViewLayoutWithAuto } from "../props/depth-0/BackViewProp";
1511
import type { ControlPanelThemeWithAuto } from "../props/depth-0/ControlPanelProp";
16-
import type { HintFaceletStyleWithAuto } from "../props/depth-0/HintFaceletProp";
17-
import type { IndexerStrategyName } from "../props/depth-0/IndexerConstructorRequestProp";
18-
import type { ViewerLinkPageWithAuto } from "../props/depth-0/ViewerLinkProp";
1912
import type { VisualizationFormatWithAuto } from "../props/depth-0/VisualizationProp";
2013
import { TwistyPlayerModel } from "../props/TwistyPlayerModel";
2114
import { Twisty2DSceneWrapper } from "./2D/Twisty2DSceneWrapper";
@@ -24,9 +17,10 @@ import { TwistyButtonsV2 } from "./control-panel/TwistyButtonsV2";
2417
import { TwistyScrubberV2 } from "./control-panel/TwistyScrubberV2";
2518
import type { TwistyAnimationControllerDelegate } from "./TwistyAnimationController";
2619
import { TwistyPlayerController } from "./TwistyPlayerController";
20+
import { TwistyPlayerSettable } from "./TwistyPlayerSettable";
2721

2822
export class TwistyPlayerV2
29-
extends ManagedCustomElement
23+
extends TwistyPlayerSettable
3024
implements TwistyAnimationControllerDelegate
3125
{
3226
model: TwistyPlayerModel = new TwistyPlayerModel();
@@ -119,166 +113,6 @@ export class TwistyPlayerV2
119113
}
120114
}
121115

122-
set alg(newAlg: Alg | string) {
123-
this.model.algProp.set(newAlg);
124-
}
125-
126-
get alg(): never {
127-
throw new Error("Cannot get `.alg` directly from a `TwistyPlayer`.");
128-
}
129-
130-
set setup(newSetup: Alg | string) {
131-
this.model.setupProp.set(newSetup);
132-
}
133-
134-
get setup(): never {
135-
throw new Error("Cannot get `.setup` directly from a `TwistyPlayer`.");
136-
}
137-
138-
set experimentalSetupAnchor(anchor: SetupToLocation) {
139-
this.model.setupAnchorProp.set(anchor);
140-
}
141-
142-
get experimentalSetupAnchor(): never {
143-
throw new Error("Cannot get `.anchor` directly from a `TwistyPlayer`.");
144-
}
145-
146-
set puzzle(puzzleID: PuzzleID) {
147-
this.model.puzzleProp.set(puzzleID);
148-
}
149-
150-
get puzzle(): never {
151-
throw new Error("Cannot get `.puzzle` directly from a `TwistyPlayer`.");
152-
}
153-
154-
set timestamp(timestamp: MillisecondTimestamp) {
155-
this.model.timestampRequestProp.set(timestamp);
156-
}
157-
158-
get timestamp(): never {
159-
throw new Error("Cannot get `.timestamp` directly from a `TwistyPlayer`.");
160-
}
161-
162-
set hintFacelets(hintFaceletStyle: HintFaceletStyleWithAuto) {
163-
this.model.hintFaceletProp.set(hintFaceletStyle);
164-
}
165-
166-
get hintFacelets(): never {
167-
throw new Error(
168-
"Cannot get `.hintFacelets` directly from a `TwistyPlayer`.",
169-
);
170-
}
171-
172-
set experimentalStickering(stickering: ExperimentalStickering) {
173-
this.model.stickeringProp.set(stickering);
174-
}
175-
176-
get experimentalStickering(): never {
177-
throw new Error("Cannot get `.stickering` directly from a `TwistyPlayer`.");
178-
}
179-
180-
set backView(backView: BackViewLayoutWithAuto) {
181-
this.model.backViewProp.set(backView);
182-
}
183-
184-
get backView(): never {
185-
throw new Error("Cannot get `.backView` directly from a `TwistyPlayer`.");
186-
}
187-
188-
set background(backgroundTheme: BackgroundThemeWithAuto) {
189-
this.model.backgroundProp.set(backgroundTheme);
190-
}
191-
192-
get background(): never {
193-
throw new Error("Cannot get `.background` directly from a `TwistyPlayer`.");
194-
}
195-
196-
set controlPanel(newControlPanel: ControlPanelThemeWithAuto) {
197-
this.model.controlPanelProp.set(newControlPanel);
198-
}
199-
200-
get controlPanel(): never {
201-
throw new Error(
202-
"Cannot get `.controlPanel` directly from a `TwistyPlayer`.",
203-
);
204-
}
205-
206-
set visualization(visualizationFormat: VisualizationFormatWithAuto) {
207-
this.model.visualizationFormatProp.set(visualizationFormat);
208-
}
209-
210-
get visualization(): never {
211-
throw new Error(
212-
"Cannot get `.visualization` directly from a `TwistyPlayer`.",
213-
);
214-
}
215-
216-
set viewerLink(viewerLinkPage: ViewerLinkPageWithAuto) {
217-
this.model.viewerLinkProp.set(viewerLinkPage);
218-
}
219-
220-
get viewerLink(): never {
221-
throw new Error("Cannot get `.viewerLink` directly from a `TwistyPlayer`.");
222-
}
223-
224-
set cameraLatitude(latitude: number) {
225-
this.model.orbitCoordinatesRequestProp.set({ latitude });
226-
}
227-
228-
get cameraLatitude(): never {
229-
throw new Error(
230-
"Cannot get `.cameraLatitude` directly from a `TwistyPlayer`.",
231-
);
232-
}
233-
234-
set cameraLongitude(longitude: number) {
235-
this.model.orbitCoordinatesRequestProp.set({ longitude });
236-
}
237-
238-
get cameraLongitude(): never {
239-
throw new Error(
240-
"Cannot get `.cameraLongitude` directly from a `TwistyPlayer`.",
241-
);
242-
}
243-
244-
set cameraDistance(distance: number) {
245-
this.model.orbitCoordinatesRequestProp.set({ distance });
246-
}
247-
248-
get cameraDistance(): never {
249-
throw new Error(
250-
"Cannot get `.cameraDistance` directly from a `TwistyPlayer`.",
251-
);
252-
}
253-
254-
set cameraLatitudeLimit(latitudeLimit: number) {
255-
this.model.latitudeLimitProp.set(latitudeLimit);
256-
}
257-
258-
get cameraLatitudeLimit(): never {
259-
throw new Error(
260-
"Cannot get `.cameraLatitudeLimit` directly from a `TwistyPlayer`.",
261-
);
262-
}
263-
264-
// TODO: this needs a much better name.
265-
set indexer(indexer: IndexerStrategyName) {
266-
this.model.indexerConstructorRequestProp.set(indexer);
267-
}
268-
269-
get indexer(): never {
270-
throw new Error("Cannot get `.indexer` directly from a `TwistyPlayer`.");
271-
}
272-
273-
// TODO: this needs a much better name.
274-
set tempoScale(newTempoScale: number) {
275-
this.model.tempoScaleProp.set(newTempoScale);
276-
}
277-
278-
get tempoScale(): never {
279-
throw new Error("Cannot get `.tempoScale` directly from a `TwistyPlayer`.");
280-
}
281-
282116
jumpToStart(options?: { flash: boolean }): void {
283117
this.controller.jumpToStart(options);
284118
}

0 commit comments

Comments
 (0)