@@ -9,6 +9,7 @@ const State = {
99 isDispatchReady : true , // don't allow multiple overlapping dispatches
1010 puzzleIndex : 0 ,
1111 wgslStatus : "" ,
12+ showSolution : false ,
1213} ;
1314
1415codeState = [ ] ;
@@ -122,7 +123,6 @@ function initializeEditor() {
122123 } ) ;
123124 AppState . editor . setKeyboardHandler ( "ace/keyboard/vim" ) ;
124125 // AppState.editor.setValue(initialContent || "");
125- console . log ( "Initial content:\n" , initialContent ) ;
126126 console . log ( "Editor initialized" ) ;
127127}
128128
@@ -151,6 +151,9 @@ function setupEventListeners() {
151151 document . getElementById ( "next" ) . addEventListener ( "click" , ( ) => {
152152 update ( { type : "selectPuzzle" , value : "next" } ) ;
153153 } ) ;
154+ document . getElementById ( "solution" ) . addEventListener ( "click" , ( ) => {
155+ update ( { type : "clickedSolution" } ) ;
156+ } ) ;
154157}
155158
156159////////////////////////////////////////
@@ -271,8 +274,15 @@ async function update(event) {
271274 } else {
272275 AppState . editor . setValue ( AppState . module . getTemplate ( AppState . puzzleIndex ) ) ;
273276 }
277+ // reset showSolution when starting a new puzzle
278+ AppState . showSolution = false ;
279+ }
280+ if ( event . type === "clickedSolution" ) {
281+ AppState . showSolution = ! AppState . showSolution ;
282+ console . log ( "showSolution: " , AppState . showSolution ) ;
274283 }
275284
285+
276286 updateEditor ( ) ;
277287 render ( ) ;
278288}
@@ -286,7 +296,7 @@ function render() {
286296 console . log ( "AppState.checkAnswer: " , AppState . checkAnswer ) ;
287297 document . getElementById ( "correct" ) . textContent = AppState . checkAnswer
288298 ? "Tests passed!"
289- : "Some tests failed." ;
299+ : "Some tests failed."
290300 if ( AppState . checkAnswer ) {
291301 document . getElementById ( "correct" ) . style . color = "LimeGreen" ;
292302 document . getElementById ( "correct" ) . style . fontWeight = "bold" ;
@@ -301,4 +311,14 @@ function render() {
301311 PuzzleSpec [ AppState . puzzleIndex ] . name ;
302312 document . getElementById ( "puzzle_description" ) . textContent =
303313 PuzzleSpec [ AppState . puzzleIndex ] . description ;
314+ if ( AppState . showSolution ) {
315+ document . getElementById ( "output" ) . style . display = "none" ;
316+ // use puzzleIndex to get markdown
317+ document . getElementById ( "writeup" ) . innerHTML = "<zero-md src=\"/assets/markdown/puzzle" + ( AppState . puzzleIndex + 1 ) + ".md\"></zero-md>" ;
318+ console . log ( "writeup: " , document . getElementById ( "writeup" ) . innerHTML ) ;
319+ document . getElementById ( "writeup" ) . style . display = "block" ;
320+ } else {
321+ document . getElementById ( "output" ) . style . display = "block" ;
322+ document . getElementById ( "writeup" ) . style . display = "none" ;
323+ }
304324}
0 commit comments