@@ -33,7 +33,7 @@ func (w *World) AddSystemInterface(sys SystemAddByInterfacer, in interface{}, ex
33
33
w .sysIn = make (map [reflect.Type ][]reflect.Type )
34
34
}
35
35
36
- if reflect .TypeOf (in ) != reflect .TypeOf ([]interface {}{}) {
36
+ if reflect .TypeOf (in ). AssignableTo ( reflect .TypeOf ([]interface {}{}) ) {
37
37
in = []interface {}{in }
38
38
}
39
39
for _ , v := range in .([]interface {}) {
@@ -48,13 +48,12 @@ func (w *World) AddSystemInterface(sys SystemAddByInterfacer, in interface{}, ex
48
48
w .sysEx = make (map [reflect.Type ][]reflect.Type )
49
49
}
50
50
51
- if reflect .TypeOf (ex ) != reflect .TypeOf ([]interface {}{}) {
51
+ if ! reflect .TypeOf (ex ). AssignableTo ( reflect .TypeOf ([]interface {}{}) ) {
52
52
ex = []interface {}{ex }
53
53
}
54
54
for _ , v := range ex .([]interface {}) {
55
55
w .sysEx [reflect .TypeOf (sys )] = append (w .sysEx [reflect .TypeOf (sys )], reflect .TypeOf (v ).Elem ())
56
56
}
57
- // w.sysEx[reflect.TypeOf(sys)] = reflect.TypeOf(ex).Elem()
58
57
}
59
58
60
59
// AddEntity adds the entity to all systems that have been added via
@@ -67,27 +66,30 @@ func (w *World) AddEntity(e Identifier) {
67
66
if w .sysEx == nil {
68
67
w .sysEx = make (map [reflect.Type ][]reflect.Type )
69
68
}
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
+ }
70
78
for _ , system := range w .systems {
71
79
sys , ok := system .(SystemAddByInterfacer )
72
80
if ! ok {
73
81
continue
74
82
}
75
83
76
84
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
82
87
}
83
88
}
84
89
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
91
93
}
92
94
}
93
95
}
0 commit comments