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

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

[nongnu] elpa/pacmacs 9cb0cbab39 352/472: Merge pull request #172 from c


From: ELPA Syncer
Subject: [nongnu] elpa/pacmacs 9cb0cbab39 352/472: Merge pull request #172 from codingteam/unterrified-original-possition-171
Date: Thu, 6 Jan 2022 21:59:38 -0500 (EST)

branch: elpa/pacmacs
commit 9cb0cbab3984c91b3f72a078f7119777929554e9
Merge: 784b5c60e4 9375a8a3e7
Author: Alexey Kutepov <reximkut@gmail.com>
Commit: Alexey Kutepov <reximkut@gmail.com>

    Merge pull request #172 from codingteam/unterrified-original-possition-171
    
    Terrify/unterrify ghost without losing state
---
 pacmacs.el           | 63 ++++++++++++++++++++++---------------------
 test/pacmacs-test.el | 75 +++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 82 insertions(+), 56 deletions(-)

diff --git a/pacmacs.el b/pacmacs.el
index d93ee1a437..34327c80b2 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -417,43 +417,42 @@
     (pacmacs--track-object-from-player terrified-ghost)
     (pacmacs--step-object terrified-ghost)))
 
-(defun pacmacs--create-game-object (row column list-name constructor)
-  (let ((game-object (funcall constructor row column)))
-    (add-to-list list-name game-object)
-    (pacmacs--put-object game-object)))
-
-(defun pacmacs--create-terrified-ghost (row column)
-  (pacmacs--create-game-object row column 'pacmacs--terrified-ghosts
-                               #'pacmacs--make-terrified-ghost))
-
-(defun pacmacs--create-ghost (row column)
-  (pacmacs--create-game-object row column 'pacmacs--ghosts
-                               #'pacmacs--make-ghost))
-
-(defun pacmacs--replace-game-objects (game-objects new-constructor 
old-destructor)
-  (dolist (game-object game-objects)
-    (plist-bind ((row :row)
-                 (column :column))
-        game-object
-      (funcall new-constructor row column))
-    (funcall old-destructor game-object)))
+(defun pacmacs--terrified-ghost-timed-out-p (terrified-ghost)
+  (<= (plist-get terrified-ghost :terrified-timer) 0))
+
+(defun pacmacs--terrify-ghost (ghost)
+  (plist-put ghost :current-animation
+             (pacmacs-load-anim "Terrified-Ghost"))
+  (plist-put ghost :switch-direction-callback
+             #'pacmacs--switch-direction-callback)
+  (plist-put ghost :type 'terrified-ghost)
+  (plist-put ghost :terrified-timer
+             pacmacs--ghost-terrified-time-ms)
+  ghost)
+
+(defun pacmacs--unterrify-ghost (terrified-ghost)
+  (plist-put terrified-ghost :switch-direction-callback
+             (pacmacs--switch-direction-animation-callback "Red-Ghost"))
+  (plist-put terrified-ghost :type 'ghost)
+  (pacmacs--switch-direction terrified-ghost
+                             (plist-get terrified-ghost :direction))
+  terrified-ghost)
 
 (defun pacmacs--terrify-all-ghosts ()
-  (pacmacs--replace-game-objects pacmacs--ghosts
-                                 #'pacmacs--create-terrified-ghost
-                                 #'pacmacs--remove-object)
+  (dolist (ghost pacmacs--ghosts)
+    (add-to-list 'pacmacs--terrified-ghosts
+                 (pacmacs--terrify-ghost ghost)))
   (setq pacmacs--ghosts nil))
 
 (defun pacmacs--unterrify-timed-out-ghosts ()
-  (let ((timed-out-predicate
-         (-lambda (terrified-ghost)
-           (<= (plist-get terrified-ghost :terrified-timer) 0))))
-    (pacmacs--replace-game-objects
-     (-filter timed-out-predicate pacmacs--terrified-ghosts)
-     #'pacmacs--create-ghost
-     #'pacmacs--remove-object)
-    (setq pacmacs--terrified-ghosts (-remove timed-out-predicate
-                                             pacmacs--terrified-ghosts))))
+  (dolist (terrified-ghost (-filter #'pacmacs--terrified-ghost-timed-out-p
+                                    pacmacs--terrified-ghosts))
+    (add-to-list 'pacmacs--ghosts
+                 (pacmacs--unterrify-ghost terrified-ghost)))
+
+  (setq pacmacs--terrified-ghosts
+        (-remove #'pacmacs--terrified-ghost-timed-out-p
+                 pacmacs--terrified-ghosts)))
 
 (defun pacmacs--detect-pill-collision ()
   (plist-bind ((row :row)
diff --git a/test/pacmacs-test.el b/test/pacmacs-test.el
index 5c0858880b..f146abea6f 100644
--- a/test/pacmacs-test.el
+++ b/test/pacmacs-test.el
@@ -42,30 +42,6 @@
     (should (equal expected-outcome
                    pacmacs--terrified-ghosts))))
 
-(ert-deftest pacmacs--replace-game-objects-test ()
-  (let* ((game-objects '((:row 10 :column 20)
-                         (:row 30 :column 40)))
-         (replaced-objects nil)
-         (destroyed-objects nil)
-         (new-constructor (-lambda (row column)
-                            (setq replaced-objects
-                                  (cons (list :row (1+ row)
-                                              :column (1+ column))
-                                        replaced-objects))))
-         (old-destructor (-lambda (game-object)
-                           (setq destroyed-objects (cons game-object
-                                                         destroyed-objects)))))
-    (pacmacs--replace-game-objects game-objects new-constructor old-destructor)
-    (should (equal '((:row 10 :column 20)
-                     (:row 30 :column 40))
-                   game-objects))
-    (should (equal '((:row 31 :column 41)
-                     (:row 11 :column 21))
-                   replaced-objects))
-    (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)
@@ -89,3 +65,54 @@
      (mock (pacmacs--load-current-level) => nil)
      (pacmacs--load-next-level)
      (should (= 0 pacmacs-current-level)))))
+
+(ert-deftest pacmacs--terrify-ghost-test ()
+  (let* ((pacmacs--ghost-terrified-time-ms 60065)
+         (ghost (list :property-1 1
+                      :property-2 2
+                      :current-animation 'ghost-animation
+                      :switch-direction-callback 'ghost-direction-switcher
+                      :type 'ghost))
+         (terrified-ghost (list :property-1 1
+                                :property-2 2
+                                :current-animation 'terrified-ghost-animation
+                                :switch-direction-callback 
'pacmacs--switch-direction-callback
+                                :type 'terrified-ghost
+                                :terrified-timer 
pacmacs--ghost-terrified-time-ms)))
+    (with-mock
+     (mock (pacmacs-load-anim "Terrified-Ghost") => 'terrified-ghost-animation)
+     (should (equal terrified-ghost
+                    (pacmacs--terrify-ghost ghost))))))
+
+(ert-deftest pacmacs--unterrify-ghost-test ()
+  (let* ((pacmacs--ghost-terrified-time-ms 60065)
+         (terrified-ghost (list :property-1 1
+                                :property-2 2
+                                :direction 'right
+                                :current-animation 'terrified-ghost-animation
+                                :switch-direction-callback 
'terrified-ghost-direction-switcher
+                                :type 'terrified-ghost
+                                :terrified-timer 
pacmacs--ghost-terrified-time-ms))
+         (ghost (list :property-1 1
+                      :property-2 2
+                      :direction 'right
+                      :current-animation 'terrified-ghost-animation
+                      :switch-direction-callback 'ghost-direction-switcher
+                      :type 'ghost
+                      :terrified-timer pacmacs--ghost-terrified-time-ms)))
+    (with-mock
+     (mock (pacmacs--switch-direction * 'right))
+     (mock (pacmacs--switch-direction-animation-callback "Red-Ghost")
+           => 'ghost-direction-switcher)
+
+     (should (equal ghost
+                    (pacmacs--unterrify-ghost terrified-ghost))))))
+
+(ert-deftest pacmacs--terrified-ghost-timed-out-p-test ()
+  (should (not
+          (pacmacs--terrified-ghost-timed-out-p
+           (list :terrified-timer 60065))))
+  (should (pacmacs--terrified-ghost-timed-out-p
+           (list :terrified-timer 0)))
+  (should (pacmacs--terrified-ghost-timed-out-p
+           (list :terrified-timer -1))))



reply via email to

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