Skip to content

Commit c391582

Browse files
Spencer BrowerNoofbiz
Spencer Brower
authored andcommitted
fix(World): Fixed an issue causing ex filters to fail.
1 parent ecd1139 commit c391582

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

world.go

+16-14
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (w *World) AddSystemInterface(sys SystemAddByInterfacer, in interface{}, ex
3333
w.sysIn = make(map[reflect.Type][]reflect.Type)
3434
}
3535

36-
if reflect.TypeOf(in) != reflect.TypeOf([]interface{}{}) {
36+
if reflect.TypeOf(in).AssignableTo(reflect.TypeOf([]interface{}{})) {
3737
in = []interface{}{in}
3838
}
3939
for _, v := range in.([]interface{}) {
@@ -48,13 +48,12 @@ func (w *World) AddSystemInterface(sys SystemAddByInterfacer, in interface{}, ex
4848
w.sysEx = make(map[reflect.Type][]reflect.Type)
4949
}
5050

51-
if reflect.TypeOf(ex) != reflect.TypeOf([]interface{}{}) {
51+
if !reflect.TypeOf(ex).AssignableTo(reflect.TypeOf([]interface{}{})) {
5252
ex = []interface{}{ex}
5353
}
5454
for _, v := range ex.([]interface{}) {
5555
w.sysEx[reflect.TypeOf(sys)] = append(w.sysEx[reflect.TypeOf(sys)], reflect.TypeOf(v).Elem())
5656
}
57-
// w.sysEx[reflect.TypeOf(sys)] = reflect.TypeOf(ex).Elem()
5857
}
5958

6059
// AddEntity adds the entity to all systems that have been added via
@@ -67,27 +66,30 @@ func (w *World) AddEntity(e Identifier) {
6766
if w.sysEx == nil {
6867
w.sysEx = make(map[reflect.Type][]reflect.Type)
6968
}
69+
70+
search := func(i Identifier, types []reflect.Type) bool {
71+
for _, t := range types {
72+
if reflect.TypeOf(i).Implements(t) {
73+
return true
74+
}
75+
}
76+
return false
77+
}
7078
for _, system := range w.systems {
7179
sys, ok := system.(SystemAddByInterfacer)
7280
if !ok {
7381
continue
7482
}
7583

7684
if ex, not := w.sysEx[reflect.TypeOf(sys)]; not {
77-
for _, t := range ex {
78-
if reflect.TypeOf(e).Implements(t) {
79-
// TODO: Issue
80-
continue
81-
}
85+
if search(e, ex) {
86+
continue
8287
}
8388
}
8489
if in, ok := w.sysIn[reflect.TypeOf(sys)]; ok {
85-
for _, t := range in {
86-
if reflect.TypeOf(e).Implements(t) {
87-
sys.AddByInterface(e)
88-
// TODO: Issue
89-
continue
90-
}
90+
if search(e, in) {
91+
sys.AddByInterface(e)
92+
continue
9193
}
9294
}
9395
}

0 commit comments

Comments
 (0)