[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))))
- [nongnu] elpa/pacmacs 9e7685b818 248/472: Drop XBM support for wall tiles (#141), (continued)
- [nongnu] elpa/pacmacs 9e7685b818 248/472: Drop XBM support for wall tiles (#141), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 5ec5ce8e67 267/472: Remove that pacmacs--object-at-p already!, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs c571f5874c 272/472: Extract wall bits normalization, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 9a9ecb6679 283/472: Implement direction switching callbacks (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e710f00f69 295/472: Remove pacmacs--unterrify-all-ghosts (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e1ae35d526 316/472: Minimal version of 24.4 as the package requirement, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 73fcaa8a91 324/472: Remove pacmacs--vector+ (#159), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e228a3c95d 334/472: Add 5th big pill level (#162), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 4924601822 341/472: UT for unterrify-ghost function (#171), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 0990672a5b 348/472: Fix stupid typos and mistakes -_-, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 9cb0cbab39 352/472: Merge pull request #172 from codingteam/unterrified-original-possition-171,
ELPA Syncer <=
- [nongnu] elpa/pacmacs 61c37f08b1 355/472: Update URL in the headers (#178), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs fad3786449 361/472: Use push instead of add-to-list (#173), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 6a91d72f35 359/472: terrify-ghost instead of reset-terrified-ghost, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs f7f962303b 371/472: Use background for start gradient color (#138), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs c7a3a4cbac 388/472: Merge pull request #184 from codingteam/update-readme-179, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs ecf71a3f49 378/472: Rename put-bits-dot to put-wall-tile-corner (#138), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs d7c9d248e6 385/472: Pass wall bits to create-wall-tile as list (#138), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 66cdd67cbb 387/472: Merge pull request #186 from codingteam/prettier-walls-138, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 365bfaee8e 386/472: Fix create-wall-tile UT (#138), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs f9c2eada4c 390/472: Move measure-time function to pacmacs-rr module, ELPA Syncer, 2022/01/06