Fix fatal error with not setting display name on all ingreds

This commit is contained in:
b 2021-03-04 06:47:08 -08:00
parent 3eff324660
commit cf8ef62a3e
2 changed files with 21 additions and 10 deletions

View file

@ -9,7 +9,7 @@ console.log(ing_url_tag);
const ING_BUILD_VERSION = "6.9.23"; const ING_BUILD_VERSION = "6.9.24";
/* /*
* END testing section * END testing section
*/ */
@ -113,6 +113,7 @@ function init() {
console.log(ings); console.log(ings);
console.log("all recipes"); console.log("all recipes");
console.log(recipes); console.log(recipes);
console.log(ingMap);
/*console.log(ingList); /*console.log(ingList);
console.log(recipeList); console.log(recipeList);
console.log(ingIDMap); console.log(ingIDMap);
@ -193,6 +194,7 @@ function calculateCraft() {
} }
let ingreds = []; let ingreds = [];
for (i = 1; i < 7; i++) { for (i = 1; i < 7; i++) {
console.log(getValue("ing-choice-"+i));
getValue("ing-choice-" + i) === "" ? ingreds.push(expandIngredient(ingMap.get("No Ingredient"))) : ingreds.push(expandIngredient(ingMap.get(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.
@ -344,12 +346,12 @@ function shareRecipe(){
let name = player_craft.recipe.get("name").split("-"); let name = player_craft.recipe.get("name").split("-");
copyString += " > " + name[0] + " " + "Lv. " + name[1] + "-" + name[2] + " (" + player_craft.mat_tiers[0] + "\u272B, " + player_craft.mat_tiers[1] + "\u272B)\n"; copyString += " > " + name[0] + " " + "Lv. " + name[1] + "-" + name[2] + " (" + player_craft.mat_tiers[0] + "\u272B, " + player_craft.mat_tiers[1] + "\u272B)\n";
let names = [ let names = [
player_craft.ingreds[0].get("name"), player_craft.ingreds[0].get("displayName"),
player_craft.ingreds[1].get("name"), player_craft.ingreds[1].get("displayName"),
player_craft.ingreds[2].get("name"), player_craft.ingreds[2].get("displayName"),
player_craft.ingreds[3].get("name"), player_craft.ingreds[3].get("displayName"),
player_craft.ingreds[4].get("name"), player_craft.ingreds[4].get("displayName"),
player_craft.ingreds[5].get("name") player_craft.ingreds[5].get("displayName")
]; ];
//fancy justify code that doesn't work properly b/c most font isn't monospaced //fancy justify code that doesn't work properly b/c most font isn't monospaced
let buffer1 = Math.max(names[0].length,names[2].length,names[4].length); let buffer1 = Math.max(names[0].length,names[2].length,names[4].length);

View file

@ -1,4 +1,4 @@
const ING_DB_VERSION = 4; const ING_DB_VERSION = 5;
// @See https://github.com/mdn/learning-area/blob/master/javascript/apis/client-side-storage/indexeddb/video-store/index.js // @See https://github.com/mdn/learning-area/blob/master/javascript/apis/client-side-storage/indexeddb/video-store/index.js
@ -35,6 +35,14 @@ async function ing_load_local(init_func) {
idb.close(); idb.close();
} }
function clean_ing(ing) {
if (ing.remapID === undefined) {
if (ing.displayName === undefined) {
ing.displayName = ing.name;
}
}
}
/* /*
* Load item set from remote DB (aka a big json file). Calls init() on success. * Load item set from remote DB (aka a big json file). Calls init() on success.
*/ */
@ -65,8 +73,9 @@ async function load_ings(init_func) {
let add_promises = []; let add_promises = [];
let add_tx2 = idb.transaction(['ing_db'], 'readwrite'); let add_tx2 = idb.transaction(['ing_db'], 'readwrite');
let ings_store = add_tx2.objectStore('ing_db'); let ings_store = add_tx2.objectStore('ing_db');
for (const ing in ings) { for (const id in ings) {
add_promises.push(ings_store.add(ings[ing], ing)); clean_ing(ings[id]);
add_promises.push(ings_store.add(ings[id], id));
} }
let add_tx3 = idb.transaction(['recipe_db'], 'readwrite'); let add_tx3 = idb.transaction(['recipe_db'], 'readwrite');
let recipes_store = add_tx3.objectStore('recipe_db'); let recipes_store = add_tx3.objectStore('recipe_db');