summaryrefslogtreecommitdiff
path: root/serialization.lisp
diff options
context:
space:
mode:
authorGrant Shoshin Shangreaux <shoshin@cicadas.surf>2022-12-28 14:02:25 -0600
committerGrant Shoshin Shangreaux <shoshin@cicadas.surf>2022-12-28 14:02:25 -0600
commit72bcf7e66269af588d9daa9064de23d257cbd053 (patch)
treed0da6e22ddf93d2546fa415a44594f7be0f5b379 /serialization.lisp
parent2c75a754fdddb3e46e5eed95abacbcfc70334fe7 (diff)
Add: serialization for Heroes and dnd.api package
Diffstat (limited to 'serialization.lisp')
-rw-r--r--serialization.lisp25
1 files changed, 16 insertions, 9 deletions
diff --git a/serialization.lisp b/serialization.lisp
index 6579b92..d1689c1 100644
--- a/serialization.lisp
+++ b/serialization.lisp
@@ -1,13 +1,20 @@
;;;; serialization.lisp
+(in-package :dnd.api)
+(defmacro with-json-object (&body pairs)
+ (list*
+ 'json:with-object
+ (loop for (key val . more) on pairs by #'cddr
+ collect `(json:write-key-value ,key ,val))))
-(in-package :dnd)
-
-(defun hall-of-fame-hero-view (hero)
- (json:to-json
- (list :name (hero-name hero)
- :uid (uid hero)
- :renown (renown hero)
- :title (hero-title hero)
- :class (hero-class hero))))
+(defmethod json:%to-json ((hero hero))
+ (with-slots (name experience chronicle uid equipment-table) hero
+ (with-json-object
+ :|name| name
+ :|experience| experience
+ :|chronicle| chronicle
+ :|uid| uid
+ :|renown| (renown hero)
+ :|title| (hero-title hero)
+ :|class| (hero-class hero))))