Forráskód Böngészése

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.
spesk 1 éve
szülő
commit
52e51784cd
2 módosított fájl, 10 hozzáadás és 6 törlés
  1. 5 6
      ship.lisp
  2. 5 0
      structs.lisp

+ 5 - 6
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"))))
 

+ 5 - 0
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 ()