Remove common (we already have build_utils), edit instances of expandItems

This commit is contained in:
hppeng 2022-05-22 00:14:20 -07:00
parent 1e863fd015
commit 0234101262
6 changed files with 160 additions and 144 deletions

View file

@ -76,3 +76,122 @@ for (const [k, v] of translations) {
reversetranslations.set(v, k); reversetranslations.set(v, k);
} }
let nonRolledIDs = [
"name",
"lore",
"displayName",
"tier",
"set",
"slots",
"type",
"material",
"drop",
"quest",
"restrict",
"nDam", "fDam", "wDam", "aDam", "tDam", "eDam",
"atkSpd",
"hp",
"fDef", "wDef", "aDef", "tDef", "eDef",
"lvl",
"classReq",
"strReq", "dexReq", "intReq", "defReq", "agiReq",
"str", "dex", "int", "agi", "def",
"fixID",
"category",
"id",
"skillpoints",
"reqs",
"nDam_", "fDam_", "wDam_", "aDam_", "tDam_", "eDam_",
"majorIds"];
let rolledIDs = [
"hprPct",
"mr",
"sdPct",
"mdPct",
"ls",
"ms",
"xpb",
"lb",
"ref",
"thorns",
"expd",
"spd",
"atkTier",
"poison",
"hpBonus",
"spRegen",
"eSteal",
"hprRaw",
"sdRaw",
"mdRaw",
"fDamPct", "wDamPct", "aDamPct", "tDamPct", "eDamPct",
"fDefPct", "wDefPct", "aDefPct", "tDefPct", "eDefPct",
"spPct1", "spRaw1",
"spPct2", "spRaw2",
"spPct3", "spRaw3",
"spPct4", "spRaw4",
"rainbowRaw",
"sprint",
"sprintReg",
"jh",
"lq",
"gXp",
"gSpd"
];
/**
* Take an item with id list and turn it into a set of minrolls and maxrolls.
*/
function expandItem(item) {
let minRolls = new Map();
let maxRolls = new Map();
let expandedItem = new Map();
if (item.fixID) { //The item has fixed IDs.
expandedItem.set("fixID",true);
for (const id of rolledIDs) { //all rolled IDs are numerical
let val = (item[id] || 0);
minRolls.set(id,val);
maxRolls.set(id,val);
}
} else { //The item does not have fixed IDs.
for (const id of rolledIDs) {
let val = (item[id] || 0);
if (val > 0) { // positive rolled IDs
if (reversedIDs.includes(id)) {
maxRolls.set(id,idRound(val*0.3));
minRolls.set(id,idRound(val*1.3));
} else {
maxRolls.set(id,idRound(val*1.3));
minRolls.set(id,idRound(val*0.3));
}
} else if (val < 0) { //negative rolled IDs
if (reversedIDs.includes(id)) {
maxRolls.set(id,idRound(val*1.3));
minRolls.set(id,idRound(val*0.7));
}
else {
maxRolls.set(id,idRound(val*0.7));
minRolls.set(id,idRound(val*1.3));
}
}
else { // if val == 0
// NOTE: DO NOT remove this case! idRound behavior does not round to 0!
maxRolls.set(id,0);
minRolls.set(id,0);
}
}
}
for (const id of nonRolledIDs) {
expandedItem.set(id,item[id]);
}
expandedItem.set("minRolls",minRolls);
expandedItem.set("maxRolls",maxRolls);
expandedItem.set("powders", powders);
return expandedItem;
}
class Item {
constructor(item_obj) {
this.statMap = expandItem(item_obj);
}
}

View file

