@@ -299,21 +299,50 @@ <h2>Mines:</h2>
299299 }
300300
301301 function keyPressed ( ) {
302- if ( keyCode === 32 ) {
303- let mX = Math . floor ( ( mouseX - border ) / cellSize ) ;
304- let mY = Math . floor ( ( mouseY - headerSize - border ) / cellSize ) ;
305- let cell = game . grid [ mX + mY * game . width ] ;
306-
307- if ( ! cell . revealed ) {
308- game . flagCell ( mX , mY ) ;
309- }
310- } else if ( keyCode === 189 ) {
302+ if ( keyCode === 189 ) {
311303 game . calculateCellSizes ( cellSize - 5 ) ;
312304 manualSize = true ;
313305 } else if ( keyCode === 187 ) {
314306 game . calculateCellSizes ( cellSize + 5 ) ;
315307 manualSize = true ;
316308 }
309+
310+ let mX = Math . floor ( ( mouseX - border ) / cellSize ) ;
311+ let mY = Math . floor ( ( mouseY - headerSize - border ) / cellSize ) ;
312+ let cell = game . grid [ mX + mY * game . width ] ;
313+
314+ if ( mX < 0 || mX >= game . width || mY < 0 || mY >= game . height ) {
315+ return ;
316+ }
317+
318+ const shortcutsReveal = getPreferenceValue ( "shortcuts_reveal" ) ;
319+ const shortcutsFlag = getPreferenceValue ( "shortcuts_flag" ) ;
320+ const marksEnabled = getPreferenceValue ( "marks" ) ;
321+
322+ switch ( keyCode ) {
323+ case 32 : {
324+ if ( ! cell . revealed ) {
325+ game . flagCell ( mX , mY ) ;
326+ }
327+ break ;
328+ }
329+ case 90 : {
330+ if ( ! cell . revealed && ! cell . flagCell && ! cell . marked ) {
331+ game . revealCell ( mX , mY ) ;
332+ } else if ( cell . revealed && ! cell . flagged && ! cell . marked && shortcutsReveal ) {
333+ peekRadius ( mX , mY , "reveal" , true ) ;
334+ }
335+ break ;
336+ }
337+ case 88 : {
338+ if ( ! cell . revealed ) {
339+ game . flagCell ( mX , mY ) ;
340+ } else if ( cell . revealed && shortcutsFlag ) {
341+ peekRadius ( mX , mY , "flag" , true ) ;
342+ }
343+ break ;
344+ }
345+ }
317346 }
318347
319348 function clickLogic ( ) {
@@ -413,7 +442,7 @@ <h2>Mines:</h2>
413442 }
414443 }
415444
416- function peekRadius ( px , py , show ) {
445+ function peekRadius ( px , py , show , hideOverlay = false ) {
417446 let safeCount = 0 ;
418447 for ( let x = - 1 ; x <= 1 ; x ++ ) {
419448 for ( let y = - 1 ; y <= 1 ; y ++ ) {
@@ -444,7 +473,9 @@ <h2>Mines:</h2>
444473
445474 if ( cell . flagged || cell . marked ) safeCount ++ ;
446475
447- rect ( cX , cY , cellSize ) ;
476+ if ( ! hideOverlay ) {
477+ rect ( cX , cY , cellSize ) ;
478+ }
448479 }
449480
450481 if ( show === "reveal" && safeCount == game . grid [ px + py * game . width ] . count ) {
0 commit comments