Revert Map changes for big maps... use only for small object-like things

This commit is contained in:
hppeng 2022-07-17 16:34:54 -05:00
parent ae1146aec1
commit 3e9414ef1e
12 changed files with 76 additions and 67 deletions

View file

@ -1,7 +1,7 @@
let player_build; let player_build;
let build_powders; let build_powders;
function getItemNameFromID(id) { return idMap[id]; } function getItemNameFromID(id) { return idMap.get(id); }
function getTomeNameFromID(id) { return tomeIDMap.get(id); } function getTomeNameFromID(id) { return tomeIDMap.get(id); }
function parsePowdering(powder_info) { function parsePowdering(powder_info) {

View file

@ -164,8 +164,8 @@ function init_autocomplete() {
let item_arr = []; let item_arr = [];
if (eq == 'weapon') { if (eq == 'weapon') {
for (const weaponType of weapon_keys) { for (const weaponType of weapon_keys) {
for (const weapon of itemLists[weaponType]) { for (const weapon of itemLists.get(weaponType)) {
let item_obj = itemMap[weapon]; let item_obj = itemMap.get(weapon);
if (item_obj["restrict"] && item_obj["restrict"] === "DEPRECATED") { if (item_obj["restrict"] && item_obj["restrict"] === "DEPRECATED") {
continue; continue;
} }
@ -176,8 +176,8 @@ function init_autocomplete() {
} }
} }
} else { } else {
for (const item of itemLists[eq.replace(/[0-9]/g, '')]) { for (const item of itemLists.get(eq.replace(/[0-9]/g, ''))) {
let item_obj = itemMap[item]; let item_obj = itemMap.get(item);
if (item_obj["restrict"] && item_obj["restrict"] === "DEPRECATED") { if (item_obj["restrict"] && item_obj["restrict"] === "DEPRECATED") {
continue; continue;
} }
@ -220,7 +220,7 @@ function init_autocomplete() {
class: "scaled-font search-item", class: "scaled-font search-item",
selected: "dark-5", selected: "dark-5",
element: (item, data) => { element: (item, data) => {
item.classList.add(itemMap[data.value].tier); item.classList.add(itemMap.get(data.value).tier);
}, },
}, },
events: { events: {
@ -390,15 +390,7 @@ window.onerror = function(message, source, lineno, colno, error) {
}; };
(async function() { (async function() {
const start = Date.now();
let load_promises = [ load_init(), load_ing_init(), load_tome_init() ]; let load_promises = [ load_init(), load_ing_init(), load_tome_init() ];
await Promise.all(load_promises); await Promise.all(load_promises);
const codestart = Date.now();
init(); init();
const end = Date.now();
const calc_str = `builder calculation took ${(end-codestart)/ 1000} seconds.`;
const total_str = `builder total took ${(end-start)/ 1000} seconds.`;
console.log(calc_str);
console.log(total_str);
document.getElementById('stack-box').textContent += calc_str + total_str;
})(); })();

View file

@ -154,7 +154,7 @@ class ItemInputNode extends InputNode {
let item; let item;
if (item_text.slice(0, 3) == "CI-") { item = getCustomFromHash(item_text); } if (item_text.slice(0, 3) == "CI-") { item = getCustomFromHash(item_text); }
else if (item_text.slice(0, 3) == "CR-") { item = getCraftFromHash(item_text); } else if (item_text.slice(0, 3) == "CR-") { item = getCraftFromHash(item_text); }
else if (itemMap[item_text]) { item = new Item(itemMap[item_text]); } else if (itemMap.has(item_text)) { item = new Item(itemMap.get(item_text)); }
else if (tomeMap.has(item_text)) { item = new Item(tomeMap.get(item_text)); } else if (tomeMap.has(item_text)) { item = new Item(tomeMap.get(item_text)); }
if (item) { if (item) {
@ -1143,6 +1143,5 @@ function builder_graph_init() {
// this will propagate the update to the `stat_agg_node`, and then to damage calc // this will propagate the update to the `stat_agg_node`, and then to damage calc
console.log("Set up graph"); console.log("Set up graph");
INPUT_UPDATE = true;
} }

View file

@ -174,24 +174,20 @@ class ValueCheckComputeNode extends ComputeNode {
} }
let INPUT_UPDATE = false;
/** /**
* Schedule a ComputeNode to be updated. * Schedule a ComputeNode to be updated.
* *
* @param node : ComputeNode to schedule an update for. * @param node : ComputeNode to schedule an update for.
*/ */
function calcSchedule(node, timeout) { function calcSchedule(node, timeout) {
if (INPUT_UPDATE) { if (node.update_task !== null) {
if (node.update_task !== null) { clearTimeout(node.update_task);
clearTimeout(node.update_task);
}
node.mark_dirty();
node.update_task = setTimeout(function() {
node.update();
node.update_task = null;
}, timeout);
} }
node.mark_dirty();
node.update_task = setTimeout(function() {
node.update();
node.update_task = null;
}, timeout);
} }
class PrintNode extends ComputeNode { class PrintNode extends ComputeNode {

View file

@ -34,7 +34,7 @@ function getCraftFromHash(hash) {
if (version === "1") { if (version === "1") {
let ingreds = []; let ingreds = [];
for (let i = 0; i < 6; i ++ ) { for (let i = 0; i < 6; i ++ ) {
ingreds.push( expandIngredient(ingMap[ingIDMap[Base64.toInt(name.substring(2*i,2*i+2))]]) ); ingreds.push( expandIngredient(ingMap.get(ingIDMap.get(Base64.toInt(name.substring(2*i,2*i+2))))) );
} }
let recipe = expandRecipe(recipeMap.get(recipeIDMap.get(Base64.toInt(name.substring(12,14))))); let recipe = expandRecipe(recipeMap.get(recipeIDMap.get(Base64.toInt(name.substring(12,14)))));

View file

@ -32,6 +32,15 @@ let player_craft;
function init_crafter() { function init_crafter() {
//no ing //no ing
console.log("all ingredients");
console.log(ingMap);
console.log("all recipes");
console.log(recipeMap);
/*console.log(ingList);
console.log(recipeList);
console.log(ingIDMap);
console.log(recipeIDMap);*/
try { try {
document.getElementById("recipe-choice").addEventListener("change", (event) => { document.getElementById("recipe-choice").addEventListener("change", (event) => {
updateMaterials(); updateMaterials();
@ -140,7 +149,7 @@ function calculateCraft() {
for (i = 1; i < 7; i++) { for (i = 1; i < 7; i++) {
console.log("ing-choice-"+i); console.log("ing-choice-"+i);
// console.log(getValue("ing-choice-"+i)); // console.log(getValue("ing-choice-"+i));
getValue("ing-choice-" + i) === "" ? ingreds.push(expandIngredient(ingMap["No Ingredient"])) : ingreds.push(expandIngredient(ingMap[getValue("ing-choice-" + i)])); getValue("ing-choice-" + i) === "" ? ingreds.push(expandIngredient(ingMap.get("No Ingredient"))) : ingreds.push(expandIngredient(ingMap.get(getValue("ing-choice-" + i))));
} }
let atkSpd = "NORMAL"; //default attack speed will be normal. let atkSpd = "NORMAL"; //default attack speed will be normal.
for (const b of ["slow-atk-button", "normal-atk-button", "fast-atk-button"]) { for (const b of ["slow-atk-button", "normal-atk-button", "fast-atk-button"]) {
@ -205,7 +214,7 @@ function decodeCraft(ing_url_tag) {
if (version === "1") { if (version === "1") {
ingreds = []; ingreds = [];
for (let i = 0; i < 6; i ++ ) { for (let i = 0; i < 6; i ++ ) {
setValue("ing-choice-"+(i+1), ingIDMap[Base64.toInt(tag.substring(2*i,2*i+2))]); setValue("ing-choice-"+(i+1), ingIDMap.get(Base64.toInt(tag.substring(2*i,2*i+2))));
//console.log(Base64.toInt(tag.substring(2*i,2*i+2))); //console.log(Base64.toInt(tag.substring(2*i,2*i+2)));
} }
recipe = recipeIDMap.get(Base64.toInt(tag.substring(12,14))); recipe = recipeIDMap.get(Base64.toInt(tag.substring(12,14)));

View file

@ -331,7 +331,7 @@ function populateFields() {
class_list.appendChild(el); class_list.appendChild(el);
} }
let item_list = document.getElementById("base-list"); let item_list = document.getElementById("base-list");
for (const name of Object.keys(itemMap)) { for (const name of itemMap.keys()) {
let el = document.createElement("option"); let el = document.createElement("option");
el.value = name; el.value = name;
item_list.appendChild(el); item_list.appendChild(el);
@ -368,7 +368,7 @@ function useBaseItem(elem) {
let baseItem; let baseItem;
//Check items db. //Check items db.
for (const [name,itemObj] of Object.entries(itemMap)) { for (const [name,itemObj] of itemMap) {
if (itemName === name) { if (itemName === name) {
baseItem = expandItem(itemObj); baseItem = expandItem(itemObj);
break; break;

View file

@ -1871,18 +1871,18 @@ function displayIDProbabilities(parent_id, item, amp) {
if (amp != 0) {toggleButton("cork_amp_" + amp)} if (amp != 0) {toggleButton("cork_amp_" + amp)}
let item_name = item.get("displayName"); let item_name = item.get("displayName");
console.log(itemMap[item_name]) console.log(itemMap.get(item_name))
let table_elem = document.createElement("table"); let table_elem = document.createElement("table");
parent_elem.appendChild(table_elem); parent_elem.appendChild(table_elem);
for (const [id,val] of Object.entries(itemMap[item_name])) { for (const [id,val] of Object.entries(itemMap.get(item_name))) {
if (rolledIDs.includes(id)) { if (rolledIDs.includes(id)) {
if (!item.get("maxRolls").get(id)) { continue; } if (!item.get("maxRolls").get(id)) { continue; }
let min = item.get("minRolls").get(id); let min = item.get("minRolls").get(id);
let max = item.get("maxRolls").get(id); let max = item.get("maxRolls").get(id);
//Apply corkian amps //Apply corkian amps
if (val > 0) { if (val > 0) {
let base = val; let base = itemMap.get(item_name)[id];
if (reversedIDs.includes(id)) {max = Math.max( Math.round((0.3 + 0.05*amp) * base), 1)} if (reversedIDs.includes(id)) {max = Math.max( Math.round((0.3 + 0.05*amp) * base), 1)}
else {min = Math.max( Math.round((0.3 + 0.05*amp) * base), 1)} else {min = Math.max( Math.round((0.3 + 0.05*amp) * base), 1)}
} }

View file

@ -17,15 +17,16 @@ let amp_state = 0; //the level of corkian map used for ID purposes. Default 0.
function init_itempage() { function init_itempage() {
//console.log(item_url_tag); //console.log(item_url_tag);
//displayExpandedItem(expandItem(itemMap.get(item_url_tag).statMap, []), "item-view");
try{ try{
item = expandItem(itemMap[item_url_tag.replaceAll("%20"," ")], []); item = expandItem(itemMap.get(item_url_tag.replaceAll("%20"," ")), []);
if (item.get('category') === 'weapon') { if (item.get('category') === 'weapon') {
item.set('powders', []); item.set('powders', []);
apply_weapon_powders(item); apply_weapon_powders(item);
} }
displaysq2ExpandedItem(item, "item-view"); displayExpandedItem(item, "item-view");
displaysq2AdditionalInfo("additional-info", item); displayAdditionalInfo("additional-info", item);
displaysq2IDCosts("identification-costs", item); displayIDCosts("identification-costs", item);
if (item.get("set") && sets[item.get("set")]) { if (item.get("set") && sets[item.get("set")]) {
displayAllSetBonuses("set-bonus-info",item.get("set")); displayAllSetBonuses("set-bonus-info",item.get("set"));
} }

View file

@ -7,15 +7,10 @@ let load_complete = false;
let load_in_progress = false; let load_in_progress = false;
let items; let items;
let sets = new Map(); let sets = new Map();
let itemMap = {}; let itemMap;
let idMap = {}; let idMap;
let redirectMap; let redirectMap;
let itemLists = {}; let itemLists = new Map();
// List of 'raw' "none" items (No Helmet, etc), in order helmet, chestplate... ring1, ring2, brace, neck, weapon.
for (const it of itemTypes) {
itemLists[it] = [];
}
/* /*
* Load item set from local DB. Calls init() on success. * Load item set from local DB. Calls init() on success.
*/ */
@ -194,6 +189,11 @@ async function load_init() {
}); });
} }
// List of 'raw' "none" items (No Helmet, etc), in order helmet, chestplate... ring1, ring2, brace, neck, weapon.
for (const it of itemTypes) {
itemLists.set(it, []);
}
let none_items = [ let none_items = [
["armor", "helmet", "No Helmet"], ["armor", "helmet", "No Helmet"],
["armor", "chestplate", "No Chestplate"], ["armor", "chestplate", "No Chestplate"],
@ -232,15 +232,27 @@ for (let i = 0; i < none_items.length; i++) {
} }
function init_maps() { function init_maps() {
for (const item of items) { //warp
itemLists[item.type].push(item.displayName); itemMap = new Map();
itemMap[item.displayName] = item; /* Mapping from item names to set names. */
idMap[item.id] = item.displayName; idMap = new Map();
} redirectMap = new Map();
for (const item of none_items) {
itemLists[item.type].push(item.displayName);
itemMap[item.displayName] = item;
idMap[item.id] = "";
}
items = items.concat(none_items); items = items.concat(none_items);
//console.log(items);
for (const item of items) {
if (item.remapID === undefined) {
itemLists.get(item.type).push(item.displayName);
itemMap.set(item.displayName, item);
if (none_items.includes(item)) {
idMap.set(item.id, "");
}
else {
idMap.set(item.id, item.displayName);
}
}
else {
redirectMap.set(item.id, item.remapID);
}
}
console.log(itemMap);
} }

View file

@ -9,13 +9,13 @@ let iload_complete = false;
let ings; let ings;
let recipes; let recipes;
let ingMap = {}; let ingMap = new Map();
let ingList = []; let ingList = [];
let recipeMap; let recipeMap;
let recipeList = []; let recipeList = [];
let ingIDMap = {}; let ingIDMap = new Map();
let recipeIDMap; let recipeIDMap;
/* /*
@ -178,9 +178,9 @@ function init_ing_maps() {
posMods: {"left": 0, "right": 0, "above": 0, "under": 0, "touching": 0, "notTouching": 0}, posMods: {"left": 0, "right": 0, "above": 0, "under": 0, "touching": 0, "notTouching": 0},
id: 4000 id: 4000
}; };
ingMap[ing.displayName] = ing; ingMap.set(ing.displayName, ing);
ingList.push(ing.displayName); ingList.push(ing.displayName);
ingIDMap[ing.id] = ing.displayName; ingIDMap.set(ing.id, ing.displayName);
let numerals = new Map([[1, "I"], [2, "II"], [3, "III"], [4, "IV"], [5, "V"], [6, "VI"]]); let numerals = new Map([[1, "I"], [2, "II"], [3, "III"], [4, "IV"], [5, "V"], [6, "VI"]]);
for (let i = 0; i < 5; i ++) { for (let i = 0; i < 5; i ++) {
for (const powderIng of powderIngreds) { for (const powderIng of powderIngreds) {
@ -215,17 +215,17 @@ function init_ing_maps() {
ing.itemIDs["agiReq"] = powderIng["skpReq"]; ing.itemIDs["agiReq"] = powderIng["skpReq"];
break; break;
} }
ingMap[ing.displayName] = ing; ingMap.set(ing.displayName, ing);
ingList.push(ing.displayName); ingList.push(ing.displayName);
ingIDMap[ing.id] = ing.displayName; ingIDMap.set(ing.id, ing.displayName);
} }
} }
for (const ing of ings) { for (const ing of ings) {
ingMap[ing.displayName] = ing; ingMap.set(ing.displayName, ing);
ingList.push(ing.displayName); ingList.push(ing.displayName);
ingIDMap[ing.id] = ing.displayName; ingIDMap.set(ing.id, ing.displayName);
} }
for (const recipe of recipes) { for (const recipe of recipes) {
recipeMap.set(recipe.name, recipe); recipeMap.set(recipe.name, recipe);

View file

@ -1,5 +1,5 @@
function calculate_skillpoints(equipment, weapon) { function calculate_skillpoints(equipment, weapon) {
const start = Date.now(); const start = performance.now();
// Calculate equipment equipping order and required skillpoints. // Calculate equipment equipping order and required skillpoints.
// Return value: [equip_order, best_skillpoints, final_skillpoints, best_total]; // Return value: [equip_order, best_skillpoints, final_skillpoints, best_total];
let fixed = []; let fixed = [];
@ -211,7 +211,7 @@ function calculate_skillpoints(equipment, weapon) {
// best_skillpoints: manually assigned (before any gear) // best_skillpoints: manually assigned (before any gear)
// final_skillpoints: final totals (5 individ) // final_skillpoints: final totals (5 individ)
// best_total: total skillpoints assigned (number) // best_total: total skillpoints assigned (number)
const end = Date.now(); const end = performance.now();
const output_msg = `skillpoint calculation took ${(end-start)/ 1000} seconds.`; const output_msg = `skillpoint calculation took ${(end-start)/ 1000} seconds.`;
console.log(output_msg); console.log(output_msg);
document.getElementById('stack-box').textContent += output_msg; document.getElementById('stack-box').textContent += output_msg;