MCPcopy Create free account
hub / github.com/esengine/esengine / first

Method first

packages/core/src/ECS/Core/Query/CompiledQuery.ts:235–253  ·  view source on GitHub ↗

* 获取第一个匹配的实体及其组件 * * Get first matching entity with its components. * * @returns 实体和组件元组,或 null | Entity and components tuple, or null

()

Source from the content-addressed store, hash-verified

233 * @returns 实体和组件元组,或 null | Entity and components tuple, or null
234 */
235 public first(): [Entity, ...InstanceTypes<T>] | null {
236 const entities = this.entities;
237 if (entities.length === 0) {
238 return null;
239 }
240
241 const entity = entities[0]!;
242 const components: Component[] = [];
243
244 for (const type of this._componentTypes) {
245 const component = entity.getComponent(type);
246 if (!component) {
247 return null;
248 }
249 components.push(component);
250 }
251
252 return [entity, ...(components as InstanceTypes<T>)];
253 }
254
255 /**
256 * 转换为数组

Callers 2

get_local_ipFunction · 0.45

Calls 2

pushMethod · 0.65
getComponentMethod · 0.45

Tested by

no test coverage detected