* 检查实体是否匹配当前系统的查询条件 * Check if an entity matches this system's query condition * * @param entity 要检查的实体 / The entity to check * @returns 是否匹配 / Whether the entity matches
(entity: Entity)
| 963 | * @returns 是否匹配 / Whether the entity matches |
| 964 | */ |
| 965 | public matchesEntity(entity: Entity): boolean { |
| 966 | if (!this._matcher) { |
| 967 | return false; |
| 968 | } |
| 969 | |
| 970 | // nothing 匹配器不匹配任何实体 |
| 971 | if (this._matcher.isNothing()) { |
| 972 | return false; |
| 973 | } |
| 974 | |
| 975 | // 空匹配器匹配所有实体 |
| 976 | if (this._matcher.isEmpty()) { |
| 977 | return true; |
| 978 | } |
| 979 | |
| 980 | const condition = this._matcher.getCondition(); |
| 981 | |
| 982 | // 检查 all 条件 |
| 983 | for (const componentType of condition.all) { |
| 984 | if (!entity.hasComponent(componentType)) { |
| 985 | return false; |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | // 检查 any 条件 |
| 990 | if (condition.any.length > 0) { |
| 991 | let hasAny = false; |
| 992 | for (const componentType of condition.any) { |
| 993 | if (entity.hasComponent(componentType)) { |
| 994 | hasAny = true; |
| 995 | break; |
| 996 | } |
| 997 | } |
| 998 | if (!hasAny) { |
| 999 | return false; |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | // 检查 none 条件 |
| 1004 | for (const componentType of condition.none) { |
| 1005 | if (entity.hasComponent(componentType)) { |
| 1006 | return false; |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | // 检查 tag 条件 |
| 1011 | if (condition.tag !== undefined && entity.tag !== condition.tag) { |
| 1012 | return false; |
| 1013 | } |
| 1014 | |
| 1015 | // 检查 name 条件 |
| 1016 | if (condition.name !== undefined && entity.name !== condition.name) { |
| 1017 | return false; |
| 1018 | } |
| 1019 | |
| 1020 | // 检查单组件条件 |
| 1021 | if (condition.component !== undefined && !entity.hasComponent(condition.component)) { |
| 1022 | return false; |
nothing calls this directly
no test coverage detected