Powders aaaa
This commit is contained in:
commit
c3c11dca3b
7 changed files with 801 additions and 393 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
||||||
*.swp
|
*.swp
|
||||||
*.bat
|
*.bat
|
||||||
sets/
|
sets/
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
|
|
@ -6,13 +6,15 @@ function calculateSpellDamage(stats, spellConversions, rawModifier, pctModifier,
|
||||||
|
|
||||||
let buildStats = new Map(stats);
|
let buildStats = new Map(stats);
|
||||||
if(externalStats) { //if nothing is passed in, then this hopefully won't trigger
|
if(externalStats) { //if nothing is passed in, then this hopefully won't trigger
|
||||||
for (const [key,value] of externalStats) {
|
for (let i = 0; i < externalStats.length; i++) {
|
||||||
|
const key = externalStats[i][0];
|
||||||
|
const value = externalStats[i][1];
|
||||||
if (typeof value === "number") {
|
if (typeof value === "number") {
|
||||||
buildStats.set(key, buildStats.get(key) + value);
|
buildStats.set(key, buildStats.get(key) + value);
|
||||||
} else if (Array.isArray(value)) {
|
} else if (Array.isArray(value)) {
|
||||||
arr = [];
|
arr = [];
|
||||||
for (let i = 0; i < value.length; i++) {
|
for (let j = 0; j < value.length; j++) {
|
||||||
arr[i] = buildStats.get(key)[i] + value[i];
|
arr[j] = buildStats.get(key)[j] + value[j];
|
||||||
}
|
}
|
||||||
buildStats.set(key, arr);
|
buildStats.set(key, arr);
|
||||||
}
|
}
|
||||||
|
@ -21,8 +23,9 @@ function calculateSpellDamage(stats, spellConversions, rawModifier, pctModifier,
|
||||||
|
|
||||||
// Array of neutral + ewtfa damages. Each entry is a pair (min, max).
|
// Array of neutral + ewtfa damages. Each entry is a pair (min, max).
|
||||||
let damages = [];
|
let damages = [];
|
||||||
for (const damage_string of buildStats.get("damageRaw")) {
|
const rawDamages = buildStats.get("damageRaw");
|
||||||
const damage_vals = damage_string.split("-").map(Number);
|
for (let i = 0; i < rawDamages.length; i++) {
|
||||||
|
const damage_vals = rawDamages[i].split("-").map(Number);
|
||||||
damages.push(damage_vals);
|
damages.push(damage_vals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
display.js
11
display.js
|
@ -511,7 +511,8 @@ function displayExpandedItem(item, parent_id){
|
||||||
let active_elem;
|
let active_elem;
|
||||||
let fix_id = item.has("fixID") && item.get("fixID");
|
let fix_id = item.has("fixID") && item.get("fixID");
|
||||||
let elemental_format = false;
|
let elemental_format = false;
|
||||||
for (const command of display_commands) {
|
for (let i = 0; i < display_commands.length; i++) {
|
||||||
|
const command = display_commands[i];
|
||||||
if (command.charAt(0) === "#") {
|
if (command.charAt(0) === "#") {
|
||||||
if (command === "#cdiv") {
|
if (command === "#cdiv") {
|
||||||
active_elem = document.createElement('div');
|
active_elem = document.createElement('div');
|
||||||
|
@ -725,12 +726,12 @@ function displayExpandedItem(item, parent_id){
|
||||||
effects = powderSpecial["armorSpecialEffects"];
|
effects = powderSpecial["armorSpecialEffects"];
|
||||||
specialTitle.textContent += powderSpecial["armorSpecialName"] + ": ";
|
specialTitle.textContent += powderSpecial["armorSpecialName"] + ": ";
|
||||||
}
|
}
|
||||||
for (const [key,value] of effects) {
|
for (let i = 0; i < effects.length; i++) {
|
||||||
if (key !== "Description") {
|
if (effects[i][0] !== "Description") {
|
||||||
let effect = document.createElement("p");
|
let effect = document.createElement("p");
|
||||||
effect.classList.add("itemp");
|
effect.classList.add("itemp");
|
||||||
effect.textContent += key + ": " + value[power] + specialSuffixes.get(key);
|
effect.textContent += effects[i][0] + ": " + effects[i][1][power] + specialSuffixes.get(effects[i][0]);
|
||||||
if(key === "Damage"){
|
if(effects[i][0] === "Damage"){
|
||||||
effect.textContent += elementIcons[skp_elements.indexOf(element)];
|
effect.textContent += elementIcons[skp_elements.indexOf(element)];
|
||||||
}
|
}
|
||||||
if (element === "w") {
|
if (element === "w") {
|
||||||
|
|
151
items.html
151
items.html
|
@ -1,144 +1,53 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html scroll-behavior="smooth">
|
<html scroll-behavior="smooth">
|
||||||
<head>
|
<head>
|
||||||
<meta name="HandheldFriendly" content="true" />
|
|
||||||
<meta name="MobileOptimized" content="320" />
|
|
||||||
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, width=device-width, user-scalable=no" />
|
|
||||||
<!-- nunito font, copying wynndata -->
|
<!-- nunito font, copying wynndata -->
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Nunito&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Nunito&display=swap" rel="stylesheet">
|
||||||
|
|
||||||
<link rel="stylesheet" href="styles.css">
|
<link rel="stylesheet" href="styles.css">
|
||||||
<link rel="stylesheet" href="items.css">
|
|
||||||
<link rel="stylesheet" media="screen and (min-width: 1100px)" href="items-wide.css"/>
|
|
||||||
<link rel="stylesheet" media="screen and (max-width: 1099px)" href="items-narrow.css"/>
|
|
||||||
<link rel="icon" href="favicon.png">
|
<link rel="icon" href="favicon.png">
|
||||||
<link rel="manifest" href="manifest.json">
|
<link rel="manifest" href="manifest.json">
|
||||||
<title>Wynn Clientside</title>
|
<title>WynnAtlas</title>
|
||||||
</head>
|
</head>
|
||||||
<body class="all">
|
<body class="all" style="overflow-y: scroll">
|
||||||
<div class="center">
|
<div class="header" id="header">
|
||||||
<header class = "header nomarginp">
|
WynnAtlas
|
||||||
<div class = "headerleft">
|
|
||||||
<a href = "./" class = "nomarginp iconlink tooltip">
|
|
||||||
<img src = "/media/icons/builder.png" class = "left linkoptions headericon">
|
|
||||||
</img>
|
|
||||||
<div class = "tooltiptext center">WynnBuilder</div>
|
|
||||||
</a>
|
|
||||||
<a href = "./crafter.html" class = "nomarginp iconlink tooltip">
|
|
||||||
<img src = "/media/icons/crafter.png" class = "left linkoptions headericon">
|
|
||||||
</img>
|
|
||||||
<div class = "tooltiptext center">WynnCrafter</div>
|
|
||||||
</a>
|
|
||||||
<a href = "./items.html" class = "nomarginp iconlink tooltip">
|
|
||||||
<img src = "/media/icons/searcher.png" class = "left linkoptions headericon">
|
|
||||||
</img>
|
|
||||||
<div class = "tooltiptext center">WynnAtlas</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
<div class = "headercenter">
|
<div class="center" id="header2">
|
||||||
<div >
|
Made by: hppeng and ferricles
|
||||||
<p class = "itemp" id = "header">WynnAtlas</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="center" id="credits">
|
||||||
|
<a href="credits.txt">Additional credits</a>
|
||||||
</div>
|
</div>
|
||||||
<div class = "headerright">
|
<div class="center" id="main" style="padding: 2%">
|
||||||
|
<div id="search-container" style="margin-bottom: 1.5%">
|
||||||
</div>
|
<div class="left" id="search-filter" style="display: inline-block; vertical-align: top">
|
||||||
</header>
|
<label for="search-filter-field">Filter By:</label>
|
||||||
</div>
|
|
||||||
<br>
|
<br>
|
||||||
|
<input id="search-filter-field" type="text" placeholder="str >= 15 & dex >= 10" style="width: 25vw; padding: 8px">
|
||||||
<br>
|
<br>
|
||||||
<div class="itemsearch">
|
<div id="search-filter-error" style="color: #ff0000"></div>
|
||||||
<div class="searchbox">
|
|
||||||
<div class="left">
|
|
||||||
<label for="name-choice">Name:</label><br>
|
|
||||||
<input class="searchinput" type="text" id="name-choice" name="name-choice" placeholder="Item name (case insensitive)" tabindex="1"/>
|
|
||||||
<p class="error"></p>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="left">
|
<div class="left" id="search-sort" style="display: inline-block; vertical-align: top">
|
||||||
<label for="category-choice">Category:</label><br>
|
<label for="search-sort-field">Sort By:</label>
|
||||||
<input class="searchinput" list="category-items" id="category-choice" name="category-choice" placeholder="ALL" tabindex="2"/>
|
<br>
|
||||||
<datalist id="category-items">
|
<input id="search-sort-field" type="text" placeholder="str + dex; meleerawdmg + spellrawdmg" style="width: 25vw; padding: 8px">
|
||||||
<option value="ALL">
|
<br>
|
||||||
<option value="armor">
|
<div id="search-sort-error" style="color: #ff0000"></div>
|
||||||
<option value="helmet">
|
|
||||||
<option value="chestplate">
|
|
||||||
<option value="leggings">
|
|
||||||
<option value="boots">
|
|
||||||
<option value="accessory">
|
|
||||||
<option value="ring">
|
|
||||||
<option value="bracelet">
|
|
||||||
<option value="necklace">
|
|
||||||
<option value="weapon">
|
|
||||||
<option value="wand">
|
|
||||||
<option value="spear">
|
|
||||||
<option value="bow">
|
|
||||||
<option value="dagger">
|
|
||||||
<option value="relik">
|
|
||||||
</datalist>
|
|
||||||
<p class="error"></p>
|
|
||||||
</div>
|
|
||||||
<div class="left">
|
|
||||||
<label for="rarity-choice">Rarity:</label><br>
|
|
||||||
<input class="searchinput" list="rarity-items" id="rarity-choice" name="rarity-choice" placeholder="ANY" tabindex="3"/>
|
|
||||||
<datalist id="rarity-items">
|
|
||||||
<option value="ANY">
|
|
||||||
<option value="Normal">
|
|
||||||
<option value="Unique">
|
|
||||||
<option value="Rare">
|
|
||||||
<option value="Legendary">
|
|
||||||
<option value="Fabled">
|
|
||||||
<option value="Mythic">
|
|
||||||
<option value="Sane">
|
|
||||||
</datalist>
|
|
||||||
<p class="error"></p>
|
|
||||||
</div>
|
|
||||||
<div class="left">
|
|
||||||
<label for="level-choice">Level:</label><br>
|
|
||||||
<input class="searchinput" type="text" id="level-choice" name="level-choice" value="1-106" tabindex="4"/>
|
|
||||||
<p class="error"></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<datalist id="filter-items">
|
|
||||||
</datalist>
|
|
||||||
<div class="left">
|
|
||||||
<label for="filter1-choice">Filter 1:</label><br>
|
|
||||||
<input class="searchinput" list="filter-items" id="filter1-choice" name="filter1-choice" placeholder="ANY" tabindex="5"/>
|
|
||||||
<p class="error"></p>
|
|
||||||
</div>
|
|
||||||
<div class="left">
|
|
||||||
<label for="filter2-choice">Filter 2:</label><br>
|
|
||||||
<input class="searchinput" list="filter-items" id="filter2-choice" name="filter2-choice" placeholder="ANY" tabindex="6"/>
|
|
||||||
<p class="error"></p>
|
|
||||||
</div>
|
|
||||||
<div class="left">
|
|
||||||
<label for="filter3-choice">Filter 3:</label><br>
|
|
||||||
<input class="searchinput" list="filter-items" id="filter3-choice" name="filter3-choice" placeholder="ANY" tabindex="7"/>
|
|
||||||
<p class="error"></p>
|
|
||||||
</div>
|
|
||||||
<div class="left">
|
|
||||||
<label for="filter4-choice">Filter 4:</label><br>
|
|
||||||
<input class="searchinput" list="filter-items" id="filter4-choice" name="filter4-choice" placeholder="ANY" tabindex="8"/>
|
|
||||||
<p class="error"></p>
|
|
||||||
</div>
|
|
||||||
<div class="right" style="grid-column:1/span 2">
|
|
||||||
<button class = "button" id = "search-button" onclick = "doItemSearch()" tabindex="9">
|
|
||||||
Search!
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div id="summary" class="left" style="grid-column:3/span 2">
|
|
||||||
Hello!
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="center items" id="main">
|
<div id="item-list-container">
|
||||||
|
<div class="left" id="item-list" style="display: flex; flex-flow: row wrap"></div>
|
||||||
|
<div class="center" id="item-list-footer"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript" src="/utils.js"></script>
|
<script type="text/javascript" src="utils.js"></script>
|
||||||
<script type="text/javascript" src="/build_utils.js"></script>
|
<script type="text/javascript" src="build_utils.js"></script>
|
||||||
<script type="text/javascript" src="/damage_calc.js"></script>
|
<script type="text/javascript" src="damage_calc.js"></script>
|
||||||
<script type="text/javascript" src="/display.js"></script>
|
<script type="text/javascript" src="display.js"></script>
|
||||||
<script type="text/javascript" src="/query.js"></script>
|
<script type="text/javascript" src="query.js"></script>
|
||||||
<script type="text/javascript" src="/load.js"></script>
|
<script type="text/javascript" src="load.js"></script>
|
||||||
<script type="text/javascript" src="/items.js"></script>
|
<script type="text/javascript" src="items.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
354
items.js
354
items.js
|
@ -1,199 +1,193 @@
|
||||||
|
// represents a field containing a query expression string
|
||||||
const translate_mappings = {
|
class ExprField {
|
||||||
//"Name": "name",
|
constructor(fieldId, errorTextId, compiler) {
|
||||||
//"Display Name": "displayName",
|
this.field = document.getElementById(fieldId);
|
||||||
//"tier"Tier": ",
|
this.errorText = document.getElementById(errorTextId);
|
||||||
//"Set": "set",
|
this.compiler = compiler;
|
||||||
"Powder Slots": "slots",
|
this.output = null;
|
||||||
//"Type": "type",
|
this.text = null;
|
||||||
//"armorType", (deleted)
|
|
||||||
//"color", (deleted)
|
|
||||||
//"lore", (deleted)
|
|
||||||
//"material", (deleted)
|
|
||||||
"Drop type": "drop",
|
|
||||||
"Quest requirement": "quest",
|
|
||||||
"Restriction": "restrict",
|
|
||||||
//"Base Neutral Damage": "nDam",
|
|
||||||
//"Base Fire Damage": "fDam",
|
|
||||||
//"Base Water Damage": "wDam",
|
|
||||||
//"Base Air Damage": "aDam",
|
|
||||||
//"Base Thunder Damage": "tDam",
|
|
||||||
//"Base Earth Damage": "eDam",
|
|
||||||
//"Base Attack Speed": "atkSpd",
|
|
||||||
"Health": "hp",
|
|
||||||
"Raw Fire Defense": "fDef",
|
|
||||||
"Raw Water Defense": "wDef",
|
|
||||||
"Raw Air Defense": "aDef",
|
|
||||||
"Raw Thunder Defense": "tDef",
|
|
||||||
"Raw Earth Defense": "eDef",
|
|
||||||
"Combat Level": "lvl",
|
|
||||||
//"Class Requirement": "classReq",
|
|
||||||
"Req Strength": "strReq",
|
|
||||||
"Req Dexterity": "dexReq",
|
|
||||||
"Req Intelligence": "intReq",
|
|
||||||
"Req Agility": "agiReq",
|
|
||||||
"Req Defense": "defReq",
|
|
||||||
"% Health Regen": "hprPct",
|
|
||||||
"Mana Regen": "mr",
|
|
||||||
"% Spell Damage": "sdPct",
|
|
||||||
"% Melee Damage": "mdPct",
|
|
||||||
"Life Steal": "ls",
|
|
||||||
"Mana Steal": "ms",
|
|
||||||
"XP Bonus": "xpb",
|
|
||||||
"Loot Bonus": "lb",
|
|
||||||
"Reflection": "ref",
|
|
||||||
"Strength": "str",
|
|
||||||
"Dexterity": "dex",
|
|
||||||
"Intelligence": "int",
|
|
||||||
"Agility": "agi",
|
|
||||||
"Defense": "def",
|
|
||||||
"Thorns": "thorns",
|
|
||||||
"Exploding": "expd",
|
|
||||||
"Walk Speed": "spd",
|
|
||||||
"Attack Speed Bonus": "atkTier",
|
|
||||||
"Poison": "poison",
|
|
||||||
"Health Bonus": "hpBonus",
|
|
||||||
"Soul Point Regen": "spRegen",
|
|
||||||
"Stealing": "eSteal",
|
|
||||||
"Raw Health Regen": "hprRaw",
|
|
||||||
"Raw Spell": "sdRaw",
|
|
||||||
"Raw Melee": "mdRaw",
|
|
||||||
"% Fire Damage": "fDamPct",
|
|
||||||
"% Water Damage": "wDamPct",
|
|
||||||
"% Air Damage": "aDamPct",
|
|
||||||
"% Thunder Damage": "tDamPct",
|
|
||||||
"% Earth Damage": "eDamPct",
|
|
||||||
"% Fire Defense": "fDefPct",
|
|
||||||
"% Water Defense": "wDefPct",
|
|
||||||
"% Air Defense": "aDefPct",
|
|
||||||
"% Thunder Defense": "tDefPct",
|
|
||||||
"% Earth Defense": "eDefPct",
|
|
||||||
"Fixed IDs": "fixID",
|
|
||||||
"Custom Skin": "skin",
|
|
||||||
//"Item Category": "category",
|
|
||||||
|
|
||||||
"1st Spell Cost %": "spPct1",
|
|
||||||
"1st Spell Cost Raw": "spRaw1",
|
|
||||||
"2nd Spell Cost %": "spPct2",
|
|
||||||
"2nd Spell Cost Raw": "spRaw2",
|
|
||||||
"3rd Spell Cost %": "spPct3",
|
|
||||||
"3rd Spell Cost Raw": "spRaw3",
|
|
||||||
"4th Spell Cost %": "spPct4",
|
|
||||||
"4th Spell Cost Raw": "spRaw4",
|
|
||||||
|
|
||||||
"Rainbow Spell Damage": "rainbowRaw",
|
|
||||||
"Sprint": "sprint",
|
|
||||||
"Sprint Regen": "sprintReg",
|
|
||||||
"Jump Height": "jh",
|
|
||||||
"Loot Quality": "lq",
|
|
||||||
|
|
||||||
"Gather XP Bonus": "gXp",
|
|
||||||
"Gather Speed Bonus": "gSpd",
|
|
||||||
};
|
|
||||||
|
|
||||||
const special_mappings = {
|
|
||||||
"Sum (skill points)": new SumQuery(["str", "dex", "int", "def", "agi"]),
|
|
||||||
"Sum (Mana Sustain)": new SumQuery(["mr", "ms"]),
|
|
||||||
"Sum (Life Sustain)": new SumQuery(["hpr", "ls"]),
|
|
||||||
"Sum (Health + Health Bonus)": new SumQuery(["hp", "hpBonus"]),
|
|
||||||
"No Strength Req": new NegateQuery("strReq"),
|
|
||||||
"No Dexterity Req": new NegateQuery("dexReq"),
|
|
||||||
"No Intelligence Req": new NegateQuery("intReq"),
|
|
||||||
"No Agility Req": new NegateQuery("agiReq"),
|
|
||||||
"No Defense Req": new NegateQuery("defReq"),
|
|
||||||
};
|
|
||||||
|
|
||||||
let itemFilters = document.getElementById("filter-items");
|
|
||||||
for (let x in translate_mappings) {
|
|
||||||
let el = document.createElement("option");
|
|
||||||
el.value = x;
|
|
||||||
itemFilters.appendChild(el);
|
|
||||||
}
|
|
||||||
for (let x in special_mappings) {
|
|
||||||
let el = document.createElement("option");
|
|
||||||
el.value = x;
|
|
||||||
itemFilters.appendChild(el);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let itemTypes = [ "helmet", "chestplate", "leggings", "boots", "ring", "bracelet", "necklace", "wand", "spear", "bow", "dagger", "relik" ];
|
get value() {
|
||||||
let itemCategories = [ "armor", "accessory", "weapon" ];
|
return this.field.value;
|
||||||
|
|
||||||
function applyQuery(items, query) {
|
|
||||||
return items.filter(query.filter, query).sort(query.compare);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayItems(items_copy) {
|
compile() {
|
||||||
let items_parent = document.getElementById("main");
|
if (this.value === this.text) return false;
|
||||||
for (let i in items_copy) {
|
this.text = this.value;
|
||||||
let item = items_copy[i];
|
this.errorText.innerText = '';
|
||||||
let box = document.createElement("div");
|
try {
|
||||||
box.classList.add("box");
|
this.output = this.compiler(this.text);
|
||||||
box.id = "item"+i;
|
} catch (e) {
|
||||||
items_parent.appendChild(box);
|
this.errorText.innerText = e.message;
|
||||||
displayExpandedItem(expandItem(item, []), box.id);
|
this.output = null;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doItemSearch() {
|
function compareLexico(ia, keysA, ib, keysB) {
|
||||||
window.scrollTo(0, 0);
|
for (let i = 0; i < keysA.length; i++) { // assuming keysA and keysB are the same length
|
||||||
let queries = [];
|
let aKey = keysA[i], bKey = keysB[i];
|
||||||
queries.push(new NameQuery(document.getElementById("name-choice").value));
|
if (typeof aKey !== typeof bKey) throw new Error(`Incomparable types ${typeof aKey} and ${typeof bKey}`); // can this even happen?
|
||||||
|
switch (typeof aKey) {
|
||||||
let categoryOrType = document.getElementById("category-choice").value;
|
case 'string':
|
||||||
if (itemTypes.includes(categoryOrType)) {
|
aKey = aKey.toLowerCase();
|
||||||
queries.push(new IdMatchQuery("type", categoryOrType));
|
bKey = bKey.toLowerCase();
|
||||||
|
if (aKey < bKey) return -1;
|
||||||
|
if (aKey > bKey) return 1;
|
||||||
|
break;
|
||||||
|
case 'number': // sort numeric stuff in reverse order
|
||||||
|
if (aKey < bKey) return 1;
|
||||||
|
if (aKey > bKey) return -1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`Incomparable type ${typeof aKey}`);
|
||||||
}
|
}
|
||||||
else if (itemCategories.includes(categoryOrType)) {
|
}
|
||||||
queries.push(new IdMatchQuery("category", categoryOrType));
|
return ib.lvl - ia.lvl;
|
||||||
}
|
}
|
||||||
|
|
||||||
let rarity = document.getElementById("rarity-choice").value;
|
function stringify(v) {
|
||||||
if (rarity) {
|
return typeof v === 'number' ? (Math.round(v * 100) / 100).toString() : v;
|
||||||
if (rarity === "ANY") {
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
queries.push(new IdMatchQuery("tier", rarity));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let level_dat = document.getElementById("level-choice").value.split("-");
|
|
||||||
queries.push(new LevelRangeQuery(parseInt(level_dat[0]), parseInt(level_dat[1])));
|
|
||||||
|
|
||||||
for (let i = 1; i <= 4; ++i) {
|
|
||||||
let raw_dat = document.getElementById("filter"+i+"-choice").value;
|
|
||||||
let filter_dat = translate_mappings[raw_dat];
|
|
||||||
if (filter_dat !== undefined) {
|
|
||||||
queries.push(new IdQuery(filter_dat));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
filter_dat = special_mappings[raw_dat];
|
|
||||||
if (filter_dat !== undefined) {
|
|
||||||
queries.push(filter_dat);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let items_copy = items.slice();
|
|
||||||
document.getElementById("main").textContent = "";
|
|
||||||
for (const query of queries) {
|
|
||||||
items_copy = applyQuery(items_copy, query);
|
|
||||||
}
|
|
||||||
document.getElementById("summary").textContent = items_copy.length + " results."
|
|
||||||
displayItems(items_copy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
const itemList = document.getElementById('item-list');
|
||||||
|
const itemListFooter = document.getElementById('item-list-footer');
|
||||||
|
|
||||||
|
// compile the search db from the item db
|
||||||
|
const searchDb = items.filter(i => !i.remapID).map(i => [i, expandItem(i, [])]);
|
||||||
|
|
||||||
|
// init item list elements
|
||||||
|
const ITEM_LIST_SIZE = 64;
|
||||||
|
const itemEntries = [];
|
||||||
|
for (let i = 0; i < ITEM_LIST_SIZE; i++) {
|
||||||
|
const itemElem = document.createElement('div');
|
||||||
|
itemElem.classList.add('box');
|
||||||
|
itemElem.setAttribute('id', `item-entry-${i}`);
|
||||||
|
itemElem.style.display = 'none';
|
||||||
|
itemElem.style.width = '20vw';
|
||||||
|
itemElem.style.margin = '1vw';
|
||||||
|
itemElem.style.verticalAlign = 'top';
|
||||||
|
itemList.append(itemElem);
|
||||||
|
itemEntries.push(itemElem);
|
||||||
|
}
|
||||||
|
|
||||||
|
// the two search query input boxes
|
||||||
|
const searchFilterField = new ExprField('search-filter-field', 'search-filter-error', function(exprStr) {
|
||||||
|
const expr = compileQueryExpr(exprStr);
|
||||||
|
return expr !== null ? expr : (i, ie) => true;
|
||||||
|
});
|
||||||
|
const searchSortField = new ExprField('search-sort-field', 'search-sort-error', function(exprStr) {
|
||||||
|
const subExprs = exprStr.split(';').map(compileQueryExpr).filter(f => f != null);
|
||||||
|
return function(i, ie) {
|
||||||
|
const sortKeys = [];
|
||||||
|
for (let k = 0; k < subExprs.length; k++) sortKeys.push(subExprs[k](i, ie));
|
||||||
|
return sortKeys;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// updates the current search state from the search query input boxes
|
||||||
|
function updateSearch() {
|
||||||
|
// compile query expressions, aborting if nothing has changed or either fails to compile
|
||||||
|
const changed = searchFilterField.compile() | searchSortField.compile();
|
||||||
|
if (!changed || searchFilterField.output === null || searchSortField.output === null) return;
|
||||||
|
|
||||||
|
// update url query string
|
||||||
|
const newUrl = `${window.location.protocol}//${window.location.host}${window.location.pathname}`
|
||||||
|
+ `?f=${encodeURIComponent(searchFilterField.value)}&s=${encodeURIComponent(searchSortField.value)}`;
|
||||||
|
window.history.pushState({ path: newUrl }, '', newUrl);
|
||||||
|
|
||||||
|
// hide old search results
|
||||||
|
itemListFooter.innerText = '';
|
||||||
|
for (const itemEntry of itemEntries) itemEntry.style.display = 'none';
|
||||||
|
|
||||||
|
// index and sort search results
|
||||||
|
const searchResults = [];
|
||||||
|
try {
|
||||||
|
for (let i = 0; i < searchDb.length; i++) {
|
||||||
|
const item = searchDb[i][0], itemExp = searchDb[i][1];
|
||||||
|
if (checkBool(searchFilterField.output(item, itemExp))) {
|
||||||
|
searchResults.push({ item, itemExp, sortKeys: searchSortField.output(item, itemExp) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
searchFilterField.errorText.innerText = e.message;
|
||||||
return;
|
return;
|
||||||
let items_copy = items.slice();
|
}
|
||||||
//let query = new NameQuery("Bob's");
|
if (searchResults.length === 0) {
|
||||||
let query1 = new IdQuery("sdRaw");
|
itemListFooter.innerText = 'No results!';
|
||||||
items_copy = applyQuery(items_copy, query1);
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
searchResults.sort((a, b) => compareLexico(a.item, a.sortKeys, b.item, b.sortKeys));
|
||||||
|
} catch (e) {
|
||||||
|
searchSortField.errorText.innerText = e.message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let query2 = new TypeQuery("helmet");
|
// display search results
|
||||||
items_copy = applyQuery(items_copy, query2);
|
const searchMax = Math.min(searchResults.length, ITEM_LIST_SIZE);
|
||||||
|
for (let i = 0; i < searchMax; i++) {
|
||||||
|
const result = searchResults[i];
|
||||||
|
itemEntries[i].style.display = 'inline-block';
|
||||||
|
displayExpandedItem(result.itemExp, `item-entry-${i}`);
|
||||||
|
if (result.sortKeys.length > 0) {
|
||||||
|
const sortKeyListContainer = document.createElement('div');
|
||||||
|
sortKeyListContainer.classList.add('itemleft');
|
||||||
|
const sortKeyList = document.createElement('ul');
|
||||||
|
sortKeyList.classList.add('itemp', 'T0');
|
||||||
|
sortKeyList.style.marginLeft = '1.75em';
|
||||||
|
sortKeyListContainer.append(sortKeyList);
|
||||||
|
for (let j = 0; j < result.sortKeys.length; j++) {
|
||||||
|
const sortKeyElem = document.createElement('li');
|
||||||
|
sortKeyElem.innerText = stringify(result.sortKeys[j]);
|
||||||
|
sortKeyList.append(sortKeyElem);
|
||||||
|
}
|
||||||
|
itemEntries[i].append(sortKeyListContainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (searchMax < searchResults.length) {
|
||||||
|
itemListFooter.innerText = `${searchResults.length - searchMax} more...`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
displayItems(items_copy);
|
// updates the search state from the input boxes after a brief delay, to prevent excessive DOM updates
|
||||||
|
let updateSearchTask = null;
|
||||||
|
function scheduleSearchUpdate() {
|
||||||
|
if (updateSearchTask !== null) {
|
||||||
|
clearTimeout(updateSearchTask);
|
||||||
|
}
|
||||||
|
updateSearchTask = setTimeout(() => {
|
||||||
|
updateSearchTask = null;
|
||||||
|
updateSearch();
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
searchFilterField.field.addEventListener('input', e => scheduleSearchUpdate());
|
||||||
|
searchSortField.field.addEventListener('input', e => scheduleSearchUpdate());
|
||||||
|
|
||||||
|
// parse query string, display initial search results
|
||||||
|
if (window.location.search.startsWith('?')) {
|
||||||
|
for (const entryStr of window.location.search.substring(1).split('&')) {
|
||||||
|
const ndx = entryStr.indexOf('=');
|
||||||
|
if (ndx !== -1) {
|
||||||
|
switch (entryStr.substring(0, ndx)) {
|
||||||
|
case 'f':
|
||||||
|
searchFilterField.field.value = decodeURIComponent(entryStr.substring(ndx + 1));
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
searchSortField.field.value = decodeURIComponent(entryStr.substring(ndx + 1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateSearch();
|
||||||
|
|
||||||
|
// focus the query filter text box
|
||||||
|
searchFilterField.field.focus();
|
||||||
|
searchFilterField.field.select();
|
||||||
}
|
}
|
||||||
|
|
||||||
load_init(init);
|
load_init(init);
|
||||||
|
|
621
query.js
621
query.js
|
@ -1,85 +1,582 @@
|
||||||
let queryTypeMap = new Map();
|
/*
|
||||||
|
* disj := conj "|" disj
|
||||||
|
* | conj
|
||||||
|
*
|
||||||
|
* conj := cmp "&" conj
|
||||||
|
* | cmpEq
|
||||||
|
*
|
||||||
|
* cmpEq := cmpRel "=" cmpEq
|
||||||
|
* | cmpRel "!=" cmpEq
|
||||||
|
*
|
||||||
|
* cmpRel := sum "<=" cmpRel
|
||||||
|
* | sum "<" cmpRel
|
||||||
|
* | sum ">" cmpRel
|
||||||
|
* | sum ">=" cmpRel
|
||||||
|
* | sum
|
||||||
|
*
|
||||||
|
* sum := prod "+" sum
|
||||||
|
* | prod "-" sum
|
||||||
|
* | prod
|
||||||
|
*
|
||||||
|
* prod := exp "*" prod
|
||||||
|
* | exp "/" prod
|
||||||
|
* | exp
|
||||||
|
*
|
||||||
|
* exp := unary "^" exp
|
||||||
|
* | unary
|
||||||
|
*
|
||||||
|
* unary := "-" unary
|
||||||
|
* | "!" unary
|
||||||
|
* | prim
|
||||||
|
*
|
||||||
|
* prim := nLit
|
||||||
|
* | bLit
|
||||||
|
* | sLit
|
||||||
|
* | ident "(" [disj ["," disj...]] ")"
|
||||||
|
* | ident
|
||||||
|
* | "(" disj ")"
|
||||||
|
*/
|
||||||
|
|
||||||
class NameQuery {
|
// a list of tokens indexed by a single pointer
|
||||||
constructor(string) { this.queryString = string.toLowerCase(); }
|
class TokenList {
|
||||||
|
constructor(tokens) {
|
||||||
filter(item) {
|
this.tokens = tokens;
|
||||||
if (item.remapID === undefined) {
|
this.ptr = 0;
|
||||||
return (item.displayName.toLowerCase().includes(this.queryString));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compare(a, b) { return a < b; }
|
get here() {
|
||||||
}
|
if (this.ptr >= this.tokens.length) throw new Error('Reached end of expression');
|
||||||
queryTypeMap.set("name", function(s) { return new NameQuery(s); } );
|
return this.tokens[this.ptr];
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compare(a, b) { return a > b; }
|
advance(steps = 1) {
|
||||||
|
this.ptr = Math.min(this.ptr + steps, this.tokens.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NegateQuery {
|
// type casts
|
||||||
constructor(id) {
|
function checkBool(v) {
|
||||||
this.id = id;
|
if (typeof v !== 'boolean') throw new Error(`Expected boolean, but got ${typeof v}`);
|
||||||
this.compare = function(a, b) { return 0; };
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
filter(item) {
|
function checkNum(v) {
|
||||||
return (!(this.id in item)) || (item[this.id] == 0);
|
if (typeof v !== 'number') throw new Error(`Expected number, but got ${typeof v}`);
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
queryTypeMap.set("null", function(s) { return new IdQuery(s); } );
|
|
||||||
|
|
||||||
class IdQuery {
|
function checkStr(v) {
|
||||||
constructor(id) {
|
if (typeof v !== 'string') throw new Error(`Expected string, but got ${typeof v}`);
|
||||||
this.id = id;
|
return v;
|
||||||
this.compare = function(a, b) {
|
}
|
||||||
return b[id] - a[id];
|
|
||||||
|
// properties of items that can be looked up
|
||||||
|
const itemQueryProps = (function() {
|
||||||
|
const props = {};
|
||||||
|
function prop(names, getProp) {
|
||||||
|
if (Array.isArray(names)) {
|
||||||
|
for (name of names) {
|
||||||
|
props[name] = getProp;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
props[names] = getProp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function maxId(names, idKey) {
|
||||||
|
prop(names, (i, ie) => ie.get('maxRolls').get(idKey) || 0);
|
||||||
|
}
|
||||||
|
function minId(names, idKey) {
|
||||||
|
prop(names, (i, ie) => ie.get('minRolls').get(idKey) || 0);
|
||||||
|
}
|
||||||
|
function rangeAvg(names, getProp) {
|
||||||
|
prop(names, (i, ie) => {
|
||||||
|
const range = getProp(i, ie);
|
||||||
|
if (!range) return 0;
|
||||||
|
const ndx = range.indexOf('-');
|
||||||
|
return (parseInt(range.substring(0, ndx), 10) + parseInt(range.substring(ndx + 1), 10)) / 2;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function map(names, comps, f) {
|
||||||
|
return prop(names, (i, ie) => {
|
||||||
|
const args = [];
|
||||||
|
for (let k = 0; k < comps.length; k++) args.push(comps[k](i, ie));
|
||||||
|
return f.apply(null, args);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function sum(names, ...comps) {
|
||||||
|
return map(names, comps, (...summands) => {
|
||||||
|
let total = 0;
|
||||||
|
for (let i = 0; i < summands.length; i++) total += summands[i];
|
||||||
|
return total;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
prop('name', (i, ie) => i.displayName || i.name);
|
||||||
|
prop('type', (i, ie) => i.type);
|
||||||
|
prop(['cat', 'category'], (i, ie) => i.category);
|
||||||
|
const tierIndices = { Normal: 0, Unique: 1, Set: 2, Rare: 3, Legendary: 4, Fabled: 5, Mythic: 6 };
|
||||||
|
prop(['rarityname', 'raritystr', 'tiername', 'tierstr'], (i, ie) => i.tier);
|
||||||
|
prop(['rarity', 'tier'], (i, ie) => tierIndices[i.tier]);
|
||||||
|
|
||||||
|
prop(['level', 'lvl', 'combatlevel', 'combatlvl'], (i, ie) => i.lvl);
|
||||||
|
prop(['strmin', 'strreq'], (i, ie) => i.strReq);
|
||||||
|
prop(['dexmin', 'dexreq'], (i, ie) => i.dexReq);
|
||||||
|
prop(['intmin', 'intreq'], (i, ie) => i.intReq);
|
||||||
|
prop(['defmin', 'defreq'], (i, ie) => i.defReq);
|
||||||
|
prop(['agimin', 'agireq'], (i, ie) => i.agiReq);
|
||||||
|
sum(['summin', 'sumreq', 'totalmin', 'totalreq'], props.strmin, props.dexmin, props.intmin, props.defmin, props.agimin);
|
||||||
|
|
||||||
|
prop('str', (i, ie) => i.str);
|
||||||
|
prop('dex', (i, ie) => i.dex);
|
||||||
|
prop('int', (i, ie) => i.int);
|
||||||
|
prop('def', (i, ie) => i.def);
|
||||||
|
prop('agi', (i, ie) => i.agi);
|
||||||
|
sum(['skillpoints', 'skillpts', 'attributes', 'attrs'], props.str, props.dex, props.int, props.def, props.agi);
|
||||||
|
|
||||||
|
rangeAvg(['neutraldmg', 'neutraldam', 'ndmg', 'ndam'], (i, ie) => i.nDam);
|
||||||
|
rangeAvg(['earthdmg', 'earthdam', 'edmg', 'edam'], (i, ie) => i.eDam);
|
||||||
|
rangeAvg(['thunderdmg', 'thunderdam', 'tdmg', 'tdam'], (i, ie) => i.tDam);
|
||||||
|
rangeAvg(['waterdmg', 'waterdam', 'wdmg', 'wdam'], (i, ie) => i.wDam);
|
||||||
|
rangeAvg(['firedmg', 'firedam', 'fdmg', 'fdam'], (i, ie) => i.fDam);
|
||||||
|
rangeAvg(['airdmg', 'airdam', 'admg', 'adam'], (i, ie) => i.aDam);
|
||||||
|
sum(['sumdmg', 'sumdam', 'totaldmg', 'totaldam'], props.ndam, props.edam, props.tdam, props.wdam, props.fdam, props.adam);
|
||||||
|
|
||||||
|
maxId(['earthdmg%', 'earthdam%', 'edmg%', 'edam%', 'edampct'], 'eDamPct');
|
||||||
|
maxId(['thunderdmg%', 'thunderdam%', 'tdmg%', 'tdam%', 'tdampct'], 'tDamPct');
|
||||||
|
maxId(['waterdmg%', 'waterdam%', 'wdmg%', 'wdam%', 'wdampct'], 'wDamPct');
|
||||||
|
maxId(['firedmg%', 'firedam%', 'fdmg%', 'fdam%', 'fdampct'], 'fDamPct');
|
||||||
|
maxId(['airdmg%', 'airdam%', 'admg%', 'adam%', 'adampct'], 'aDamPct');
|
||||||
|
sum(['sumdmg%', 'sumdam%', 'totaldmg%', 'totaldam%', 'sumdampct', 'totaldampct'], props.edampct, props.tdampct, props.wdampct, props.fdampct, props.adampct);
|
||||||
|
|
||||||
|
maxId(['mainatkdmg', 'mainatkdam', 'mainatkdmg%', 'mainatkdam%', 'meleedmg', 'meleedam', 'meleedmg%', 'meleedam%', 'mdpct'], 'mdPct');
|
||||||
|
maxId(['mainatkrawdmg', 'mainatkrawdam', 'mainatkneutraldmg', 'mainatkneutraldam', 'meleerawdmg', 'meleerawdam', 'meleeneutraldmg', 'meleeneutraldam', 'mdraw'], 'mdRaw');
|
||||||
|
maxId(['spelldmg', 'spelldam', 'spelldmg%', 'spelldam%', 'sdpct'], 'sdPct');
|
||||||
|
maxId(['spellrawdmg', 'spellrawdam', 'spellneutraldmg', 'spellneutraldam', 'sdraw'], 'sdRaw');
|
||||||
|
|
||||||
|
const atkSpdIndices = { SUPER_SLOW: -3, VERY_SLOW: -2, SLOW: -1, NORMAL: 0, FAST: 1, VERY_FAST: 2, SUPER_FAST: 3 };
|
||||||
|
prop(['attackspeed', 'atkspd'], (i, ie) => i.atkSpd ? atkSpdIndices[i.atkSpd] : 0);
|
||||||
|
maxId(['bonusattackspeed', 'bonusatkspd', 'attackspeedid', 'atkspdid', 'attackspeed+', 'atkspd+', 'atktier'], 'atkTier');
|
||||||
|
sum(['sumattackspeed', 'totalattackspeed', 'sumatkspd', 'totalatkspd', 'sumatktier', 'totalatktier'], props.atkspd, props.atktier);
|
||||||
|
|
||||||
|
prop(['earthdef', 'edef'], (i, ie) => i.eDef || 0);
|
||||||
|
prop(['thunderdef', 'tdef'], (i, ie) => i.tDef || 0);
|
||||||
|
prop(['waterdef', 'wdef'], (i, ie) => i.wDef || 0);
|
||||||
|
prop(['firedef', 'fdef'], (i, ie) => i.fDef || 0);
|
||||||
|
prop(['airdef', 'adef'], (i, ie) => i.aDef || 0);
|
||||||
|
sum(['sumdef', 'totaldef'], props.edef, props.tdef, props.wdef, props.fdef, props.adef);
|
||||||
|
|
||||||
|
maxId(['earthdef%', 'edef%', 'edefpct'], 'eDefPct');
|
||||||
|
maxId(['thunderdef%', 'tdef%', 'tdefpct'], 'tDefPct');
|
||||||
|
maxId(['waterdef%', 'wdef%', 'wdefpct'], 'wDefPct');
|
||||||
|
maxId(['firedef%', 'fdef%', 'fdefpct'], 'fDefPct');
|
||||||
|
maxId(['airdef%', 'adef%', 'adefpct'], 'aDefPct');
|
||||||
|
sum(['sumdef%', 'totaldef%', 'sumdefpct', 'totaldefpct'], props.edefpct, props.tdefpct, props.wdefpct, props.fdefpct, props.adefpct);
|
||||||
|
|
||||||
|
prop(['health', 'hp'], (i, ie) => i.hp || 0);
|
||||||
|
maxId(['bonushealth', 'healthid', 'bonushp', 'hpid', 'health+', 'hp+', 'hpbonus'], 'hpBonus');
|
||||||
|
sum(['sumhealth', 'sumhp', 'totalhealth', 'totalhp'], props.hp, props.hpid);
|
||||||
|
|
||||||
|
maxId(['hpregen', 'hpr', 'hr', 'hprraw'], 'hprRaw');
|
||||||
|
maxId(['hpregen%', 'hpr%', 'hr%', 'hprpct'], 'hprPct');
|
||||||
|
maxId(['lifesteal', 'ls'], 'ls');
|
||||||
|
maxId(['manaregen', 'mr'], 'mr');
|
||||||
|
maxId(['manasteal', 'ms'], 'ms');
|
||||||
|
|
||||||
|
maxId(['walkspeed', 'movespeed', 'ws', 'spd'], 'spd');
|
||||||
|
maxId('sprint', 'sprint');
|
||||||
|
maxId(['sprintregen', 'sprintreg'], 'sprintReg');
|
||||||
|
maxId(['jumpheight', 'jh'], 'jh');
|
||||||
|
|
||||||
|
minId(['spellcost1', 'rawspellcost1', 'spcost1', 'spraw1'], 'spRaw1');
|
||||||
|
minId(['spellcost1%', 'spcost1%', 'sppct1'], 'spPct1');
|
||||||
|
minId(['spellcost2', 'rawspellcost2', 'spcost2', 'spraw2'], 'spRaw2');
|
||||||
|
minId(['spellcost2%', 'spcost2%', 'sppct2'], 'spPct2');
|
||||||
|
minId(['spellcost3', 'rawspellcost3', 'spcost3', 'spraw3'], 'spRaw3');
|
||||||
|
minId(['spellcost3%', 'spcost3%', 'sppct3'], 'spPct3');
|
||||||
|
minId(['spellcost4', 'rawspellcost4', 'spcost4', 'spraw4'], 'spRaw4');
|
||||||
|
minId(['spellcost4%', 'spcost4%', 'sppct4'], 'spPct4');
|
||||||
|
sum(['sumspellcost', 'totalspellcost', 'sumrawspellcost', 'totalrawspellcost', 'sumspcost', 'totalspcost', 'sumspraw', 'totalspraw'], props.spraw1, props.spraw2, props.spraw3, props.spraw4);
|
||||||
|
sum(['sumspellcost%', 'totalspellcost%', 'sumspcost%', 'totalspcost%', 'sumsppct', 'totalsppct'], props.sppct1, props.sppct2, props.sppct3, props.sppct4);
|
||||||
|
|
||||||
|
maxId(['exploding', 'expl', 'expd'], 'expd');
|
||||||
|
maxId('poison', 'poison');
|
||||||
|
maxId('thorns', 'thorns');
|
||||||
|
maxId(['reflection', 'refl', 'ref'], 'ref');
|
||||||
|
maxId(['soulpointregen', 'spr', 'spregen'], 'spRegen');
|
||||||
|
maxId(['lootbonus', 'lb'], 'lb');
|
||||||
|
maxId(['xpbonus', 'xpb', 'xb'], 'xpb');
|
||||||
|
maxId(['stealing', 'esteal'], 'eSteal');
|
||||||
|
prop(['powderslots', 'powders', 'slots', 'sockets'], (i, ie) => i.slots || 0);
|
||||||
|
|
||||||
|
return props;
|
||||||
|
})();
|
||||||
|
|
||||||
|
// functions that can be called in query expressions
|
||||||
|
const itemQueryFuncs = {
|
||||||
|
max(args) {
|
||||||
|
if (args.length < 1) throw new Error('Not enough args to max()');
|
||||||
|
let runningMax = -Infinity;
|
||||||
|
for (let i = 0; i < args.length; i++) {
|
||||||
|
if (checkNum(args[i]) > runningMax) runningMax = args[i];
|
||||||
|
}
|
||||||
|
return runningMax;
|
||||||
|
},
|
||||||
|
min(args) {
|
||||||
|
if (args.length < 1) throw new Error('Not enough args to min()');
|
||||||
|
let runningMin = Infinity;
|
||||||
|
for (let i = 0; i < args.length; i++) {
|
||||||
|
if (checkNum(args[i]) < runningMin) runningMin = args[i];
|
||||||
|
}
|
||||||
|
return runningMin;
|
||||||
|
},
|
||||||
|
floor(args) {
|
||||||
|
if (args.length < 1) throw new Error('Not enough args to floor()');
|
||||||
|
return Math.floor(checkNum(args[0]));
|
||||||
|
},
|
||||||
|
ceil(args) {
|
||||||
|
if (args.length < 1) throw new Error('Not enough args to ceil()');
|
||||||
|
return Math.ceil(checkNum(args[0]));
|
||||||
|
},
|
||||||
|
round(args) {
|
||||||
|
if (args.length < 1) throw new Error('Not enough args to ceil()');
|
||||||
|
return Math.round(checkNum(args[0]));
|
||||||
|
},
|
||||||
|
sqrt(args) {
|
||||||
|
if (args.length < 1) throw new Error('Not enough args to ceil()');
|
||||||
|
return Math.sqrt(checkNum(args[0]));
|
||||||
|
},
|
||||||
|
abs(args) {
|
||||||
|
if (args.length < 1) throw new Error('Not enough args to ceil()');
|
||||||
|
return Math.abs(checkNum(args[0]));
|
||||||
|
},
|
||||||
|
contains(args) {
|
||||||
|
if (args.length < 2) throw new Error('Not enough args to contains()');
|
||||||
|
return checkStr(args[0]).toLowerCase().includes(checkStr(args[1]).toLowerCase());
|
||||||
|
},
|
||||||
|
atkspdmod(args) {
|
||||||
|
if (args.length < 1) throw new Error('Not enough args to atkSpdMod()');
|
||||||
|
switch (checkNum(args[0])) {
|
||||||
|
case 2: return 3.1;
|
||||||
|
case 1: return 2.5;
|
||||||
|
case 0: return 2.05;
|
||||||
|
case -1: return 1.5;
|
||||||
|
case -2: return 0.83;
|
||||||
|
}
|
||||||
|
if (args[0] <= -3) return 0.51;
|
||||||
|
if (args[0] >= 3) return 4.3;
|
||||||
|
throw new Error('Invalid argument to atkSpdMod()');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// the compiler itself
|
||||||
|
const compileQueryExpr = (function() {
|
||||||
|
// tokenize an expression string
|
||||||
|
function tokenize(exprStr) {
|
||||||
|
exprStr = exprStr.trim();
|
||||||
|
const tokens = [];
|
||||||
|
let col = 0;
|
||||||
|
function pushSymbol(sym) {
|
||||||
|
tokens.push({ type: 'sym', sym });
|
||||||
|
col += sym.length;
|
||||||
|
}
|
||||||
|
while (col < exprStr.length) {
|
||||||
|
// parse fixed symbols, like operators and stuff
|
||||||
|
switch (exprStr[col]) {
|
||||||
|
case '(':
|
||||||
|
case ')':
|
||||||
|
case ',':
|
||||||
|
case '&':
|
||||||
|
case '|':
|
||||||
|
case '+':
|
||||||
|
case '-':
|
||||||
|
case '*':
|
||||||
|
case '/':
|
||||||
|
case '^':
|
||||||
|
case '=':
|
||||||
|
pushSymbol(exprStr[col]);
|
||||||
|
continue;
|
||||||
|
case '>':
|
||||||
|
pushSymbol(exprStr[col + 1] === '=' ? '>=' : '>');
|
||||||
|
continue;
|
||||||
|
case '<':
|
||||||
|
pushSymbol(exprStr[col + 1] === '=' ? '<=' : '<');
|
||||||
|
continue;
|
||||||
|
case '!':
|
||||||
|
pushSymbol(exprStr[col + 1] === '=' ? '!=' : '!');
|
||||||
|
continue;
|
||||||
|
case ' ': // ignore extra whitespace
|
||||||
|
++col;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// parse a numeric literal
|
||||||
|
let m;
|
||||||
|
if ((m = /^\d+(?:\.\d*)?/.exec(exprStr.substring(col))) !== null) {
|
||||||
|
tokens.push({ type: 'num', value: parseFloat(m[0]) });
|
||||||
|
col += m[0].length;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// parse a string literal
|
||||||
|
if ((m = /^"([^"]+)"/.exec(exprStr.substring(col))) !== null) { // with double-quotes
|
||||||
|
tokens.push({ type: 'str', value: m[1] });
|
||||||
|
col += m[0].length;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((m = /^'([^']+)'/.exec(exprStr.substring(col))) !== null) { // with single-quotes
|
||||||
|
tokens.push({ type: 'str', value: m[1] });
|
||||||
|
col += m[0].length;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// parse an identifier or boolean literal
|
||||||
|
if ((m = /^\w[\w\d+%]*/.exec(exprStr.substring(col))) !== null) {
|
||||||
|
switch (m[0]) {
|
||||||
|
case 'true':
|
||||||
|
tokens.push({ type: 'bool', value: true });
|
||||||
|
col += 4;
|
||||||
|
continue;
|
||||||
|
case 'false':
|
||||||
|
tokens.push({ type: 'bool', value: false });
|
||||||
|
col += 5;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tokens.push({ type: 'id', id: m[0] });
|
||||||
|
col += m[0].length;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// if we reach here without successfully parsing a token, it's an error
|
||||||
|
throw new Error(`Could not parse character "${exprStr[col]}" at position ${col}`);
|
||||||
|
}
|
||||||
|
tokens.push({ type: 'eof' });
|
||||||
|
return new TokenList(tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse tokens into an ast
|
||||||
|
function takeDisj(tokens) {
|
||||||
|
const left = takeConj(tokens);
|
||||||
|
if (tokens.here.type === 'sym' && tokens.here.sym === '|') {
|
||||||
|
tokens.advance();
|
||||||
|
const right = takeDisj(tokens);
|
||||||
|
return (i, ie) => checkBool(left(i, ie)) || checkBool(right(i, ie));
|
||||||
|
}
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
function takeConj(tokens) {
|
||||||
|
const left = takeCmpEq(tokens);
|
||||||
|
if (tokens.here.type === 'sym' && tokens.here.sym === '&') {
|
||||||
|
tokens.advance();
|
||||||
|
const right = takeConj(tokens);
|
||||||
|
return (i, ie) => checkBool(left(i, ie)) && checkBool(right(i, ie));
|
||||||
|
}
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
function takeCmpEq(tokens) {
|
||||||
|
const left = takeCmpRel(tokens);
|
||||||
|
if (tokens.here.type === 'sym') {
|
||||||
|
switch (tokens.here.sym) {
|
||||||
|
case '=': {
|
||||||
|
tokens.advance();
|
||||||
|
const right = takeCmpEq(tokens);
|
||||||
|
return (i, ie) => {
|
||||||
|
const a = left(i, ie), b = right(i, ie);
|
||||||
|
if (typeof a !== typeof b) return false;
|
||||||
|
switch (typeof a) {
|
||||||
|
case 'number':
|
||||||
|
return Math.abs(left(i, ie) - right(i, ie)) < 1e-4;
|
||||||
|
case 'boolean':
|
||||||
|
return a === b;
|
||||||
|
case 'string':
|
||||||
|
return a.toLowerCase() === b.toLowerCase();
|
||||||
|
}
|
||||||
|
throw new Error('???'); // wut
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case '!=': {
|
||||||
filter(item) {
|
tokens.advance();
|
||||||
return (this.id in item) && (item[this.id]);
|
const right = takeCmpEq(tokens);
|
||||||
|
return (i, ie) => {
|
||||||
|
const a = left(i, ie), b = right(i, ie);
|
||||||
|
if (typeof a !== typeof b) return false;
|
||||||
|
switch (typeof a) {
|
||||||
|
case 'number':
|
||||||
|
return Math.abs(left(i, ie) - right(i, ie)) >= 1e-4;
|
||||||
|
case 'boolean':
|
||||||
|
return a !== b;
|
||||||
|
case 'string':
|
||||||
|
return a.toLowerCase() !== b.toLowerCase();
|
||||||
}
|
}
|
||||||
}
|
throw new Error('???'); // wtf
|
||||||
queryTypeMap.set("stat", function(s) { return new IdQuery(s); } );
|
|
||||||
|
|
||||||
class IdMatchQuery {
|
|
||||||
constructor(id, value) {
|
|
||||||
this.id = id;
|
|
||||||
this.value = value;
|
|
||||||
this.compare = function(a, b) {
|
|
||||||
return 0;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
filter(item) {
|
|
||||||
return (this.id in item) && (item[this.id] == this.value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
class SumQuery {
|
function takeCmpRel(tokens) {
|
||||||
constructor(ids) {
|
const left = takeSum(tokens);
|
||||||
this.compare = function(a, b) {
|
if (tokens.here.type === 'sym') {
|
||||||
let balance = 0;
|
switch (tokens.here.sym) {
|
||||||
for (const id of ids) {
|
case '<=': {
|
||||||
if (a[id]) { balance -= a[id]; }
|
tokens.advance();
|
||||||
if (b[id]) { balance += b[id]; }
|
const right = takeCmpRel(tokens);
|
||||||
|
return (i, ie) => checkNum(left(i, ie)) <= checkNum(right(i, ie));
|
||||||
}
|
}
|
||||||
return balance;
|
case '<': {
|
||||||
|
tokens.advance();
|
||||||
|
const right = takeCmpRel(tokens);
|
||||||
|
return (i, ie) => checkNum(left(i, ie)) < checkNum(right(i, ie));
|
||||||
|
}
|
||||||
|
case '>': {
|
||||||
|
tokens.advance();
|
||||||
|
const right = takeCmpRel(tokens);
|
||||||
|
return (i, ie) => checkNum(left(i, ie)) > checkNum(right(i, ie));
|
||||||
|
}
|
||||||
|
case '>=': {
|
||||||
|
tokens.advance();
|
||||||
|
const right = takeCmpRel(tokens);
|
||||||
|
return (i, ie) => checkNum(left(i, ie)) >= checkNum(right(i, ie));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
function takeSum(tokens) {
|
||||||
|
const left = takeProd(tokens);
|
||||||
|
if (tokens.here.type === 'sym') {
|
||||||
|
switch (tokens.here.sym) {
|
||||||
|
case '+': {
|
||||||
|
tokens.advance();
|
||||||
|
const right = takeSum(tokens);
|
||||||
|
return (i, ie) => checkNum(left(i, ie)) + checkNum(right(i, ie));
|
||||||
|
}
|
||||||
|
case '-': {
|
||||||
|
tokens.advance();
|
||||||
|
const right = takeSum(tokens);
|
||||||
|
return (i, ie) => checkNum(left(i, ie)) - checkNum(right(i, ie));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
function takeProd(tokens) {
|
||||||
|
const left = takeExp(tokens);
|
||||||
|
if (tokens.here.type === 'sym') {
|
||||||
|
switch (tokens.here.sym) {
|
||||||
|
case '*': {
|
||||||
|
tokens.advance();
|
||||||
|
const right = takeProd(tokens);
|
||||||
|
return (i, ie) => checkNum(left(i, ie)) * checkNum(right(i, ie));
|
||||||
|
}
|
||||||
|
case '/': {
|
||||||
|
tokens.advance();
|
||||||
|
const right = takeProd(tokens);
|
||||||
|
return (i, ie) => checkNum(left(i, ie)) / checkNum(right(i, ie));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
function takeExp(tokens) {
|
||||||
|
const left = takeUnary(tokens);
|
||||||
|
if (tokens.here.type === 'sym' && tokens.here.sym === '^') {
|
||||||
|
tokens.advance();
|
||||||
|
const right = takeExp(tokens);
|
||||||
|
return (i, ie) => checkNum(left(i, ie)) ** checkNum(right(i, ie));
|
||||||
|
}
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
function takeUnary(tokens) {
|
||||||
|
if (tokens.here.type === 'sym') {
|
||||||
|
switch (tokens.here.sym) {
|
||||||
|
case '-': {
|
||||||
|
tokens.advance();
|
||||||
|
const operand = takeUnary(tokens);
|
||||||
|
return (i, ie) => -checkNum(operand(i, ie));
|
||||||
|
}
|
||||||
|
case '!': {
|
||||||
|
tokens.advance();
|
||||||
|
const operand = takeUnary(tokens);
|
||||||
|
return (i, ie) => !checkBool(operand(i, ie));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return takePrim(tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
function takePrim(tokens) {
|
||||||
|
switch (tokens.here.type) {
|
||||||
|
case 'num': {
|
||||||
|
const lit = tokens.here.value;
|
||||||
|
tokens.advance();
|
||||||
|
return (i, ie) => lit;
|
||||||
|
}
|
||||||
|
case 'bool': {
|
||||||
|
const lit = tokens.here.value;
|
||||||
|
tokens.advance();
|
||||||
|
return (i, ie) => lit;
|
||||||
|
}
|
||||||
|
case 'str': {
|
||||||
|
const lit = tokens.here.value;
|
||||||
|
tokens.advance();
|
||||||
|
console.log(lit);
|
||||||
|
return (i, ie) => lit;
|
||||||
|
}
|
||||||
|
case 'id':
|
||||||
|
const id = tokens.here.id;
|
||||||
|
tokens.advance();
|
||||||
|
if (tokens.here.type === 'sym' && tokens.here.sym === '(') { // it's a function call
|
||||||
|
tokens.advance();
|
||||||
|
const argExprs = [];
|
||||||
|
if (tokens.here.type !== 'sym' || tokens.here.sym !== ')') {
|
||||||
|
arg_iter: // collect arg expressions, if there are any
|
||||||
|
while (true) {
|
||||||
|
argExprs.push(takeDisj(tokens));
|
||||||
|
if (tokens.here.type === 'sym') {
|
||||||
|
switch (tokens.here.sym) {
|
||||||
|
case ')':
|
||||||
|
tokens.advance();
|
||||||
|
break arg_iter;
|
||||||
|
case ',':
|
||||||
|
tokens.advance();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error(`Expected "," or ")", but got ${JSON.stringify(tokens.here)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const func = itemQueryFuncs[id.toLowerCase()];
|
||||||
|
if (!func) throw new Error(`Unknown function: ${id}`);
|
||||||
|
return (i, ie) => {
|
||||||
|
const args = [];
|
||||||
|
for (let k = 0; k < argExprs.length; k++) args.push(argExprs[k](i, ie));
|
||||||
|
return func(args);
|
||||||
};
|
};
|
||||||
|
} else { // not a function call
|
||||||
|
const prop = itemQueryProps[id.toLowerCase()];
|
||||||
|
if (!prop) throw new Error(`Unknown property: ${id}`);
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
case 'sym':
|
||||||
|
if (tokens.here.sym === '(') {
|
||||||
|
tokens.advance();
|
||||||
|
const expr = takeDisj(tokens);
|
||||||
|
if (tokens.here.type !== 'sym' || tokens.here.sym !== ')') throw new Error('Bracket mismatch');
|
||||||
|
tokens.advance();
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
throw new Error(tokens.here.type === 'eof' ? 'Reached end of expression' : `Unexpected token: ${JSON.stringify(tokens.here)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
filter(item) {
|
// full compilation function, with extra safety for empty input strings
|
||||||
return true;
|
return function(exprStr) {
|
||||||
}
|
const tokens = tokenize(exprStr);
|
||||||
}
|
return tokens.tokens.length <= 1 ? null : takeDisj(tokens);
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
|
@ -3,3 +3,4 @@ Version 1: http://localhost:8000/#1_0690px0CE0QR0050050K40BR0Qk00001004fI
|
||||||
Version 2: http://localhost:8000/#2_2SG2SH2SI2SJ2SK0K22SM2SN05n000t210t0000000
|
Version 2: http://localhost:8000/#2_2SG2SH2SI2SJ2SK0K22SM2SN05n000t210t0000000
|
||||||
Version 3: https://localhost:8000/#3_0250px0uX0K50K20OK0OJ00A0Qe1z+m21001M1g0000100nZ6
|
Version 3: https://localhost:8000/#3_0250px0uX0K50K20OK0OJ00A0Qe1z+m21001M1g0000100nZ6
|
||||||
Version 3: https://localhost:8000/#3_0K60iv0CE0Qt0BK0BK0K40Jc0uG160V050o1L1g00001003C6
|
Version 3: https://localhost:8000/#3_0K60iv0CE0Qt0BK0BK0K40Jc0uG160V050o1L1g00001003C6
|
||||||
|
Version 4: https://localhost:8000/#4_-1+W+W+W+W+W+W9g91-1+W+W+W+W+W+W9d91-1+W+W+W+W+W+W9i9--1+W+W+W+W+W+W9a91-1+W+W+W+W+W+W9m91-1+W+W+W+W+W+W9m91-1+W+W+W+W+W+W9c91-1+W+W+W+W+W+W9n91-1+W+W+W+W+W+W9q9100000000001g000010036C
|
||||||
|
|
Loading…
Reference in a new issue