val entities = Query.where { has(Transform.id) }.eval()
val entities = Query.where { has(Transform.id, Mesh.id) }.eval()
val entities = Query.where { changed(Transform.id) }.eval()
val entities = Query.where { (has(Transform.id) and has(Mesh.id)) or has(Panel.id) }.eval()
val entities = Query.where { has(TestComponent.id) }
.filter { by(TestComponent.intVarData).isEqualTo(1) }
.eval()
val entities = Query.where { has(TestComponent.id) }
.sort {
with {
by(TestComponent.intVarData)
}
}.eval()
class Query
prev_
: Query?
[Get][Set] |
Signature
var prev_: Query? |
query_
: IntArray
[Get][Set] |
Signature
var query_: IntArray |
build
()
|
Evaluates the query for a specific DataModel and returns the a built query.
Signature
fun build(): BuiltQuery Returns
BuiltQuery
|
eval
()
|
Evaluates the query and returns a sequence of entities that match the query criteria.
This method executes the query against the current DataModel and returns matching entities. The result is a lazy sequence, so operations on it are only performed as needed.
Example:
// Find all entities with a Transform component and iterate through them
Query.where { has(Transform.id) }
.eval()
.forEach { entity ->
// Process each entity val
transform = entity.getComponent<Transform>()
// ...
}
Signature
fun eval(): Sequence<Entity> Returns
Sequence<Entity>
|
eval
(
dm
)
|
Evaluates the query against a specific DataModel and returns matching entities.
In a Spatial app, there is only one DataModel, so this method is rarely used. Use eval() instead to evaluate the query against the current DataModel.
Example:
// Evaluate a query against a specific DataModel
val customDataModel = DataModel.create()
val entities = Query.where { has(Transform.id) }.eval(customDataModel)
Signature
fun eval(dm: DataModel): Sequence<Entity> Parameters Returns
Sequence<Entity>
|
filter
(
initializer
)
|
Specifies the filter criteria for the query.
Example:
// Find all entities with a TestComponent component and filter by the intVarData field
val entities = Query.where { has(TestComponent.id) }
.filter { by(TestComponent.intVarData).isEqualTo(1) }
.eval()
Signature
fun filter(initializer: FilterBuilder.() -> Unit): Query Parameters
initializer:
Function1
|
sort
(
initializer
)
|
Specifies the sort order for the query.
Example:
// Find all entities with a TestComponent component and sort by the intVarData field
val entities = Query.where { has(TestComponent.id) }
.sort {
with {
by(TestComponent.intVarData)
}
}
.eval()
Signature
fun sort(initializer: SortBuilder.() -> Unit): Query Parameters
initializer:
Function1
|
eval
(
preBuiltQuery
)
|
Evaluates a pre-built query and returns a sequence of entities that match the query.
Signature
fun eval(preBuiltQuery: BuiltQuery): Sequence<Entity> Parameters
preBuiltQuery:
BuiltQuery
Returns
Sequence<Entity>
|
eval
(
dm
, preBuiltQuery
)
|
Evaluates a pre-built query on a specific DataModel and returns a sequence of entities that match the query.
Signature
fun eval(dm: DataModel, preBuiltQuery: BuiltQuery): Sequence<Entity> Parameters
preBuiltQuery:
BuiltQuery
Returns
Sequence<Entity>
|
where
(
initializer
)
|
DSL for building queries. The DSL provides an interface for building complex queries with logical operations.
Example:
// Find entities that have both Transform and Mesh components
val query = Query.where { has(Transform.id) and has(Mesh.id) }
// Find entities that have either changed Transform or changed Mesh components
val query = Query.where { changed(Transform.id) or changed(Mesh.id) }
// Find entities that have a Controller component and are local
val query = Query.where { has(Controller.id) } .filter { isLocal() } .eval()
// Find entities with a specific component that have changed in the last tick
val query = Query.where { has(Grabbable.id) and changed(Transform.id) }
Signature
fun where(initializer: QueryBuilder.() -> Unit): Query Parameters
initializer:
Function1
|