AddSystemInterface adds a system to the world, but also adds a filter that allows automatic adding of entities that match the provided in interface, and excludes any that match the provided ex interface, even if they also match in. in and ex must be pointers to the interface or else this panics.
(sys SystemAddByInterfacer, in interface{}, ex interface{})
| 27 | // that match the provided ex interface, even if they also match in. in and ex must be |
| 28 | // pointers to the interface or else this panics. |
| 29 | func (w *World) AddSystemInterface(sys SystemAddByInterfacer, in interface{}, ex interface{}) { |
| 30 | w.AddSystem(sys) |
| 31 | |
| 32 | if w.sysIn == nil { |
| 33 | w.sysIn = make(map[reflect.Type][]reflect.Type) |
| 34 | } |
| 35 | |
| 36 | if !reflect.TypeOf(in).AssignableTo(reflect.TypeOf([]interface{}{})) { |
| 37 | in = []interface{}{in} |
| 38 | } |
| 39 | for _, v := range in.([]interface{}) { |
| 40 | w.sysIn[reflect.TypeOf(sys)] = append(w.sysIn[reflect.TypeOf(sys)], reflect.TypeOf(v).Elem()) |
| 41 | } |
| 42 | |
| 43 | if ex == nil { |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | if w.sysEx == nil { |
| 48 | w.sysEx = make(map[reflect.Type][]reflect.Type) |
| 49 | } |
| 50 | |
| 51 | if !reflect.TypeOf(ex).AssignableTo(reflect.TypeOf([]interface{}{})) { |
| 52 | ex = []interface{}{ex} |
| 53 | } |
| 54 | for _, v := range ex.([]interface{}) { |
| 55 | w.sysEx[reflect.TypeOf(sys)] = append(w.sysEx[reflect.TypeOf(sys)], reflect.TypeOf(v).Elem()) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // AddEntity adds the entity to all systems that have been added via |
| 60 | // AddSystemInterface. If the system was added via AddSystem the entity will not be |