Add elapsed time to each split

This commit is contained in:
Logan Hunt 2022-05-31 14:56:24 -07:00
parent e6fe31daef
commit 84e566e92b
Signed by untrusted user who does not match committer: simponic
GPG Key ID: 52B3774857EB24B1
4 changed files with 46 additions and 9 deletions

View File

@ -16,6 +16,20 @@
(sxql:order-by :category_split_id) (sxql:order-by :category_split_id)
(sxql:where (:= :run run)))) (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. ;; Returns stuff like PB, best of each split, etc.
(defun run-statistics (category) (defun run-statistics (category)
`((asdf . 1))) `((asdf . 1)))

View File

@ -69,13 +69,25 @@
(uiop/os:getcwd)) (uiop/os:getcwd))
'probe-file))) 'probe-file)))
('NEW-CATEGORY ('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 ('START-SPEEDRUN
(let* ((categories (mito:select-dao 'category)) (let* ((categories (mito:select-dao 'category))
(category-alist (mapcar (lambda (category) `(,(category-name category) . ,category)) categories))) (category-alist (mapcar (lambda (category) `(,(format nil "~a - ~a" (category-name category) (category-percentage category)) . ,category)) categories)))
(if categories (if categories
(speedrun-ui (select-option category-alist)) (speedrun-ui (select-option category-alist))
(format t "E: There are no categories. Try creating one or importing one")))) (format t "E: There are no categories. Try creating one or importing one"))))
('EXIT ('EXIT
(quit)))) (quit))))
(format t "~%") (format t "~%")

14
ui.lisp
View File

@ -97,7 +97,7 @@
(if (member 'title-instance redraws) (if (member 'title-instance redraws)
(croatoan:clear scr) (croatoan:clear scr)
(let* ((padding 4) (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))) (width (+ (* 2 padding) (max-length title)))
(height (+ (* 2 padding) (length title))) (height (+ (* 2 padding) (length title)))
(logo-centered (center-box scr width height)) (logo-centered (center-box scr width height))
@ -121,10 +121,18 @@
(splits-height (- (croatoan:height scr) timer-height)) (splits-height (- (croatoan:height scr) timer-height))
(split-list (make-instance 'highlight-list (split-list (make-instance 'highlight-list
:scroll-i scroll :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 :height splits-height
:width max-width :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)))))) ;; :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))) (splits-instance (highlight-list-window split-list `(0 ,centered-x)))
(timer-instance (timer-window speedrun `(,splits-height ,centered-x) max-width timer-height))) (timer-instance (timer-window speedrun `(,splits-height ,centered-x) max-width timer-height)))

View File

@ -9,3 +9,6 @@
(defun max-length (lists) (defun max-length (lists)
(reduce (lambda (a x) (max a x)) (mapcar #'length lists))) (reduce (lambda (a x) (max a x)) (mapcar #'length lists)))
(defun not-empty-string (str)
(not (zerop (length str))))