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.classList.add("box");
box.id = "item"+i; box.id = "item"+i;
items_parent.appendChild(box); items_parent.appendChild(box);
displayExpandedItem(expandItem(item, []), box.id); displayExpandedItem(item, box.id);
} }
} }
let items_expanded;
function doItemSearch() { function doItemSearch() {
window.scrollTo(0, 0); window.scrollTo(0, 0);
let queries = []; let queries = [];
@ -174,26 +176,21 @@ function doItemSearch() {
} }
} }
let items_copy = items.slice(); let items_copy = items_expanded.slice();
document.getElementById("main").textContent = ""; document.getElementById("main").textContent = "";
for (const query of queries) { for (const query of queries) {
console.log(items_copy.length);
console.log(query);
console.log(query.filter);
items_copy = applyQuery(items_copy, query); items_copy = applyQuery(items_copy, query);
console.log(items_copy.length);
} }
document.getElementById("summary").textContent = items_copy.length + " results." document.getElementById("summary").textContent = items_copy.length + " results."
displayItems(items_copy); displayItems(items_copy);
} }
function init() { function init() {
return; items_expanded = items.filter( (i) => !("remapID" in i) ).map( (i) => expandItem(i, []) );
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);
} }
load_init(init); load_init(init);

View file

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