-
Notifications
You must be signed in to change notification settings - Fork 2
/
parent.go
40 lines (35 loc) · 871 Bytes
/
parent.go
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
package ecs
// ParentSystem manages Parent Components.
type ParentSystem struct {
mgr *World
}
// NewParentSystem constructs a new ParentSystem.
func NewParentSystem(mgr *World) *ParentSystem {
return &ParentSystem{
mgr: mgr,
}
}
// Update the ParentSystem.
func (s *ParentSystem) Update() {
// Remove references to Children that have been destroyed from the Parents
// that claim them.
for _, e := range s.mgr.Get([]string{"Children"}) {
c := s.mgr.Component(e, "Children").(*Children)
val := []Entity{}
for _, child := range c.Value {
if !s.mgr.Exists(child) {
continue
}
val = append(val, child)
}
c.Value = val
}
}
// Children allows hierarchical relationships between entities. Some Entities have Children.
type Children struct {
Value []Entity
}
// Type of this Component.
func (*Children) Type() string {
return "Children"
}