aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core-units/container.lisp
blob: afa68b35061285d47796e9dc38d0c833b0f38f89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
;;;; units/container.lisp

(in-package #:wheelwork)


(defclass/std container ()
  ((units :with :a))
  (:documentation "Just a list of units. Made into a class so that
  transformation affine transformations methods can be specialzied on
  whole groups of units"))

(defmethod drop-unit ((unit unit))
  "Removes a unit from its container. Returns T if the unit actually was removed."
  (when-let (container (unit-container unit))
    (setf
     (container-units container) (delete unit (container-units container))
     (unit-container unit) nil)
    t))

(defmethod add-unit ((container container) (unit unit))
  "Adds a unit to the end of a container (thus affecting render
order). Makes sure to remove the unit from its current container if
necessary."
  (when (unit-container unit)
    (drop-unit unit))
  (push unit  (container-units container))
  (setf (unit-container unit) container)
  unit)

(defmethod cleanup ((container container))
  (dolist (u (container-units container))
    (cleanup u)))