From 3a75db643de070d6a6c5ad2c247fd658caa4561b Mon Sep 17 00:00:00 2001 From: ferricles Date: Mon, 16 May 2022 14:37:49 -0700 Subject: [PATCH] crafted recipe choice image updates upon recipe type input change --- js/crafter.js | 12 ++++++++++++ js/sq2display_constants.js | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/js/crafter.js b/js/crafter.js index 64a0b4a..e48c598 100644 --- a/js/crafter.js +++ b/js/crafter.js @@ -48,6 +48,7 @@ function init_crafter() { document.getElementById("level-choice").addEventListener("change", (event) => { updateMaterials(); }); + document.getElementById("recipe-choice").setAttribute("oninput", "updateCraftedImage()"); populateFields(); decodeCraft(ing_url_tag); @@ -188,6 +189,7 @@ function decodeCraft(ing_url_tag) { //console.log(Base64.toInt(tag.substring(12,14))); recipesName = recipe.split("-"); setValue("recipe-choice",recipesName[0]); + updateCraftedImage(); setValue("level-choice",recipesName[1]+"-"+recipesName[2]); tierNum = Base64.toInt(tag.substring(14,15)); mat_tiers = []; @@ -297,6 +299,16 @@ function toggleMaterial(buttonId) { } } +/* Updates the crafted icon. +*/ +function updateCraftedImage() { + let input = document.getElementById("recipe-choice"); + if (item_types.includes(input.value)) { + document.getElementById("recipe-img").src = "../media/items/" + (newIcons ? "new/":"old/") + "generic-" + input.value.toLowerCase() + ".png"; + } + +} + /* Reset all fields */ function resetFields() { diff --git a/js/sq2display_constants.js b/js/sq2display_constants.js index e043076..5152c30 100644 --- a/js/sq2display_constants.js +++ b/js/sq2display_constants.js @@ -46,6 +46,24 @@ let elem_colors = [ "#FFFFFF" ] +let item_types = [ + "Helmet", + "Chestplate", + "Leggings", + "Boots", + "Ring", + "Bracelet", + "Necklace", + "Dagger", + "Spear", + "Wand", + "Relik", + "Bow", + "Potion", + "Scroll", + "Food" +] + /* * Display commands */