@@ -118,12 +118,57 @@ export class App {
118
118
initialConfig . viewerLink = "none" ;
119
119
this . twistyPlayer = new TwistyPlayer ( initialConfig ) ;
120
120
this . puzzlePane . appendChild ( this . twistyPlayer ) ;
121
- const originalPuzzleID = initialConfig . puzzle ?? "3x3x3" ;
121
+
122
+ this . twistyPlayer . experimentalModel . puzzleSetupAlg . addFreshListener ( ( ) =>
123
+ this . #onSetupOrAlgChange( ) ,
124
+ ) ;
125
+ this . twistyPlayer . experimentalModel . puzzleAlg . addFreshListener ( ( ) =>
126
+ this . #onSetupOrAlgChange( ) ,
127
+ ) ;
128
+ this . element
129
+ . querySelector ( ".auto-notation-undo" ) !
130
+ . addEventListener ( "click" , ( ) => {
131
+ this . controlPane . puzzleSelect . value = this . #autoNotationPuzzleOld! ;
132
+ this . controlPane . puzzleSelectChanged ( ) ;
133
+ this . element . querySelector < HTMLSpanElement > (
134
+ ".auto-notation-change-back" ,
135
+ ) ! . hidden = true ;
136
+ this . element . querySelector < HTMLSpanElement > (
137
+ ".auto-notation-change-redo" ,
138
+ ) ! . hidden = false ;
139
+ this . #autofixEnabled = false ;
140
+ } ) ;
141
+ this . element
142
+ . querySelector ( ".auto-notation-redo" ) !
143
+ . addEventListener ( "click" , ( ) => {
144
+ this . controlPane . puzzleSelect . value = this . #autoNotationPuzzleNew! ;
145
+ this . controlPane . puzzleSelectChanged ( ) ;
146
+ this . element . querySelector < HTMLSpanElement > (
147
+ ".auto-notation-change-back" ,
148
+ ) ! . hidden = false ;
149
+ this . element . querySelector < HTMLSpanElement > (
150
+ ".auto-notation-change-redo" ,
151
+ ) ! . hidden = true ;
152
+ this . #autofixEnabled = true ;
153
+ } ) ;
154
+ }
155
+
156
+ #autoNotationPuzzleOld: PuzzleID | undefined ;
157
+ #autoNotationPuzzleNew: PuzzleID | undefined ;
158
+ #autofixEnabled: boolean = true ;
159
+ // TODO: factor this out into a class
160
+ async #onSetupOrAlgChange( ) {
161
+ console . log ( this . #autofixEnabled) ;
162
+ if ( ! this . #autofixEnabled) {
163
+ return ;
164
+ }
122
165
( async ( ) => {
123
- const [ puzzleAlgWithIssue , puzzleSetupAlgWithIssue ] = await Promise . all ( [
124
- this . twistyPlayer . experimentalModel . puzzleAlg . get ( ) ,
125
- this . twistyPlayer . experimentalModel . puzzleSetupAlg . get ( ) ,
126
- ] ) ;
166
+ const [ originalPuzzleID , puzzleAlgWithIssue , puzzleSetupAlgWithIssue ] =
167
+ await Promise . all ( [
168
+ this . twistyPlayer . experimentalModel . puzzleID . get ( ) ,
169
+ this . twistyPlayer . experimentalModel . puzzleAlg . get ( ) ,
170
+ this . twistyPlayer . experimentalModel . puzzleSetupAlg . get ( ) ,
171
+ ] ) ;
127
172
if (
128
173
puzzleAlgWithIssue . issues . errors . length > 0 ||
129
174
puzzleSetupAlgWithIssue . issues . errors . length > 0
@@ -132,7 +177,12 @@ export class App {
132
177
this . twistyPlayer . experimentalModel . alg . get ( ) ,
133
178
this . twistyPlayer . experimentalModel . setupAlg . get ( ) ,
134
179
] ) ;
135
- for ( const puzzleID of [ "square1" , "clock" , "megaminx" ] ) {
180
+ for ( const puzzleID of [
181
+ "3x3x3" ,
182
+ "square1" ,
183
+ "clock" ,
184
+ "megaminx" ,
185
+ ] satisfies PuzzleID [ ] ) {
136
186
const puzzleLoader = puzzles [ puzzleID ] ;
137
187
const kpuzzle = await puzzleLoader . kpuzzle ( ) ;
138
188
try {
@@ -142,23 +192,32 @@ export class App {
142
192
kpuzzle . defaultPattern ( ) . applyAlg ( algWithIssue . alg ) &&
143
193
kpuzzle . defaultPattern ( ) . applyAlg ( setupAlgWithIssue . alg ) // TODO: This ignores e.g. bandaging
144
194
) {
145
- this . element . querySelector ( ".auto-notation-puzzle" ) ! . textContent =
146
- puzzleLoader . fullName ;
195
+ this . #autoNotationPuzzleOld = originalPuzzleID ;
196
+ this . #autoNotationPuzzleNew = puzzleID ;
197
+
198
+ for ( const elem of this . element . querySelectorAll (
199
+ ".auto-notation-puzzle-old" ,
200
+ ) ) {
201
+ elem . textContent = puzzles [ originalPuzzleID ] . fullName ;
202
+ }
203
+ for ( const elem of this . element . querySelectorAll (
204
+ ".auto-notation-puzzle-new" ,
205
+ ) ) {
206
+ elem . textContent = puzzleLoader . fullName ;
207
+ }
208
+
147
209
this . element . querySelector < HTMLSpanElement > (
148
210
".auto-notation" ,
149
211
) ! . hidden = false ;
212
+ this . element . querySelector < HTMLSpanElement > (
213
+ ".auto-notation-change-back" ,
214
+ ) ! . hidden = false ;
215
+ this . element . querySelector < HTMLSpanElement > (
216
+ ".auto-notation-change-redo" ,
217
+ ) ! . hidden = true ;
218
+
150
219
this . controlPane . puzzleSelect . value = puzzleID ;
151
220
this . controlPane . puzzleSelectChanged ( ) ;
152
- this . element
153
- . querySelector ( ".auto-notation-undo" ) !
154
- . addEventListener ( "click" , ( ) => {
155
- this . controlPane . puzzleSelect . value = originalPuzzleID ;
156
- this . controlPane . puzzleSelectChanged ( ) ;
157
- this . element . querySelector (
158
- ".auto-notation-changed-back" ,
159
- ) ! . textContent =
160
- `This has been changed back to ${ puzzles [ originalPuzzleID ] . fullName } .` ;
161
- } ) ;
162
221
return ;
163
222
}
164
223
} catch { }
0 commit comments