| 1 | import ecs |
| 2 | |
| 3 | struct Entity { |
| 4 | components []Component |
| 5 | } |
| 6 | |
| 7 | interface Component {} |
| 8 | |
| 9 | fn two_components_filter_query[A, B](entity Entity) bool { |
| 10 | return check_if_entity_has_component[A](entity) && check_if_entity_has_component[B](entity) |
| 11 | } |
| 12 | |
| 13 | pub fn check_if_entity_has_component[T](entity Entity) bool { |
| 14 | get_entity_component[T](entity) or { return false } |
| 15 | |
| 16 | return true |
| 17 | } |
| 18 | |
| 19 | pub fn get_entity_component[T](entity Entity) !&T { |
| 20 | for component in entity.components { |
| 21 | if component is T { |
| 22 | return component |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | return error('Entity with does not have a component of type ${T.name}') |
| 27 | } |
| 28 | |
| 29 | fn component_interface_hack() []Component { |
| 30 | return [ecs.Position{}, ecs.Velocity{}] |
| 31 | } |
| 32 | |
| 33 | fn test_generic_fn_variable() { |
| 34 | query := two_components_filter_query[ecs.Position, ecs.Velocity] |
| 35 | assert true |
| 36 | } |
| 37 | |