emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/pacmacs a896a83366 312/472: Merge pull request #164 from c


From: ELPA Syncer
Subject: [nongnu] elpa/pacmacs a896a83366 312/472: Merge pull request #164 from codingteam/blink-almost-timed-out-159
Date: Thu, 6 Jan 2022 21:59:35 -0500 (EST)

branch: elpa/pacmacs
commit a896a833664450b792742c479c5dd98d1c42fa2c
Merge: 3758d601d3 d608708f15
Author: Alexey Kutepov <reximkut@gmail.com>
Commit: Alexey Kutepov <reximkut@gmail.com>

    Merge pull request #164 from codingteam/blink-almost-timed-out-159
    
    Blink almost timed out terrified ghosts
---
 pacmacs.el           | 25 +++++++++++++++++++++++--
 test/pacmacs-test.el | 16 ++++++++++++++++
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/pacmacs.el b/pacmacs.el
index e0887ab881..c969715207 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -49,6 +49,8 @@
 
 (defconst pacmacs-buffer-name "*Pacmacs*")
 (defconst pacmacs-tick-duration-ms 100)
+(defconst pacmacs--ghost-blinking-threshold-ms 2500)
+(defconst pacmacs--ghost-terrified-time-ms 5000)
 
 (defvar pacmacs-debug-output nil)
 
@@ -151,6 +153,22 @@
                  (cl-decf terrified-timer
                           pacmacs-tick-duration-ms)))))
 
+(defun pacmacs--handle-ghost-blinking-threshold ()
+  (dolist (terrified-ghost pacmacs--terrified-ghosts)
+    (plist-bind ((terrified-timer :terrified-timer))
+        terrified-ghost
+      (when
+          ;; FIXME: In Emacs 24.3 `<=` accepts only 2
+          ;; arguments. Please rewrite this when Emacs 24.3 is finally
+          ;; dropped.
+          (and (<= terrified-timer
+                   pacmacs--ghost-blinking-threshold-ms)
+               (<= pacmacs--ghost-blinking-threshold-ms
+                   (+ terrified-timer pacmacs-tick-duration-ms)))
+        (plist-put terrified-ghost
+                   :current-animation
+                   (pacmacs-load-anim "Blinking-Terrified-Ghost"))))))
+
 (defun pacmacs--switch-direction-animation-callback (animation-prefix)
   (let ((direction-animations (-mapcat
                                (-lambda (direction)
@@ -182,7 +200,7 @@
         :speed 1
         :speed-counter 0
         :type 'terrified-ghost
-        :terrified-timer 5000))
+        :terrified-timer pacmacs--ghost-terrified-time-ms))
 
 (defun pacmacs--make-ghost (row column)
   (list :row row
@@ -475,7 +493,11 @@
     (pacmacs--anim-object-list-next-frame pacmacs--terrified-ghosts 
pacmacs-tick-duration-ms)
 
     (pacmacs--recalc-track-board)
+
     (pacmacs--unterrify-timed-out-ghosts)
+    (pacmacs--decrease-terrified-timers)
+    (pacmacs--handle-ghost-blinking-threshold)
+
     (if pacmacs--pills
         (progn
           (pacmacs--step-object pacmacs--player-state)
@@ -487,7 +509,6 @@
             (pacmacs--step-ghosts)
             (pacmacs--step-terrified-ghosts)
             (pacmacs--detect-terrified-ghost-collision)
-            (pacmacs--decrease-terrified-timers)
             (when (pacmacs--ghost-collision-p)
               (dolist (ghost pacmacs--ghosts)
                 (pacmacs--step-back-object ghost))
diff --git a/test/pacmacs-test.el b/test/pacmacs-test.el
index 2575314fe9..f2be579b06 100644
--- a/test/pacmacs-test.el
+++ b/test/pacmacs-test.el
@@ -90,3 +90,19 @@
     (should (equal '((:row 30 :column 40)
                      (:row 10 :column 20))
                    destroyed-objects))))
+
+(ert-deftest pacmacs--handle-ghost-blinking-threshold-test ()
+  (let ((pacmacs--terrified-ghosts '((:terrified-timer 900 :current-animation 
1)
+                                     (:terrified-timer 999 :current-animation 
2)
+                                     (:terrified-timer 1001 :current-animation 
3)
+                                     (:terrified-timer 899 :current-animation 
4)))
+        (pacmacs-tick-duration-ms 100)
+        (pacmacs--ghost-blinking-threshold-ms 1000))
+    (with-mock
+     (mock (pacmacs-load-anim "Blinking-Terrified-Ghost") => 42 :times 2)
+     (pacmacs--handle-ghost-blinking-threshold)
+     (should (equal '((:terrified-timer 900 :current-animation 42)
+                      (:terrified-timer 999 :current-animation 42)
+                      (:terrified-timer 1001 :current-animation 3)
+                      (:terrified-timer 899 :current-animation 4))
+                    pacmacs--terrified-ghosts)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]