ecs: query takes [#entity] list
This commit is contained in:
parent
38462bceac
commit
7767608595
|
@ -170,12 +170,16 @@ export class ECSCompiler extends Tokenizer {
|
||||||
if (tok.str == '#') {
|
if (tok.str == '#') {
|
||||||
this.consumeToken();
|
this.consumeToken();
|
||||||
let reftype = field.dtype == 'ref' ? field as RefType : undefined;
|
let reftype = field.dtype == 'ref' ? field as RefType : undefined;
|
||||||
let token = this.expectIdent();
|
return this.parseEntityForwardRef(reftype);
|
||||||
return { reftype, token };
|
|
||||||
}
|
}
|
||||||
this.compileError(`I expected a ${field.dtype} here.`); throw new Error();
|
this.compileError(`I expected a ${field.dtype} here.`); throw new Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parseEntityForwardRef(reftype?: RefType) : ForwardRef {
|
||||||
|
let token = this.expectIdent();
|
||||||
|
return { reftype, token };
|
||||||
|
}
|
||||||
|
|
||||||
parseDataArray() {
|
parseDataArray() {
|
||||||
this.expectToken('[');
|
this.expectToken('[');
|
||||||
let arr = this.parseList(this.expectInteger, ',');
|
let arr = this.parseList(this.expectInteger, ',');
|
||||||
|
@ -283,12 +287,22 @@ export class ECSCompiler extends Tokenizer {
|
||||||
if (prefix.type != TokenType.Ident) {
|
if (prefix.type != TokenType.Ident) {
|
||||||
this.consumeToken();
|
this.consumeToken();
|
||||||
}
|
}
|
||||||
let cref = this.parseComponentRef();
|
|
||||||
if (prefix.type == TokenType.Ident) {
|
if (prefix.type == TokenType.Ident) {
|
||||||
|
let cref = this.parseComponentRef();
|
||||||
q.include.push(cref);
|
q.include.push(cref);
|
||||||
} else if (prefix.str == '-') {
|
} else if (prefix.str == '-') {
|
||||||
|
let cref = this.parseComponentRef();
|
||||||
if (!q.exclude) q.exclude = [];
|
if (!q.exclude) q.exclude = [];
|
||||||
q.exclude.push(cref);
|
q.exclude.push(cref);
|
||||||
|
} else if (prefix.str == '#') {
|
||||||
|
const scope = this.currentScope;
|
||||||
|
if (scope == null) { this.internalError(); throw new Error(); }
|
||||||
|
let eref = this.parseEntityForwardRef();
|
||||||
|
this.deferred.push(() => {
|
||||||
|
let refvalue = this.resolveEntityRef(scope, eref);
|
||||||
|
if (!q.entities) q.entities = [];
|
||||||
|
q.entities.push(scope.entities[refvalue]);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.compileError(`Query components may be preceded only by a '-'.`);
|
this.compileError(`Query components may be preceded only by a '-'.`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ export interface ComponentType extends SourceLocated {
|
||||||
export interface Query extends SourceLocated {
|
export interface Query extends SourceLocated {
|
||||||
include: ComponentType[]; // TODO: make ComponentType
|
include: ComponentType[]; // TODO: make ComponentType
|
||||||
exclude?: ComponentType[];
|
exclude?: ComponentType[];
|
||||||
|
entities?: Entity[];
|
||||||
limit?: number;
|
limit?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -503,10 +504,18 @@ class EntitySet {
|
||||||
constructor(scope: EntityScope, query?: Query, a?: EntityArchetype[], e?: Entity[]) {
|
constructor(scope: EntityScope, query?: Query, a?: EntityArchetype[], e?: Entity[]) {
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
if (query) {
|
if (query) {
|
||||||
this.atypes = scope.em.archetypesMatching(query);
|
if (query.entities) {
|
||||||
this.entities = scope.entitiesMatching(this.atypes);
|
this.entities = query.entities.slice(0);
|
||||||
if (query.limit) {
|
this.atypes = [];
|
||||||
this.entities = this.entities.slice(0, query.limit);
|
for (let e of this.entities)
|
||||||
|
if (!this.atypes.includes(e.etype))
|
||||||
|
this.atypes.push(e.etype);
|
||||||
|
} else {
|
||||||
|
this.atypes = scope.em.archetypesMatching(query);
|
||||||
|
this.entities = scope.entitiesMatching(this.atypes);
|
||||||
|
if (query.limit) {
|
||||||
|
this.entities = this.entities.slice(0, query.limit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (a && e) {
|
} else if (a && e) {
|
||||||
this.atypes = a;
|
this.atypes = a;
|
||||||
|
@ -751,8 +760,10 @@ class ActionEval {
|
||||||
throw new ECSError('unroll is not yet implemented');
|
throw new ECSError('unroll is not yet implemented');
|
||||||
}
|
}
|
||||||
// define properties
|
// define properties
|
||||||
props['%elo'] = entities[0].id.toString();
|
if (entities.length) {
|
||||||
props['%ehi'] = entities[entities.length - 1].id.toString();
|
props['%elo'] = entities[0].id.toString();
|
||||||
|
props['%ehi'] = entities[entities.length - 1].id.toString();
|
||||||
|
}
|
||||||
props['%ecount'] = entities.length.toString();
|
props['%ecount'] = entities.length.toString();
|
||||||
props['%efullcount'] = fullEntityCount.toString();
|
props['%efullcount'] = fullEntityCount.toString();
|
||||||
// TODO
|
// TODO
|
||||||
|
|
Loading…
Reference in New Issue