Skip to content

Commit

Permalink
Merge branch 'integration-test-recorder-115'. Close #115
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Oct 18, 2015
2 parents e64420a + bfb089d commit 6a4bf8c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pacmacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,23 @@
;;;###autoload
(defun pacmacs-start ()
(interactive)
(pacmacs--initialize-game 'pacmacs-tick)
(pacmacs-mode))

(defun pacmacs--initialize-game (tick-function)
(switch-to-buffer pacmacs-buffer-name)
(pacmacs-mode)

(setq pacmacs-lives 3)
(setq pacmacs-score 0)
(setq pacmacs-levels (pacmacs--get-list-of-levels))
(setq pacmacs-current-level 0)

(pacmacs--load-current-level)
(pacmacs--switch-to-play-state)

(unless pacmacs-timer
(setq pacmacs-timer (run-at-time nil (* pacmacs-tick-duration-ms 0.001) 'pacmacs-tick))))
(setq pacmacs-timer (run-at-time nil (* pacmacs-tick-duration-ms 0.001)
tick-function))))

(defun pacmacs-destroy ()
(when pacmacs-timer
Expand Down
60 changes: 60 additions & 0 deletions tools/it-recorder.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
(require 'pacmacs)

(require 'cl-lib)

(defvar pacmacs--tick-counter 0)
(defvar pacmacs--recorded-actions nil)

(defun pacmacs--record-action (action-name)
(add-to-list 'pacmacs--recorded-actions
(cons action-name pacmacs--tick-counter)))

(defun pacmacs--reset-recorder ()
(setq pacmacs--tick-counter 0)
(setq pacmacs--recorded-actions nil))

(defun pacmacs--save-test-case (filename)
(interactive "FFile to save the test case: ")
(with-temp-buffer
(-> pacmacs--recorded-actions
(reverse)
(pp-to-string)
(insert))
(write-file filename)))

(defun pacmacs-record-up ()
(interactive)
(pacmacs--record-action 'up)
(pacmacs-up))

(defun pacmacs-record-down ()
(interactive)
(pacmacs--record-action 'down)
(pacmacs-down))

(defun pacmacs-record-left ()
(interactive)
(pacmacs--record-action 'left)
(pacmacs-left))

(defun pacmacs-record-right ()
(interactive)
(pacmacs--record-action 'right)
(pacmacs-right))

(defun pacmacs-record-tick ()
(interactive)
(cl-incf pacmacs--tick-counter)
(pacmacs-tick))

(define-derived-mode pacmacs-it-recorder-mode pacmacs-mode "pacmacs-it-recorder-mode"
(define-key pacmacs-it-recorder-mode-map (kbd "<up>") 'pacmacs-record-up)
(define-key pacmacs-it-recorder-mode-map (kbd "<down>") 'pacmacs-record-down)
(define-key pacmacs-it-recorder-mode-map (kbd "<left>") 'pacmacs-record-left)
(define-key pacmacs-it-recorder-mode-map (kbd "<right>") 'pacmacs-record-right))

(defun pacmacs--start-it-recorder ()
(interactive)
(pacmacs--initialize-game 'pacmacs-record-tick)
(pacmacs-it-recorder-mode)
(pacmacs--reset-recorder))

0 comments on commit 6a4bf8c

Please sign in to comment.