Skip to content

ECS Framework API v2.2.13


ECS Framework API / TypedQueryBuilder

Class: TypedQueryBuilder<TAll, TAny, TNone>

Defined in: packages/core/src/ECS/Core/Query/TypedQuery.ts:161

类型安全的查询构建器

支持链式调用,自动推断查询结果的类型

Example

typescript
// 基础查询
const query = new TypedQueryBuilder()
    .withAll(Position, Velocity)
    .build();

// 复杂查询
const complexQuery = new TypedQueryBuilder()
    .withAll(Transform, Renderer)
    .withAny(BoxCollider, CircleCollider)
    .withNone(Disabled)
    .withTag(EntityTags.Enemy)
    .build();

Type Parameters

TAll

TAll extends readonly ComponentConstructor[] = []

TAny

TAny extends readonly ComponentConstructor[] = []

TNone

TNone extends readonly ComponentConstructor[] = []

Constructors

Constructor

new TypedQueryBuilder<TAll, TAny, TNone>(all?, any?, none?, tag?, name?): TypedQueryBuilder<TAll, TAny, TNone>

Defined in: packages/core/src/ECS/Core/Query/TypedQuery.ts:172

Parameters

all?

TAll

any?

TAny

none?

TNone

tag?

number

name?

string

Returns

TypedQueryBuilder<TAll, TAny, TNone>

Methods

withAll()

withAll<TNewAll>(...types): TypedQueryBuilder<readonly [TAll, TNewAll], TAny, TNone>

Defined in: packages/core/src/ECS/Core/Query/TypedQuery.ts:196

要求实体拥有所有指定的组件

Type Parameters

TNewAll

TNewAll extends readonly ComponentConstructor[]

Parameters

types

...TNewAll

组件类型

Returns

TypedQueryBuilder<readonly [TAll, TNewAll], TAny, TNone>

新的查询构建器,类型参数更新


withAny()

withAny<TNewAny>(...types): TypedQueryBuilder<TAll, readonly [TAny, TNewAny], TNone>

Defined in: packages/core/src/ECS/Core/Query/TypedQuery.ts:218

要求实体至少拥有一个指定的组件

Type Parameters

TNewAny

TNewAny extends readonly ComponentConstructor[]

Parameters

types

...TNewAny

组件类型

Returns

TypedQueryBuilder<TAll, readonly [TAny, TNewAny], TNone>

新的查询构建器


withNone()

withNone<TNewNone>(...types): TypedQueryBuilder<TAll, TAny, readonly [TNone, TNewNone]>

Defined in: packages/core/src/ECS/Core/Query/TypedQuery.ts:240

排除拥有指定组件的实体

Type Parameters

TNewNone

TNewNone extends readonly ComponentConstructor[]

Parameters

types

...TNewNone

组件类型

Returns

TypedQueryBuilder<TAll, TAny, readonly [TNone, TNewNone]>

新的查询构建器


withTag()

withTag(tag): TypedQueryBuilder<TAll, TAny, TNone>

Defined in: packages/core/src/ECS/Core/Query/TypedQuery.ts:262

按标签过滤实体

Parameters

tag

number

标签值

Returns

TypedQueryBuilder<TAll, TAny, TNone>

新的查询构建器


withName()

withName(name): TypedQueryBuilder<TAll, TAny, TNone>

Defined in: packages/core/src/ECS/Core/Query/TypedQuery.ts:278

按名称过滤实体

Parameters

name

string

实体名称

Returns

TypedQueryBuilder<TAll, TAny, TNone>

新的查询构建器


buildMatcher()

buildMatcher(): Matcher

Defined in: packages/core/src/ECS/Core/Query/TypedQuery.ts:293

构建Matcher对象

Returns

Matcher

Matcher实例,用于传统查询API


getCondition()

getCondition(): QueryCondition

Defined in: packages/core/src/ECS/Core/Query/TypedQuery.ts:324

获取查询条件

Returns

QueryCondition

查询条件对象


getRequiredTypes()

getRequiredTypes(): TAll

Defined in: packages/core/src/ECS/Core/Query/TypedQuery.ts:337

获取required组件类型(用于类型推断)

Returns

TAll


clone()

clone(): TypedQueryBuilder<TAll, TAny, TNone>

Defined in: packages/core/src/ECS/Core/Query/TypedQuery.ts:344

克隆查询构建器

Returns

TypedQueryBuilder<TAll, TAny, TNone>

Released under the MIT License.