diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/interactive/sprite.lisp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/interactive/sprite.lisp b/src/interactive/sprite.lisp new file mode 100644 index 0000000..81f5715 --- /dev/null +++ b/src/interactive/sprite.lisp @@ -0,0 +1,42 @@ +;;;; sprite.lisp + +(in-package #:wheelwork) + +(defclass/std sprite (unit interactive) + ((framesets :with :doc "A PLIST whose values are framesets.") + (frameset-key))) + +(defun current-frameset (sprite) + (getf (sprite-framesets sprite) + (frameset-key sprite))) + +(defmethod initialize-instance :after ((sprite sprite) &key) + (with-slots (framesets frameset-key) sprite + (loop for (name fs . more) on framesets by #'cddr + do (setf (unit-container fs) sprite)) + (unless frameset-key + (setf frameset-key (first framesets))))) + +(defmethod cleanup ((sprite sprite)) + (mapc #'cleanup (sprite-framesets sprite))) + +(defmethod render ((sprite sprite)) + (when-let (fs (current-frameset sprite)) + (render fs))) + +(macrolet + ((def-sprite-accessors (&rest accessor-names) + (let ((defs + (loop for accessor-name in accessor-names + collect + `(defmethod ,accessor-name ((sprite sprite)) + (,accessor-name (current-frameset sprite))) + + collect + `(defmethod (setf ,accessor-name) (newval (sprite sprite)) + (loop for (key fs . more) on (sprite-framesets sprite) by #'cddr + do (setf (,accessor-name fs) newval)) + newval)))) + `(progn ,@defs)))) + + (def-sprite-accessors x y scale-x scale-y width height rotation)) |