Fix item sorting

This commit is contained in:
b 2021-02-05 11:35:13 -06:00
parent 194800a82d
commit 4dbf51ce5c
2 changed files with 54 additions and 30 deletions

View file

@ -130,10 +130,12 @@ function displayItems(items_copy) {
box.classList.add("box");
box.id = "item"+i;
items_parent.appendChild(box);
displayExpandedItem(expandItem(item, []), box.id);
displayExpandedItem(item, box.id);
}
}
let items_expanded;
function doItemSearch() {
window.scrollTo(0, 0);
let queries = [];
@ -174,26 +176,21 @@ function doItemSearch() {
}
}
let items_copy = items.slice();
let items_copy = items_expanded.slice();
document.getElementById("main").textContent = "";
for (const query of queries) {
console.log(items_copy.length);
console.log(query);
console.log(query.filter);
items_copy = applyQuery(items_copy, query);
console.log(items_copy.length);
}
document.getElementById("summary").textContent = items_copy.length + " results."
displayItems(items_copy);
}
function init() {
return;
let items_copy = items.slice();
//let query = new NameQuery("Bob's");
let query1 = new IdQuery("sdRaw");
items_copy = applyQuery(items_copy, query1);
let query2 = new TypeQuery("helmet");
items_copy = applyQuery(items_copy, query2);
displayItems(items_copy);
items_expanded = items.filter( (i) => !("remapID" in i) ).map( (i) => expandItem(i, []) );
}
load_init(init);

View file

@ -4,10 +4,7 @@ class NameQuery {
constructor(string) { this.queryString = string.toLowerCase(); }
filter(item) {
if (item.remapID === undefined) {
return (item.displayName.toLowerCase().includes(this.queryString));
}
return false;
return (item.get("displayName").toLowerCase().includes(this.queryString));
}
compare(a, b) { return a < b; }
@ -18,8 +15,8 @@ class LevelRangeQuery {
constructor(min, max) { this.min = min; this.max = max; }
filter(item) {
if (item.remapID === undefined) {
return (item.lvl <= this.max && item.lvl >= this.min);
if (item.get("remapID") === undefined) {
return (item.get("lvl") <= this.max && item.get("lvl") >= this.min);
}
return false;
}
@ -34,7 +31,7 @@ class NegateQuery {
}
filter(item) {
return (!(this.id in item)) || (item[this.id] == 0);
return (!item.get(this.id)) || (item.get(this.id) == 0);
}
}
queryTypeMap.set("null", function(s) { return new IdQuery(s); } );
@ -42,13 +39,33 @@ queryTypeMap.set("null", function(s) { return new IdQuery(s); } );
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]);
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");
}
else if (id in reversedIDs) {
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, 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, ,,,");
}
}
}
queryTypeMap.set("stat", function(s) { return new IdQuery(s); } );
@ -63,17 +80,27 @@ class IdMatchQuery {
}
filter(item) {
return (this.id in item) && (item[this.id] == this.value);
return item.get(this.id) && (item.get(this.id) == this.value);
}
}
class SumQuery {
constructor(ids) {
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));
}
}
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]; }
for (const getter of getters) {
if (getter(a)) { balance -= getter(a); }
if (getter(b)) { balance += getter(b); }
}
return balance;
};