mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-12 15:30:15 +00:00
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 == '#') {
|
||||
this.consumeToken();
|
||||
let reftype = field.dtype == 'ref' ? field as RefType : undefined;
|
||||
let token = this.expectIdent();
|
||||
return { reftype, token };
|
||||
return this.parseEntityForwardRef(reftype);
|
||||
}
|
||||
this.compileError(`I expected a ${field.dtype} here.`); throw new Error();
|
||||
}
|
||||
|
||||
parseEntityForwardRef(reftype?: RefType) : ForwardRef {
|
||||
let token = this.expectIdent();
|
||||
return { reftype, token };
|
||||
}
|
||||
|
||||
parseDataArray() {
|
||||
this.expectToken('[');
|
||||
let arr = this.parseList(this.expectInteger, ',');
|
||||
@ -283,12 +287,22 @@ export class ECSCompiler extends Tokenizer {
|
||||
if (prefix.type != TokenType.Ident) {
|
||||
this.consumeToken();
|
||||
}
|
||||
let cref = this.parseComponentRef();
|
||||
if (prefix.type == TokenType.Ident) {
|
||||
let cref = this.parseComponentRef();
|
||||
q.include.push(cref);
|
||||
} else if (prefix.str == '-') {
|
||||
let cref = this.parseComponentRef();
|
||||
if (!q.exclude) q.exclude = [];
|
||||
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 {
|
||||
this.compileError(`Query components may be preceded only by a '-'.`);
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ export interface ComponentType extends SourceLocated {
|
||||
export interface Query extends SourceLocated {
|
||||
include: ComponentType[]; // TODO: make ComponentType
|
||||
exclude?: ComponentType[];
|
||||
entities?: Entity[];
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
@ -503,10 +504,18 @@ class EntitySet {
|
||||
constructor(scope: EntityScope, query?: Query, a?: EntityArchetype[], e?: Entity[]) {
|
||||
this.scope = scope;
|
||||
if (query) {
|
||||
this.atypes = scope.em.archetypesMatching(query);
|
||||
this.entities = scope.entitiesMatching(this.atypes);
|
||||
if (query.limit) {
|
||||
this.entities = this.entities.slice(0, query.limit);
|
||||
if (query.entities) {
|
||||
this.entities = query.entities.slice(0);
|
||||
this.atypes = [];
|
||||
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) {
|
||||
this.atypes = a;
|
||||
@ -751,8 +760,10 @@ class ActionEval {
|
||||
throw new ECSError('unroll is not yet implemented');
|
||||
}
|
||||
// define properties
|
||||
props['%elo'] = entities[0].id.toString();
|
||||
props['%ehi'] = entities[entities.length - 1].id.toString();
|
||||
if (entities.length) {
|
||||
props['%elo'] = entities[0].id.toString();
|
||||
props['%ehi'] = entities[entities.length - 1].id.toString();
|
||||
}
|
||||
props['%ecount'] = entities.length.toString();
|
||||
props['%efullcount'] = fullEntityCount.toString();
|
||||
// TODO
|
||||
|
Loading…
x
Reference in New Issue
Block a user