wynnbuilder-forked-for-changes/query.js

113 lines
2.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) {
2021-02-05 17:35:13 +00:00
return (item.get("displayName").toLowerCase().includes(this.queryString));
2021-01-23 16:38:13 +00:00
}
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) {
2021-02-05 17:35:13 +00:00
if (item.get("remapID") === undefined) {
return (item.get("lvl") <= this.max && item.get("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-02-05 17:35:13 +00:00
return (!item.get(this.id)) || (item.get(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;
2021-02-05 17:35:13 +00:00
if (nonRolledIDs.includes(id)) {
this.compare = function(a, b) {
return b.get(id) - a.get(id);
};
this.filter = function(a) {
return a.get(this.id);
}
console.log("QUERY: ID, NONROLL");
}
2021-02-05 19:28:42 +00:00
else if (reversedIDs.includes(id)) {
2021-02-05 17:35:13 +00:00
this.compare = function(a, b) {
2021-02-05 19:28:42 +00:00
return a.get("maxRolls").get(id) - b.get("maxRolls").get(id);
2021-02-05 17:35:13 +00:00
};
this.filter = function(a) {
return a.get("maxRolls").get(this.id);
}
console.log("QUERY: ID, REVERSE");
}
else {
this.compare = function(a, b) {
return b.get("maxRolls").get(id) - a.get("maxRolls").get(id);
};
this.filter = function(a) {
return a.get("maxRolls").get(this.id);
}
console.log("QUERY: ID, ,,,");
}
2021-01-24 03:58:53 +00:00
}
}
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) {
2021-02-05 17:35:13 +00:00
return item.get(this.id) && (item.get(this.id) == this.value);
2021-01-26 09:17:11 +00:00
}
}
class SumQuery {
constructor(ids) {
2021-02-05 17:35:13 +00:00
let getters = [];
for (const id of ids) {
if (nonRolledIDs.includes(id)) {
getters.push(a => a.get(id));
}
else {
getters.push(a => a.get("maxRolls").get(id));
}
}
2021-01-26 09:17:11 +00:00
this.compare = function(a, b) {
let balance = 0;
2021-02-05 17:35:13 +00:00
for (const getter of getters) {
if (getter(a)) { balance -= getter(a); }
if (getter(b)) { balance += getter(b); }
2021-01-26 09:17:11 +00:00
}
return balance;
};
}
filter(item) {
return true;
}
}