wynnbuilder-idk/query.js

58 lines
1.3 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
class TypeQuery {
2021-01-24 10:09:59 +00:00
constructor(type) { this.type = type; }
2021-01-24 03:58:53 +00:00
filter(item) {
if (item.remapID === undefined) {
return (item.type === this.type);
}
return false;
}
2021-01-24 10:09:59 +00:00
compare(a, b) { return a < b; }
}
queryTypeMap.set("type", function(s) { return new TypeQuery(s); } );
class CategoryQuery {
constructor(category) { this.category = category; }
filter(item) {
if (item.remapID === undefined) {
return (item.category === this.category);
}
return false;
2021-01-24 03:58:53 +00:00
}
2021-01-24 10:09:59 +00:00
compare(a, b) { return a < b; }
2021-01-24 03:58:53 +00:00
}
2021-01-24 10:09:59 +00:00
queryTypeMap.set("category", function(s) { return new CategoryQuery(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); } );