commit 52e51784cda090a39c1d9fede5ab970828a943f4
Author: spesk <spw01@protonmail.com>
Date: Mon Feb 13 22:08:16 2023 -0500
Added generic slot iterator
This was very confusing for me to figure out as a CL newb. This long
commit message will describe my brief learnings.
Generics (defgeneric (obj)) implements an interface to implement
methods for various classes. The associates is denoted by the
(defmethod ((object type-of-object))) syntax. See commit for an
example. Leaving this as a breadcrumb in case I forget how this
works.
diff --git a/ship.lisp b/ship.lisp
index 0e0994f..8701cc8 100644
--- a/ship.lisp
+++ b/ship.lisp
@@ -1,11 +1,10 @@
;;; SHIP INFO ;;;
-(defun display-crew ()
- (let* ((crew (crew-crew-members (player-ship-crew *player-ship*)))
- (crew-names
- (loop for member in crew-struct
- collect (list (uniq-crew-mem-name member) NIL NIL))))
+(defun display-crew (player-ship-obj)
+ (let ((crew-names
+ (loop for member in (crew-members (crew player-ship-obj))
+ collect (list (name member)))))
(format T "~%CREW DETAILS~%~%")
- (format-table T (list (list (crew-sanity-val (player-ship-crew *player-ship*)))) :column-label '("Sanity"))
+ (format-table T (list (list (sanity-val (crew player-ship-obj)))) :column-label '("Sanity"))
(format T "~%")
(format-table T crew-names :column-label '("Name" "Buff" "Buff Amount"))))
diff --git a/structs.lisp b/structs.lisp
index 3f22eb1..48a602f 100644
--- a/structs.lisp
+++ b/structs.lisp
@@ -68,6 +68,11 @@
:initarg :crew-members ; List of *uniq-crew-mem*
:accessor crew-members)))
+;; "Given an object, return the names of it's slots"
+(defgeneric return-slots (obj))
+(defmethod return-slots ((market market))
+ (map 'list #'closer-mop:slot-definition-name (closer-mop:class-slots (class-of market))))
+
;;; Unique crew member that can provide an abstract buff
;;; or nerf to some internal game system
(defclass uniq-crew-mem ()