~lthms/fairy.lisp

4e890364c84fb4366175d9bf457997fc8d63e019 — Thomas Letan 6 years ago 26257af
feature: Retrieve a child from a layer with its key
2 files changed, 9 insertions(+), 1 deletions(-)

M example.lisp
M fairy.lisp
M example.lisp => example.lisp +2 -1
@@ 31,7 31,8 @@
(setf (fairy:width *rec*) 200)

(sleep 0.5)
(setf (fairy:origin *rec*) (gamekit:vec2 230 20))
(setf (fairy:origin (fairy:get-child *root* :rectangle))
      (gamekit:vec2 230 20))

(sleep 0.5)
(setf (fairy:visible *rec*) nil)

M fairy.lisp => fairy.lisp +7 -0
@@ 11,6 11,7 @@
           layer
           boundary
           add-child
           get-child
           delete-child
           delete-child-with-key))



@@ 77,6 78,12 @@
(defmethod add-child ((el layer) child &key with-key)
  (setf (children el) (cons (cons with-key child) (children el))))

(defmethod get-child ((el layer) key)
  (cdr (assoc key (children el))))

(defmethod (setf get-child) (value (el layer) key)
  (setf (cdr (assoc key (children el))) value))

(defmethod delete-child ((el layer) child)
  (setf (children el) (remove child (children el) :key #'cdr)))