wynnbuilder-idk/query.js

86 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-01-24 10:09:59 +00:00
let queryTypeMap = new Map();
2021-01-23 16:38:13 +00:00
class NameQuery {
2021-01-24 10:09:59 +00:00
constructor(string) { this.queryString = string.toLowerCase(); }
2021-01-23 16:38:13 +00:00
filter(item) {
if (item.remapID === undefined) {
2021-01-24 10:09:59 +00:00
return (item.displayName.toLowerCase().includes(this.queryString));
2021-01-23 16:38:13 +00:00
}
return false;
}
2021-01-24 10:09:59 +00:00
compare(a, b) { return a < b; }
2021-01-23 16:38:13 +00:00
}
2021-01-24 10:09:59 +00:00
queryTypeMap.set("name", function(s) { return new NameQuery(s); } );
2021-01-24 03:58:53 +00:00
2021-01-26 09:17:11 +00:00
class LevelRangeQuery {
constructor(min, max) { this.min = min; this.max = max; }
2021-01-24 03:58:53 +00:00
filter(item) {
if (item.remapID === undefined) {
2021-01-26 09:17:11 +00:00
return (item.lvl <= this.max && item.lvl >= this.min);
2021-01-24 03:58:53 +00:00
}
return false;
}
2021-01-26 09:17:11 +00:00
compare(a, b) { return a > b; }
2021-01-24 10:09:59 +00:00
}
2021-01-26 09:17:11 +00:00
class NegateQuery {
constructor(id) {
this.id = id;
this.compare = function(a, b) { return 0; };
}
2021-01-24 10:09:59 +00:00
filter(item) {
2021-01-26 09:17:11 +00:00
return (!(this.id in item)) || (item[this.id] == 0);
2021-01-24 03:58:53 +00:00
}
}
2021-01-26 09:17:11 +00:00
queryTypeMap.set("null", function(s) { return new IdQuery(s); } );
2021-01-24 03:58:53 +00:00
class IdQuery {
constructor(id) {
this.id = id;
this.compare = function(a, b) {
return b[id] - a[id];
};
}
filter(item) {
return (this.id in item) && (item[this.id]);
}
}
2021-01-24 10:09:59 +00:00
queryTypeMap.set("stat", function(s) { return new IdQuery(s); } );
2021-01-26 09:17:11 +00:00
class IdMatchQuery {
constructor(id, value) {
this.id = id;
this.value = value;
this.compare = function(a, b) {
return 0;
};
}
filter(item) {
return (this.id in item) && (item[this.id] == this.value);
}
}
class SumQuery {
constructor(ids) {
this.compare = function(a, b) {
let balance = 0;
for (const id of ids) {
if (a[id]) { balance -= a[id]; }
if (b[id]) { balance += b[id]; }
}
return balance;
};
}
filter(item) {
return true;
}
}