@ -1,123 +0,0 @@
let nonRolledIDs = [
"name",
"lore",
"displayName",
"tier",
"set",
"slots",
"type",
"material",
"drop",
"quest",
"restrict",
"nDam", "fDam", "wDam", "aDam", "tDam", "eDam",
"atkSpd",
"hp",
"fDef", "wDef", "aDef", "tDef", "eDef",
"lvl",
"classReq",
"strReq", "dexReq", "intReq", "defReq", "agiReq",
"str", "dex", "int", "agi", "def",
"fixID",
"category",
"id",
"skillpoints",
"reqs",
"nDam_", "fDam_", "wDam_", "aDam_", "tDam_", "eDam_",
"majorIds"];
let rolledIDs = [
"hprPct",
"mr",
"sdPct",
"mdPct",
"ls",
"ms",
"xpb",
"lb",
"ref",
"thorns",
"expd",
"spd",
"atkTier",
"poison",
"hpBonus",
"spRegen",
"eSteal",
"hprRaw",
"sdRaw",
"mdRaw",
"fDamPct", "wDamPct", "aDamPct", "tDamPct", "eDamPct",
"fDefPct", "wDefPct", "aDefPct", "tDefPct", "eDefPct",
"spPct1", "spRaw1",
"spPct2", "spRaw2",
"spPct3", "spRaw3",
"spPct4", "spRaw4",
"rainbowRaw",
"sprint",
"sprintReg",
"jh",
"lq",
"gXp",
"gSpd"
];
/**
* Take an item with id list and turn it into a set of minrolls and maxrolls.
*/
function expandItem(item) {
let minRolls = new Map();
let maxRolls = new Map();
let expandedItem = new Map();
if (item.fixID) { //The item has fixed IDs.
expandedItem.set("fixID",true);
for (const id of rolledIDs) { //all rolled IDs are numerical
let val = (item[id] || 0);
minRolls.set(id,val);
maxRolls.set(id,val);
}
} else { //The item does not have fixed IDs.
for (const id of rolledIDs) {
let val = (item[id] || 0);
if (val > 0) { // positive rolled IDs
if (reversedIDs.includes(id)) {
maxRolls.set(id,idRound(val*0.3));
minRolls.set(id,idRound(val*1.3));
} else {
maxRolls.set(id,idRound(val*1.3));
minRolls.set(id,idRound(val*0.3));
}
} else if (val < 0) { //negative rolled IDs
if (reversedIDs.includes(id)) {
maxRolls.set(id,idRound(val*1.3));
minRolls.set(id,idRound(val*0.7));
}
else {
maxRolls.set(id,idRound(val*0.7));
minRolls.set(id,idRound(val*1.3));
}
}
else { // if val == 0
// NOTE: DO NOT remove this case! idRound behavior does not round to 0!
maxRolls.set(id,0);
minRolls.set(id,0);
}
}
}
for (const id of nonRolledIDs) {
expandedItem.set(id,item[id]);
}
expandedItem.set("minRolls",minRolls);
expandedItem.set("maxRolls",maxRolls);
expandedItem.set("powders", powders);
return expandedItem;
}
class Item {
constructor(item_obj) {
this.statMap = ; //can use the statMap as an expanded Item
this.atkSpd = attackSpeed;
this.hash = "CR-" + hash;
this.initCraftStats();
this.statMap.set("hash", this.hash);
}
}

View file

