summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoutade <thegoofist@protonmail.com>2019-10-03 06:56:37 -0500
committerBoutade <thegoofist@protonmail.com>2019-10-03 06:56:37 -0500
commitfb97b3772fe6765e1f36c19aecb389830a5ab075 (patch)
tree7db8274daad03f5aa7f06d71fe5b35d03c817311
parente47ca258c26ae7da5be15ad3b8f2c978db80ae9f (diff)
explicit setter and getter
-rw-r--r--animise.lisp16
1 files changed, 12 insertions, 4 deletions
diff --git a/animise.lisp b/animise.lisp
index 7ea2731..590f622 100644
--- a/animise.lisp
+++ b/animise.lisp
@@ -33,7 +33,7 @@
((start-time
:accessor start-time
:initarg :start-time
- :initform (error "Must supply a start time."))
+ :initform 0)
(duration
:reader get-duration
:initarg :duration
@@ -53,10 +53,18 @@
(rounding
:initarg rounding
:initform t )
+ (getter)
+ (setter)
(accessor
:initarg :accessor
:initform (error "Must supply an accessor function"))))
+(defmethod initialize-instance :after ((tween tween) &key)
+ (with-slots (getter setter accessor) tween
+ (setf getter (eval `(function ,accessor)))
+ (setf setter (eval `(function (setf ,accessor))))))
+
+
;;; TWEEN-SEQ combines tweens to run one after another.
(defclass tween-seq ()
@@ -116,10 +124,10 @@
(get-duration tween))
(defmethod run-tween ((tween tween) time)
- (with-slots (start-time duration rounding ease-fn start-val target end-val accessor) tween
+ (with-slots (start-time duration rounding ease-fn start-val target end-val getter setter) tween
(when (>= time start-time)
(when (null start-val)
- (setf start-val (funcall accessor target)))
+ (setf start-val (funcall getter target)))
(let ((new-val
(+ start-val
(funcall ease-fn
@@ -127,7 +135,7 @@
duration
time
(- end-val start-val)))))
- (funcall (eval `(function (setf ,accessor)))
+ (funcall setter
(if rounding (round new-val) new-val)
target)))))