From d4e9417c32414b39e76d20a1b810d274de1f20e9 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Mon, 30 May 2022 22:45:29 -0700 Subject: Add simple cli for interfacing with program (not fully functional); show splits --- speedrun.lisp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'speedrun.lisp') diff --git a/speedrun.lisp b/speedrun.lisp index b78f75d..df473c9 100644 --- a/speedrun.lisp +++ b/speedrun.lisp @@ -52,16 +52,21 @@ (speedrun-start-timestamp speedrun) (get-internal-real-time) (run-split-start-time (current-split speedrun)) (local-time:now))) +;; Saves the speedrun into the database +(defun save-speedrun (speedrun) + (mapcar #'mito:save-dao (cons (speedrun-run-dao speedrun) (speedrun-splits speedrun)))) + ;; Set the state of the speedrun to be stopped if there are no more splits. ;; Or, set the current split to the next one in the list. (defun next-split (speedrun) (let ((now (local-time:now))) - (setf (run-split-end-time (current-split speedrun)) now) - (inc (speedrun-current-split-index speedrun)) - (if (equal (speedrun-current-split-index speedrun) (length (speedrun-splits speedrun))) - (setf (speedrun-state speedrun) 'STOPPED) - (setf (run-split-start-time (current-split speedrun)) now)))) + (unless (equal (speedrun-state speedrun) 'STOPPED) + (setf (run-split-end-time (current-split speedrun)) now) + (if (equal (speedrun-current-split-index speedrun) (1- (length (speedrun-splits speedrun)))) + (progn + (setf (speedrun-state speedrun) 'STOPPED) + (save-speedrun speedrun)) + (progn + (inc (speedrun-current-split-index speedrun)) + (setf (run-split-start-time (current-split speedrun)) now)))))) -;; Saves the speedrun into the database -(defun save-speedrun (speedrun) - (mapcar #'mito:save-dao (cons (speedrun-run-dao speedrun) (speedrun-splits speedrun)))) -- cgit v1.2.3-70-g09d2