Skip to content

Commit 048f07e

Browse files
committed
[twisty] Toggle 2D hint facelets based on the existing prop.
See: #349 (comment)
1 parent e6666ee commit 048f07e

4 files changed

Lines changed: 41 additions & 13 deletions

File tree

src/cubing/puzzles/implementations/dynamic/3x3x3/3x3x3.kpuzzle.svg.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ export const cube3x3x3SVG = `<?xml version="1.0" encoding="UTF-8"?>
1515
</g>
1616
</defs>
1717
<g id="puzzle" transform="translate(5,40) scale(40)">
18-
<!-- Hints -->
19-
<use data-copy-id="CORNERS-l0-o1" href="#sticker-thin-v" transform="translate(6.5,2.1)" style="fill: red"/>
20-
<use data-copy-id="EDGES-l1-o1" href="#sticker-thin-v" transform="translate(6.5,1.1)" style="fill: red"/>
21-
<use data-copy-id="CORNERS-l1-o2" href="#sticker-thin-v" transform="translate(6.5,0.1)" style="fill: red"/>
22-
23-
<use data-copy-id="CORNERS-l2-o2" href="#sticker-thin-h" transform="translate(3.3,-0.6)" style="fill: #26f"/>
24-
<use data-copy-id="EDGES-l2-o1" href="#sticker-thin-h" transform="translate(4.3,-0.6)" style="fill: #26f"/>
25-
<use data-copy-id="CORNERS-l1-o1" href="#sticker-thin-h" transform="translate(5.3,-0.6)" style="fill: #26f"/>
26-
27-
<use data-copy-id="CORNERS-l3-o2" href="#sticker-thin-v" transform="translate(2.6,2.1)" style="fill: orange"/>
28-
<use data-copy-id="EDGES-l3-o1" href="#sticker-thin-v" transform="translate(2.6,1.1)" style="fill: orange"/>
29-
<use data-copy-id="CORNERS-l2-o1" href="#sticker-thin-v" transform="translate(2.6,0.1)" style="fill: orange"/>
18+
<g class="hint-facelet">
19+
<use data-copy-id="CORNERS-l0-o1" href="#sticker-thin-v" transform="translate(6.5,2.1)" style="fill: red"/>
20+
<use data-copy-id="EDGES-l1-o1" href="#sticker-thin-v" transform="translate(6.5,1.1)" style="fill: red"/>
21+
<use data-copy-id="CORNERS-l1-o2" href="#sticker-thin-v" transform="translate(6.5,0.1)" style="fill: red"/>
22+
23+
<use data-copy-id="CORNERS-l2-o2" href="#sticker-thin-h" transform="translate(3.3,-0.6)" style="fill: #26f"/>
24+
<use data-copy-id="EDGES-l2-o1" href="#sticker-thin-h" transform="translate(4.3,-0.6)" style="fill: #26f"/>
25+
<use data-copy-id="CORNERS-l1-o1" href="#sticker-thin-h" transform="translate(5.3,-0.6)" style="fill: #26f"/>
26+
27+
<use data-copy-id="CORNERS-l3-o2" href="#sticker-thin-v" transform="translate(2.6,2.1)" style="fill: orange"/>
28+
<use data-copy-id="EDGES-l3-o1" href="#sticker-thin-v" transform="translate(2.6,1.1)" style="fill: orange"/>
29+
<use data-copy-id="CORNERS-l2-o1" href="#sticker-thin-v" transform="translate(2.6,0.1)" style="fill: orange"/>
30+
</g>
3031
3132
<!-- CORNERS -->
3233
<use id="CORNERS-l0-o0" href="#sticker" transform="translate(5.3,2.1)" style="fill: white"/>

src/cubing/twisty/model/props/puzzle/display/HintFaceletProp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SimpleTwistyPropSource } from "../../TwistyProp";
22

3-
// TODO: turn these maps into lists?
3+
// TODO: turn these maps into `Set`s?
44
export const hintFaceletStyles = {
55
floating: true, // default
66
none: true,

src/cubing/twisty/views/2D/Twisty2DPuzzle.css.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@ svg {
3434
from { opacity: 0; }
3535
to { opacity: 1; }
3636
}
37+
38+
.hint-facelets-none .hint-facelet {
39+
display: none;
40+
}
3741
`,
3842
);

src/cubing/twisty/views/2D/Twisty2DPuzzle.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import type { KPuzzle } from "../../../kpuzzle";
22
import type { ExperimentalStickeringMask } from "../../../puzzles/cubing-private";
33
import type { PuzzleLoader } from "../../../puzzles/PuzzleLoader";
44
import type { StickeringMask } from "../../../puzzles/stickerings/mask";
5+
import {
6+
type HintFaceletStyleWithAuto,
7+
hintFaceletStyles,
8+
} from "../../../twisty/model/props/puzzle/display/HintFaceletProp";
59
import type { PuzzleID } from "../..";
610
import {
711
Direction,
@@ -11,6 +15,7 @@ import {
1115
import { RenderScheduler } from "../../controllers/RenderScheduler";
1216
import { FreshListenerManager } from "../../model/props/TwistyProp";
1317
import type { TwistyPlayerModel } from "../../model/TwistyPlayerModel";
18+
import { ClassListManager } from "../ClassListManager";
1419
import { ManagedCustomElement } from "../ManagedCustomElement";
1520
import { customElementsShim } from "../node-custom-element-shims";
1621
import { twisty2DSVGCSS } from "./Twisty2DPuzzle.css";
@@ -49,6 +54,13 @@ export class Twisty2DPuzzle
4954
},
5055
);
5156

57+
this.#freshListenerManager.addListener(
58+
this.model!.twistySceneModel.hintFacelet,
59+
(hintFacelet) => {
60+
this.setHintFacelet(hintFacelet);
61+
},
62+
);
63+
5264
this.#freshListenerManager.addListener(
5365
this.model!.legacyPosition,
5466
this.onPositionChange.bind(this),
@@ -125,6 +137,17 @@ export class Twisty2DPuzzle
125137
}
126138
}
127139

140+
private hintFaceletsClassListManager = new ClassListManager(
141+
this,
142+
"hint-facelets-",
143+
Object.keys(hintFaceletStyles),
144+
);
145+
setHintFacelet(hintFacelet: HintFaceletStyleWithAuto) {
146+
this.hintFaceletsClassListManager.setValue(
147+
hintFacelet === "auto" ? "floating" : hintFacelet,
148+
);
149+
}
150+
128151
private render(): void {
129152
/*...*/
130153
}

0 commit comments

Comments
 (0)