From 4dbf51ce5c0cb4571e2b5115fdf5a1f0d64fcee9 Mon Sep 17 00:00:00 2001 From: b Date: Fri, 5 Feb 2021 11:35:13 -0600 Subject: [PATCH] Fix item sorting --- items.js | 21 ++++++++----------- query.js | 63 ++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/items.js b/items.js index 0a129b6..61edcc1 100644 --- a/items.js +++ b/items.js @@ -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); diff --git a/query.js b/query.js index f119c06..6bb322a 100644 --- a/query.js +++ b/query.js @@ -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; };