forked from Shirakumo/trial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer-set.lisp
62 lines (48 loc) · 2.09 KB
/
layer-set.lisp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#|
This file is a part of trial
(c) 2016 Shirakumo http://tymoon.eu ([email protected])
Author: Nicolas Hafner <[email protected]>
|#
(in-package #:org.shirakumo.fraf.trial)
(defclass layer-container (container)
((layer :initarg :layer :accessor layer)
(active :initarg :active :accessor active))
(:default-initargs
:layer 0
:active T))
(defmethod paint :around ((layer layer-container) target)
(when (active layer)
(call-next-method)))
;; FIXME: should be a container-unit, but things get recursive in the HUD
;; if that is the case. BAD!
(defclass layer-set (container unit)
((objects :initform (make-array 0 :adjustable T :fill-pointer T))
(index-map :initform (make-hash-table :test 'eql) :accessor index-map)))
(defmethod unit (index (layer-set layer-set))
(or (gethash index (index-map layer-set))
(enter (make-instance 'layer-container :layer index) layer-set)))
(defmethod enter ((layer layer-container) (layer-set layer-set))
(when (gethash (layer layer) (index-map layer-set))
(cerror "A layer with index ~a already exists in ~a."
(layer layer) layer-set))
(vector-push-extend layer (objects layer-set))
(setf (objects layer-set) (sort (objects layer-set) #'< :key #'layer))
(setf (gethash (layer layer) (index-map layer-set)) layer))
(defmethod enter ((unit unit) (layer-set layer-set))
(enter unit (unit 0 layer-set)))
(defmethod leave ((unit unit) (layer-set layer-set))
(leave unit (unit 0 layer-set)))
(defmethod paint ((layer-set layer-set) target)
(for:for ((layer across (objects layer-set)))
(paint layer target)))
(defmethod layer-active-p (n (layer-set layer-set))
(active (unit n layer-set)))
(defmethod (setf layer-active-p) (bool n (layer-set layer-set))
(setf (active (unit n layer-set)) bool))
(defclass layered-unit (unit)
((layer :initarg :layer :accessor layer))
(:default-initargs :layer 0))
(defmethod enter ((unit layered-unit) (layer-set layer-set))
(enter unit (unit (layer unit) layer-set)))
(defmethod leave ((unit layered-unit) (layer-set layer-set))
(leave unit (unit (layer unit) layer-set)))