src/core/query.js in entityjs-0.4.1 vs src/core/query.js in entityjs-0.4.2
- old
+ new
@@ -61,10 +61,11 @@
/*
Sort a query string into objects
*/
q._toObj = function(query){
+ //check if its caught
if(q.c[query]){
return q.c[query];
}
//convert to object
@@ -97,10 +98,11 @@
on:binds,
not:minus,
id:id
};
+ //catch it
q.c[query] = comp;
return comp;
}
@@ -166,11 +168,11 @@
var l = this.length, i = -1, e;
while(++i < l && (e = this[i]) != null && m.call(context || this, e, i, this) !== false);
return this;
- }
+ };
/*
The map method allows multidimensional loops.
//map through and increase y every 3 entities.
@@ -369,26 +371,36 @@
//without this filter would return a normal array.
p.filter = function(){
return re(Array.prototype.filter.apply(this, arguments));
}
+ //Removes all elements in the array that pass the truth test
+ p.reject = function(it, c){
+ for(var i=0; i<this.length; i++){
+ if(it.call(c || this, this[i], i, this)){
+ this.splice(i, 1);
+ }
+ }
+ return this;
+ };
+
/*
Finds first entity with components
re('draw').findWith('circle !red');
*/
- p.findWith = function(comps, c){
+ p.findWith = function(comps){
return this.find(function(e){
return e.has(comps);
- }, c);
+ });
}
/*
Creates a new entity and pushes it into the array.
*/
- p.e = function(comps, count){
- var e = re.e(comps, count);
+ p.e = function(comps, count, alone){
+ var e = re.e(comps, count, alone);
if(count){
//add all in query
for(var i in e){
this.push(e[i]);
}
\ No newline at end of file