~octaspire/crates2

7eae434d29f7aeac879f0935b3acab0facf9b3b2 — octaspire 4 months ago 259e997
Add initial logging, fix arrow keys in ncurses representation

  * Use 'log4cl' library for logging.

  * Add command line option for logging into the given
    file name. Console logging is disabled, because it
    intervenes with the visual representations using
    textual "rendering" - currently plain text and
    cl-charms (ncurses).

  * Fix arrow keys in cl-charms (ncurses) input handling
    and map ESC key to :back event.

  * Log user input in cl-charms (ncurses) representation.
5 files changed, 29 insertions(+), 14 deletions(-)

M crates2-charms.asd
M crates2-text.asd
M doc/TODO.org
M src/charms.lisp
M src/main.lisp
M crates2-charms.asd => crates2-charms.asd +1 -1
@@ 13,7 13,7 @@
;; See the License for the specific language governing permissions and
;; limitations under the License.
(asdf:defsystem "crates2-charms"
  :depends-on (:alexandria :unix-opts :parse-float :trivial-garbage :cl-charms)
  :depends-on (:alexandria :unix-opts :parse-float :trivial-garbage :cl-charms :log4cl)
  :serial t
  :components ((:module src
                :components

M crates2-text.asd => crates2-text.asd +1 -1
@@ 13,7 13,7 @@
;; See the License for the specific language governing permissions and
;; limitations under the License.
(asdf:defsystem "crates2-text"
  :depends-on (:alexandria :unix-opts :parse-float :trivial-garbage)
  :depends-on (:alexandria :unix-opts :parse-float :trivial-garbage :log4cl)
  :serial t
  :components ((:module src
                :components

M doc/TODO.org => doc/TODO.org +1 -0
@@ 1,1 1,2 @@
- Move common parts from =charms= and =text= renderers into separate file.
- Add command line option for setting the logging level.

M src/charms.lisp => src/charms.lisp +15 -12
@@ 217,18 217,21 @@

(defun ui-read-input ()
  (let ((c (cl-charms/low-level:wgetch *crates2-window*)))
    (case c
      (119 :north)
      (cl-charms/low-level:KEY_UP :north)
      (115 :south)
      (cl-charms/low-level:KEY_DOWN :south)
      (97  :west)
      (cl-charms/low-level:KEY_LEFT :west)
      (100 :east)
      (cl-charms/low-level:KEY_RIGHT :east)
      (113 :back)
      (114 :restart)
      (otherwise nil))))
    (log:debug "Input is ~A" c)
    (cond
      ((or (= c (char-code #\w))
           (= c cl-charms/low-level:KEY_UP)) :north)
      ((or (= c (char-code #\s))
           (= c cl-charms/low-level:KEY_DOWN)) :south)
      ((or (= c (char-code #\a))
           (= c cl-charms/low-level:KEY_LEFT)) :west)
      ((or (= c (char-code #\d))
           (= c cl-charms/low-level:KEY_RIGHT)) :east)
      ((or (= c (char-code #\q))
           ;; Escape
           (= c 27)) :back)
      ((= c (char-code #\r)) :restart)
      (t nil))))

(defun ui-maybe-read-input ()
  (let ((player (find-first-crate-of-type 'player)))

M src/main.lisp => src/main.lisp +11 -0
@@ 47,6 47,12 @@
    (setf *next-level* nil)
    (setf *frame-duration* 0.05)))

(defun log-file-parser (x)
  ;; Set logging level. TODO make this configurable.
  (log:config :debug)
  ;; Log into the given file.
  (log:config :daily x))

(defun get-current-level()
  (unless *level*
    (load-next-level))


@@ 85,6 91,10 @@ This is similar to 'test' but runs much slower."
  (:name :log-input
   :description "Log and show user input after quitting game."
   :long "log-input")
  (:name :log-file
   :description "Log to given file."
   :long "log-file"
   :arg-parser #'log-file-parser)
  (:name :fullscreen
   :description "Run in fullscreen mode"
   :long "fullscreen"))


@@ 184,6 194,7 @@ This is similar to 'test' but runs much slower."
  (setf *next-level* (- *level-number* 1)))

(defun main ()
  (log:config :remove 1)                ; Remove console logging.
  (let ((options (handler-case
                     (handler-bind ((opts:arg-parser-failed #'parser-error)
                                    (opts:unknown-option    #'unknown-option))