@ -1,7 +1,7 @@
let _ALL_NODES = new Map(); let _ALL_NODES = new Map();
class ComputeNode { class ComputeNode {
/*** /**
* Make a generic compute node. * Make a generic compute node.
* Adds the node to the global map of nodenames to nodes (for calling from html listeners). * Adds the node to the global map of nodenames to nodes (for calling from html listeners).
* *
@ -21,7 +21,7 @@ class ComputeNode {
this.fail_cb = false; // Set to true to force updates even if parent failed. this.fail_cb = false; // Set to true to force updates even if parent failed.
} }
/*** /**
* Request update of this compute node. Pushes updates to children. * Request update of this compute node. Pushes updates to children.
*/ */
update(timestamp) { update(timestamp) {
@ -42,14 +42,14 @@ class ComputeNode {
} }
} }
/*** /**
* Get value of this compute node. Can't trigger update cascades (push based update, not pull based.) * Get value of this compute node. Can't trigger update cascades (push based update, not pull based.)
*/ */
get_value() { get_value() {
return this.value return this.value
} }
/*** /**
* Abstract method for computing something. Return value is set into this.value * Abstract method for computing something. Return value is set into this.value
*/ */
compute_func(input_map) { compute_func(input_map) {
@ -62,7 +62,7 @@ class ComputeNode {
} }
} }
/*** /**
* Schedule a ComputeNode to be updated. * Schedule a ComputeNode to be updated.
* *
* @param node_name : ComputeNode name to schedule an update for. * @param node_name : ComputeNode name to schedule an update for.
@ -79,11 +79,11 @@ function calcSchedule(node_name) {
}, 500); }, 500);
} }
/*** /**
* Node for getting an item's stats from an item input field. * Node for getting an item's stats from an item input field.
*/ */
class ItemStats extends ComputeNode { class ItemInputNode extends ComputeNode {
/*** /**
* Make an item stat pulling compute node. * Make an item stat pulling compute node.
* *
* @param name: Name of this node. * @param name: Name of this node.
@ -94,7 +94,7 @@ class ItemStats extends ComputeNode {
super(name); super(name);
this.input_field.setAttribute("onInput", "calcSchedule('"+name+"');"); this.input_field.setAttribute("onInput", "calcSchedule('"+name+"');");
this.input_field = item_input_field; this.input_field = item_input_field;
this.none_item = none_item; this.none_item = expandItem(none_item);
} }
compute_func(input_map) { compute_func(input_map) {
@ -114,23 +114,23 @@ class ItemStats extends ComputeNode {
item = getCraftFromHash(item_text); item = getCraftFromHash(item_text);
} }
else if (itemMap.has(item_text)) { else if (itemMap.has(item_text)) {
item = itemMap.get(item_text); item = Item(itemMap.get(item_text));
} }
else if (tomeMap.has(item_text)) { else if (tomeMap.has(item_text)) {
item = tomeMap.get(item_text); item = Item(tomeMap.get(item_text));
} }
if (!item || item.) { if (!item || item.statMap.get('type') !== this.none_item.statMap.get('type')) {
return null; return null;
} }
return item; return item;
} }
} }
/*** /**
* Node for updating item input fields from parsed items. * Node for updating item input fields from parsed items.
*/ */
class ItemInputDisplay extends ComputeNode { class ItemInputDisplayNode extends ComputeNode {
constructor(name, item_input_field, item_image) { constructor(name, item_input_field, item_image) {
super(name); super(name);
@ -140,10 +140,7 @@ class ItemInputDisplay extends ComputeNode {
} }
compute_func(input_map) { compute_func(input_map) {
if (input_map.size !== 1) { if (input_map.size !== 1) { throw "ItemInputDisplayNode accepts exactly one input (item)"; }
throw "ItemInputDisplay accepts exactly one input (item)";
}
const [item] = input_map.values(); // Extract values, pattern match it into size one list and bind to first element const [item] = input_map.values(); // Extract values, pattern match it into size one list and bind to first element
this.input_field.classList.remove("text-light", "is-invalid", 'Normal', 'Unique', 'Rare', 'Legendary', 'Fabled', 'Mythic', 'Set', 'Crafted', 'Custom'); this.input_field.classList.remove("text-light", "is-invalid", 'Normal', 'Unique', 'Rare', 'Legendary', 'Fabled', 'Mythic', 'Set', 'Crafted', 'Custom');
@ -154,5 +151,28 @@ class ItemInputDisplay extends ComputeNode {
this.input_field.classList.add("is-invalid"); this.input_field.classList.add("is-invalid");
return null; return null;
} }
const tier = item.statMap.get('tier');
this.input_field.classList.add(tier);
this.image.classList.add(tier + "-shadow");
}
}
/**
* Change the weapon to match correct type.
*/
class WeaponDisplayNode extends ComputeNode {
constructor(name, image_field) {
super(name);
this.image = image_field;
}
compute_func(input_map) {
if (input_map.size !== 1) { throw "WeaponDisplayNode accepts exactly one input (item)"; }
const [item] = input_map.values(); // Extract values, pattern match it into size one list and bind to first element
const type = item.statMap.get('type');
this.image_field.setAttribute('src', '../media/items/new/generic-'+type+'.png');
} }
} }

View file

@ -369,7 +369,7 @@ function useBaseItem(elem) {
//Check items db. //Check items db.
for (const [name,itemObj] of itemMap) { for (const [name,itemObj] of itemMap) {
if (itemName === name) { if (itemName === name) {
baseItem = expandItem(itemObj, []); baseItem = expandItem(itemObj);
break; break;
} }
} }

View file

@ -239,7 +239,7 @@ function init_items2() {
const itemListFooter = document.getElementById('item-list-footer'); const itemListFooter = document.getElementById('item-list-footer');
// compile the search db from the item db // compile the search db from the item db
const searchDb = items.filter(i => !i.remapID).map(i => [i, expandItem(i, [])]); const searchDb = items.filter(i => !i.remapID).map(i => [i, expandItem(i)]);
// init item list elements // init item list elements
const ITEM_LIST_SIZE = 64; const ITEM_LIST_SIZE = 64;

View file

@ -250,7 +250,7 @@ function resetItemSearch() {
} }
function init_items() { function init_items() {
items_expanded = items.filter( (i) => !("remapID" in i) ).map( (i) => expandItem(i, []) ); items_expanded = items.filter( (i) => !("remapID" in i) ).map( (i) => expandItem(i) );
} }
load_init(init_items); load_init(init_items);