diff --git a/database/run.lisp b/database/run.lisp index 21d278a..a72f52e 100644 --- a/database/run.lisp +++ b/database/run.lisp @@ -16,6 +16,20 @@ (sxql:order-by :category_split_id) (sxql:where (:= :run run)))) +;; Returns the elapsed time in milliseconds since split started to either +;; current time or the split's end time +(defun run-split-elapsed-time (run-split) + (let ((start (ignore-errors (run-split-start-time run-split))) + (end (or (ignore-errors (run-split-end-time run-split)) (local-time:now)))) + (if start + (floor (* 1000 (local-time:timestamp-difference end start)))))) + +(defun format-elapsed-time (run-split) + (let ((elapsed (run-split-elapsed-time run-split))) + (if elapsed + (format-time (make-time-alist elapsed)) + "-"))) + ;; Returns stuff like PB, best of each split, etc. (defun run-statistics (category) `((asdf . 1))) diff --git a/main.lisp b/main.lisp index 57a1d29..cfe5d38 100644 --- a/main.lisp +++ b/main.lisp @@ -69,13 +69,25 @@ (uiop/os:getcwd)) 'probe-file))) ('NEW-CATEGORY - (format t "NEW CATEGORY~%")) + (let* ((name (get-input "Category Name (e.g. \"SM64\"): " 'not-empty-string)) + (percentage (get-input "Percentage (e.g. \"16 Star\"): " 'not-empty-string)) + (category (mito:insert-dao (make-instance 'category :name name :percentage percentage))) + (splits (do ((spliti 1 (1+ spliti)) + (inputs '() (push (get-input (format nil "Split [~a]: " spliti)) inputs))) + ((equal (car inputs) "") + (mapcar (lambda + (category-split-name) + (mito:insert-dao + (make-instance 'category-split + :name category-split-name + :category category))) + (reverse (cdr inputs))))))))) ('START-SPEEDRUN - (let* ((categories (mito:select-dao 'category)) - (category-alist (mapcar (lambda (category) `(,(category-name category) . ,category)) categories))) - (if categories - (speedrun-ui (select-option category-alist)) - (format t "E: There are no categories. Try creating one or importing one")))) + (let* ((categories (mito:select-dao 'category)) + (category-alist (mapcar (lambda (category) `(,(format nil "~a - ~a" (category-name category) (category-percentage category)) . ,category)) categories))) + (if categories + (speedrun-ui (select-option category-alist)) + (format t "E: There are no categories. Try creating one or importing one")))) ('EXIT (quit)))) (format t "~%") diff --git a/ui.lisp b/ui.lisp index 697b9ee..e574767 100644 --- a/ui.lisp +++ b/ui.lisp @@ -97,7 +97,7 @@ (if (member 'title-instance redraws) (croatoan:clear scr) (let* ((padding 4) - (title (append *lispruns-logo* '("" "CONTROLS" " SPACE to start or continue to the next split" " Q to quit"))) + (title (append *lispruns-logo* '("" "CONTROLS" " SPACE to start and to continue to the next split" " Q to quit"))) (width (+ (* 2 padding) (max-length title))) (height (+ (* 2 padding) (length title))) (logo-centered (center-box scr width height)) @@ -121,10 +121,18 @@ (splits-height (- (croatoan:height scr) timer-height)) (split-list (make-instance 'highlight-list :scroll-i scroll - :current-element-index (if (eq (speedrun-state speedrun) 'STOPPED) (1- (length (speedrun-splits speedrun))) (speedrun-current-split-index speedrun)) + :current-element-index (speedrun-current-split-index speedrun) :height splits-height :width max-width - :elements (mapcar #'category-split-name csplits))) + :elements (mapcar (lambda (csplit speedrun-split) + `( + (,(category-split-name csplit) . ,(/ 4 12)) + ("" . ,(/ 1 12)) + (,(format-elapsed-time speedrun-split) . ,(/ 3 12)) + )) + csplits + (speedrun-splits speedrun)))) +;; :elements (mapcar #'category-split-name csplits))) ;; :elements `((("FIRST SPLIT IS EPIC" . ,(/ 4 12)) ("" . ,(/ 1 12)) ("10:10:00.22" . ,(/ 3 12)) ("" . ,(/ 1 12)) ("20:00.00" . ,(/ 3 12)))))) (splits-instance (highlight-list-window split-list `(0 ,centered-x))) (timer-instance (timer-window speedrun `(,splits-height ,centered-x) max-width timer-height))) diff --git a/util.lisp b/util.lisp index 180a1e3..3369a03 100644 --- a/util.lisp +++ b/util.lisp @@ -9,3 +9,6 @@ (defun max-length (lists) (reduce (lambda (a x) (max a x)) (mapcar #'length lists))) + +(defun not-empty-string (str) + (not (zerop (length str))))