start making file source configurable

This commit is contained in:
2026-01-05 14:11:56 -05:00
parent 6a2ab4b673
commit 59d50a694b
4 changed files with 40 additions and 13 deletions

View File

@@ -32,6 +32,6 @@
:if-does-not-exist :create))) :if-does-not-exist :create)))
(comment (comment
(defvar drops (make-drop-data-source)) (defvar drops (make-drop-data-source "foo"))
(refresh drops) (refresh drops)
(reload drops)) (reload drops))

View File

@@ -4,19 +4,37 @@
(defparameter *chronostory-gacha-search-format* "https://chronostory.onrender.com/api/gacha-search?itemId=~a") (defparameter *chronostory-gacha-search-format* "https://chronostory.onrender.com/api/gacha-search?itemId=~a")
(defparameter *chronostory-gacha-url-format "https://chronostory.onrender.com/api/gacha-items?gachaId=~a") (defparameter *chronostory-gacha-url-format "https://chronostory.onrender.com/api/gacha-items?gachaId=~a")
(defun main () (defun print-version-information ()
(sb-ext:disable-debugger) (let* ((program-name (car sb-ext:*posix-argv*))
(let ((program-name (car sb-ext:*posix-argv*)) (write-time (file-write-date program-name)))
(args (rest sb-ext:*posix-argv*)))
(when (member "--fail" args :test #'string=)
(error "Simulated error!"))
(when (member "--version" args :test #'string=)
(let ((write-time (file-write-date program-name)))
(multiple-value-bind (second minute hour date month year) (multiple-value-bind (second minute hour date month year)
(decode-universal-time write-time) (decode-universal-time write-time)
(let ((dt (format nil "~4,'0d-~2,'0d-~2,'0d ~2,'0d:~2,'0d:~2,'0d" (let ((dt (format nil "~4,'0d-~2,'0d-~2,'0d ~2,'0d:~2,'0d:~2,'0d"
year month date hour minute second))) year month date hour minute second)))
(format t "lispostory, created ~a~%" dt))))))) (format t "lispostory, created ~a~%" dt)))))
(defun get-arg (opt args)
"Get's the argument for a given command line option. Expects <program opt arg>"
(loop :for (current next) :on args
:while next
:when (string-equal current opt)
:return next))
(defun refresh-data (data-type)
(string-case data-type
("drops" (refresh (make-drop-data-source)))
("items" (refresh (make-item-data-source)))
("mobs" (refresh (make-mob-data-source)))
("spawns" (refresh (make-spawn-data-source)))))
(defun main ()
(sb-ext:disable-debugger)
(let ((args (rest sb-ext:*posix-argv*)))
(when (find-string "--fail" args)
(error "Simulated error!"))
(when (find-string "--version" args)
(print-version-information))
(when-let ((arg (get-arg "refresh"))))))
(defun create-exe-and-die () (defun create-exe-and-die ()
(sb-ext:save-lisp-and-die (sb-ext:save-lisp-and-die

View File

@@ -41,5 +41,5 @@
(uiop:println "Done!"))) (uiop:println "Done!")))
(comment (comment
(defvar mobs (make-mob-data-source)) (defvar mobs (make-mob-data-source nil))
(reload mobs)) (reload mobs))

View File

@@ -27,10 +27,19 @@
(defun string->bool (s) (defun string->bool (s)
(if (string-equal (string-downcase s) "true") t nil)) (if (string-equal (string-downcase s) "true") t nil))
(defun find-string (str seq)
(sequence:find str seq :test #'string-equal))
(defclass data-source () (defclass data-source ()
((cache :initform nil :accessor cache) ((cache :initform nil :accessor cache)
(file-path :initarg :file-path :accessor file-path))) (file-path :initarg :file-path :accessor file-path)))
(defun maybe-pass (func arg)
"Pass ARG to FUNC if arg is not nil."
(if (fnil)arg
(funcall func arg)
(funcall func)))
(defmacro define-data-source (singular-name) (defmacro define-data-source (singular-name)
(let* ((class-name (symbolicate singular-name '-data-source)) (let* ((class-name (symbolicate singular-name '-data-source))
(constructor-name (symbolicate 'make- singular-name '-data-source)) (constructor-name (symbolicate 'make- singular-name '-data-source))
@@ -39,8 +48,8 @@
`(progn `(progn
(defclass ,class-name (data-source) ()) (defclass ,class-name (data-source) ())
(defun ,constructor-name () (defun ,constructor-name (&optional (file-path ,file-name))
(make-instance ',class-name :file-path ,file-name))))) (make-instance ',class-name :file-path file-path)))))
(defgeneric data (data-source)) (defgeneric data (data-source))
(defmethod data ((ds data-source)) (defmethod data ((ds data-source))