Quellcode durchsuchen

Abort NoMoreSecrets on key/left mouse click.

Ignore mouse up. ;)
Bugz vor 1 Jahr
Ursprung
Commit
614462537a
2 geänderte Dateien mit 27 neuen und 23 gelöschten Zeilen
  1. 26 22
      door/nomoresecrets.go
  2. 1 1
      door/wopr.go

+ 26 - 22
door/nomoresecrets.go

@@ -63,6 +63,28 @@ func nonRandom() byte {
 	return rb
 }
 
+// NoMoreSecrets Sleep
+//
+//	This allows the user to abort the effect with a key or left mouse click.
+func NMSSleep(Door *Door, sleep time.Duration) bool {
+	_, ex, err := Door.WaitKey(sleep)
+	if err == nil {
+		if ex == MOUSE {
+			m, ok := Door.GetMouse()
+			if ok {
+				if m.Button == 1 {
+					log.Println("NoMore")
+					return true
+				}
+			}
+			return false
+		}
+		log.Println("NoMore")
+		return true
+	}
+	return false
+}
+
 /*
 NoMoreSecrets - render output as random, then fade in the original text.
 
@@ -260,12 +282,7 @@ func NoMoreSecrets(output string, Door *Door, config *NoMoreSecretsConfig) {
 				return
 			}
 			// time.Sleep()
-			_, _, err := Door.WaitKey(time.Millisecond * time.Duration(config.Jumble_Loop_Speed))
-			if err == nil {
-				log.Println("NoMore")
-				keyAbort = true
-				break
-			}
+			keyAbort = NMSSleep(Door, time.Millisecond*time.Duration(config.Jumble_Loop_Speed))
 		}
 
 		for {
@@ -318,11 +335,7 @@ func NoMoreSecrets(output string, Door *Door, config *NoMoreSecretsConfig) {
 				return
 			}
 			// time.Sleep()
-			_, _, err := Door.WaitKey(time.Millisecond * time.Duration(config.Reveal_Loop_Speed))
-			if err == nil {
-				log.Println("NoMore")
-				keyAbort = true
-			}
+			keyAbort = NMSSleep(Door, time.Millisecond*time.Duration(config.Reveal_Loop_Speed))
 
 			if revealed {
 				break
@@ -465,12 +478,7 @@ func NoMoreSecrets(output string, Door *Door, config *NoMoreSecretsConfig) {
 				return
 			}
 			// time.Sleep()
-			_, _, err := Door.WaitKey(time.Millisecond * time.Duration(config.Jumble_Loop_Speed))
-			if err == nil {
-				log.Println("NoMore")
-				keyAbort = true
-				break
-			}
+			keyAbort = NMSSleep(Door, time.Millisecond*time.Duration(config.Jumble_Loop_Speed))
 		}
 
 		for {
@@ -514,11 +522,7 @@ func NoMoreSecrets(output string, Door *Door, config *NoMoreSecretsConfig) {
 				return
 			}
 			// time.Sleep()
-			_, _, err := Door.WaitKey(time.Millisecond * time.Duration(config.Reveal_Loop_Speed))
-			if err == nil {
-				log.Println("NoMore")
-				keyAbort = true
-			}
+			keyAbort = NMSSleep(Door, time.Millisecond*time.Duration(config.Reveal_Loop_Speed))
 			if revealed {
 				break
 			}

+ 1 - 1
door/wopr.go

@@ -178,7 +178,7 @@ func (w *WOPR) Animate(d *Door) {
 		// time.Sleep(time.Second - time.Duration(til)) // sec16 - (til % sec16))) //int64(time.Second) - til)) // time.Now().UnixMilli()%1000) * time.Millisecond)
 
 		// time.Second / 16
-		w.Ticker = time.NewTicker(time.Duration(sec16)) // time.Microsecond * time.Duration(62500))
+		w.Ticker = time.NewTicker(time.Duration(sec16))
 
 		var output string