Skip to content

Commit 80e64cf

Browse files
committed
QueryArray can now be initialized with instance
1 parent 5060420 commit 80e64cf

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

QueryArray.nut

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,32 @@ if ( !("csQuery" in getroottable()) || typeof ::csQuery != "table" )
22
throw "csQuery not found. Make sure you are not directly referencing this script, instead reference csQuery.nut";
33

44
class csQuery.QueryArray {
5-
constructor(_entArray){
6-
entArray = _entArray;
5+
constructor(_entArray) {
6+
if (typeof _entArray == "array") {
7+
entArray = _entArray;
8+
return;
9+
}
10+
11+
if (typeof _entArray == "instance") {
12+
entArray = [ _entArray ];
13+
return;
14+
}
15+
16+
throw "The parameter's data type is invalid (Valid Types: array, class instance)";
717
}
818

919
entArray = null;
1020

1121
function Each(callback) {
1222
foreach (ent in entArray) {
13-
callback.call(this, ent)
23+
callback.call(this, ent);
1424
}
1525
return this;
1626
}
1727

1828
function EachWithIndex(callback) {
1929
for (local i = 0; i < entArray.len(); i++) {
20-
callback.call(this, i, entArray[i])
30+
callback.call(this, i, entArray[i]);
2131
}
2232
return this;
2333
}
@@ -169,11 +179,11 @@ class csQuery.QueryArray {
169179
}
170180

171181
function Eq(index) {
172-
return csQuery.QueryArray([entArray[index]]);
182+
return csQuery.QueryArray(entArray[index]);
173183
}
174184

175185
function First() {
176-
return csQuery.QueryArray([entArray[0]]);
186+
return csQuery.QueryArray(entArray[0]);
177187
}
178188

179189
function Get(index) {

csQuery.nut

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function csQuery::Find(query) : (findBy, all) {
3535
return QueryArray([query]);
3636

3737
if (typeof query != "string" && typeof query != "integer")
38-
throw "The parameter's data type is invalid (Valid Types: class instance, string, char)"
38+
throw "The parameter's data type is invalid (Valid Types: class instance, string, char)";
3939

4040
local _selector = query[0];
4141
local body = query.slice(1);
@@ -48,8 +48,8 @@ function csQuery::Find(query) : (findBy, all) {
4848
case SELECTOR.ALL:
4949
return QueryArray( all() );
5050
case SELECTOR.FIRST:
51-
return QueryArray( [ Entities.Next(null) ] );
51+
return QueryArray( Entities.Next(null) );
5252
default:
53-
throw "The parameter has an invalid selector"
53+
throw "The parameter has an invalid selector";
5454
}
5555
}

0 commit comments

Comments
 (0)