From b1c4a5e8ed3785aa17949a3b8a9f6ad60674927d Mon Sep 17 00:00:00 2001 From: ferricles Date: Fri, 13 May 2022 22:15:33 -0700 Subject: [PATCH 1/3] total armor powder special reset on weapon change --- builder/index.html | 10 +++--- js/sq2bs.js | 4 ++- js/sq2builder.js | 87 +++++++++++++++++++++++++++++----------------- 3 files changed, 64 insertions(+), 37 deletions(-) diff --git a/builder/index.html b/builder/index.html index 9a88c07..9602c27 100644 --- a/builder/index.html +++ b/builder/index.html @@ -507,7 +507,7 @@ Rage (Passive)
- +
@@ -551,7 +551,7 @@ Kill Streak (Passive)
- +
@@ -595,7 +595,7 @@ Concentration (Passive)
- +
@@ -639,7 +639,7 @@ Endurance (Passive)
- +
@@ -683,7 +683,7 @@ Dodge (Passive)
- +
diff --git a/js/sq2bs.js b/js/sq2bs.js index 1bba067..4fa4b49 100644 --- a/js/sq2bs.js +++ b/js/sq2bs.js @@ -24,6 +24,8 @@ document.addEventListener('DOMContentLoaded', function() { } document.querySelector("#level-choice").setAttribute("oninput", "calcBuildSchedule()") + document.querySelector("#weapon-choice").setAttribute("oninput", document.querySelector("#weapon-choice").getAttribute("oninput") + "resetArmorPowderSpecials();"); + let skp_fields = document.getElementsByClassName("skp-update"); @@ -41,7 +43,7 @@ document.addEventListener('DOMContentLoaded', function() { margin: { x: 20, y: 20, - } + } }); diff --git a/js/sq2builder.js b/js/sq2builder.js index 47ec620..05124f8 100644 --- a/js/sq2builder.js +++ b/js/sq2builder.js @@ -500,6 +500,7 @@ function updateStats() { player_build.assigned_skillpoints += delta_total; if(player_build){ updatePowderSpecials("skip", false); + updateArmorPowderSpecials("skip", false); updateBoosts("skip", false); } /* @@ -645,43 +646,67 @@ function updatePowderSpecials(buttonId, recalcStats) { /* Updates PASSIVE powder special boosts (armors) */ -function updateArmorPowderSpecials(elem_id) { - console.log(player_build); +function updateArmorPowderSpecials(elem_id, recalc_stats) { //we only update the powder special + external stats if the player has a build - if (player_build !== undefined) { - let wynn_elem = elem_id.split("_")[0]; //str, dex, int, def, agi + if (elem_id !== "skip") { + if (player_build !== undefined && player_build.weapon !== undefined && player_build.weapon.get("name") !== "No Weapon") { + let wynn_elem = elem_id.split("_")[0]; //str, dex, int, def, agi - //update the label associated w/ the slider - let elem = document.getElementById(elem_id); - let label = document.getElementById(elem_id + "_label"); - let prev_label = document.getElementById(elem_id + "_prev"); - - let value = elem.value; - - //for use in editing build stats - let prev_value = prev_label.value; - let value_diff = value - prev_value; - - //update the "previous" label - prev_label.value = value; - - label.textContent = label.textContent.split(":")[0] + ": " + value; - - let dmg_id = elem_chars[skp_names.indexOf(wynn_elem)] + "DamPct"; - let new_dmgboost = player_build.externalStats.get(dmg_id) + value_diff; - - //update build external stats - the second one is the relevant one for damage calc purposes - player_build.externalStats.set(dmg_id, new_dmgboost); - player_build.externalStats.get("damageBonus")[skp_names.indexOf(wynn_elem)] = new_dmgboost; + //update the label associated w/ the slider + let elem = document.getElementById(elem_id); + let label = document.getElementById(elem_id + "_label"); + let prev_label = document.getElementById(elem_id + "_prev"); + let value = elem.value; + + //for use in editing build stats + let prev_value = prev_label.value; + let value_diff = value - prev_value; + + //update the "previous" label + prev_label.value = value; + + label.textContent = label.textContent.split(":")[0] + ": " + value; + + let dmg_id = elem_chars[skp_names.indexOf(wynn_elem)] + "DamPct"; + let new_dmgboost = player_build.externalStats.get(dmg_id) + value_diff; + + //update build external stats - the second one is the relevant one for damage calc purposes + player_build.externalStats.set(dmg_id, new_dmgboost); + player_build.externalStats.get("damageBonus")[skp_names.indexOf(wynn_elem)] = new_dmgboost; + + //update the slider's graphics + let bg_color = elem_colors[skp_names.indexOf(wynn_elem)]; + let pct = Math.round(100 * value / powderSpecialStats[skp_names.indexOf(wynn_elem)].cap); + elem.style.background = `linear-gradient(to right, ${bg_color}, ${bg_color} ${pct}%, #AAAAAA ${pct}%, #AAAAAA 100%)`; + + } + } else { + for (let i = 0; i < skp_names.length; ++i) { + skp_name = skp_names[i]; + skp_char = elem_chars[i]; + build.externalStats.set(skp_char + "DamPct", build.externalStats.get(skp_char + "DamPct") - document.getElementById(skp_name+"_boost_armor").value); + build.externalStats.get("damageBonus")[i] -= document.getElementById(skp_name+"_boost_armor").value; + + } + } + + + if (recalc_stats) { //calc build stats and display powder special calculateBuildStats(); // displaysq2PowderSpecials(document.getElementById("powder-special-stats"), powderSpecials, player_build, true); - - //update the slider's graphics - let bg_color = elem_colors[skp_names.indexOf(wynn_elem)]; - let pct = Math.round(100 * value / powderSpecialStats[skp_names.indexOf(wynn_elem)].cap); - elem.style.background = `linear-gradient(to right, ${bg_color}, ${bg_color} ${pct}%, #AAAAAA ${pct}%, #AAAAAA 100%)`; + } + +} + +function resetArmorPowderSpecials() { + for (const skp of skp_names) { + document.getElementById(skp + "_boost_armor").value = 0; + document.getElementById(skp + "_boost_armor_prev").value = 0; + + document.getElementById(skp + "_boost_armor").style.background = `linear-gradient(to right, #AAAAAA, #AAAAAA 0%, #AAAAAA 100%)`; + } } From 2c8bc4785e77e3c99167f6d5dc1299abe5032c96 Mon Sep 17 00:00:00 2001 From: ferricles Date: Fri, 13 May 2022 22:24:28 -0700 Subject: [PATCH 2/3] hotfix --- js/sq2builder.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/js/sq2builder.js b/js/sq2builder.js index 05124f8..b67268a 100644 --- a/js/sq2builder.js +++ b/js/sq2builder.js @@ -682,12 +682,13 @@ function updateArmorPowderSpecials(elem_id, recalc_stats) { } } else { - for (let i = 0; i < skp_names.length; ++i) { - skp_name = skp_names[i]; - skp_char = elem_chars[i]; - build.externalStats.set(skp_char + "DamPct", build.externalStats.get(skp_char + "DamPct") - document.getElementById(skp_name+"_boost_armor").value); - build.externalStats.get("damageBonus")[i] -= document.getElementById(skp_name+"_boost_armor").value; - + if (player_build !== undefined) { + for (let i = 0; i < skp_names.length; ++i) { + skp_name = skp_names[i]; + skp_char = elem_chars[i]; + player_build.externalStats.set(skp_char + "DamPct", player_build.externalStats.get(skp_char + "DamPct") - document.getElementById(skp_name+"_boost_armor").value); + player_build.externalStats.get("damageBonus")[i] -= document.getElementById(skp_name+"_boost_armor").value; + } } } @@ -704,7 +705,6 @@ function resetArmorPowderSpecials() { for (const skp of skp_names) { document.getElementById(skp + "_boost_armor").value = 0; document.getElementById(skp + "_boost_armor_prev").value = 0; - document.getElementById(skp + "_boost_armor").style.background = `linear-gradient(to right, #AAAAAA, #AAAAAA 0%, #AAAAAA 100%)`; } From e465d5e5a35a1b707cebcb12fdbd4fbdf3339784 Mon Sep 17 00:00:00 2001 From: ferricles Date: Fri, 13 May 2022 22:35:31 -0700 Subject: [PATCH 3/3] small bug fix + resetting armor powder slider now resets label text --- js/sq2builder.js | 4 ++-- js/sq2display_constants.js | 8 ++++++++ js/utils.js | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/js/sq2builder.js b/js/sq2builder.js index b67268a..c5aa058 100644 --- a/js/sq2builder.js +++ b/js/sq2builder.js @@ -693,7 +693,7 @@ function updateArmorPowderSpecials(elem_id, recalc_stats) { } - if (recalc_stats) { + if (recalc_stats && player_build) { //calc build stats and display powder special calculateBuildStats(); // displaysq2PowderSpecials(document.getElementById("powder-special-stats"), powderSpecials, player_build, true); @@ -706,7 +706,7 @@ function resetArmorPowderSpecials() { document.getElementById(skp + "_boost_armor").value = 0; document.getElementById(skp + "_boost_armor_prev").value = 0; document.getElementById(skp + "_boost_armor").style.background = `linear-gradient(to right, #AAAAAA, #AAAAAA 0%, #AAAAAA 100%)`; - + document.getElementById(skp + "_boost_armor_label").textContent = `% ${capitalizeFirst(elem_names[skpnames.indexOf(skp)])} Damage Boost: 0` } } diff --git a/js/sq2display_constants.js b/js/sq2display_constants.js index aa45706..e043076 100644 --- a/js/sq2display_constants.js +++ b/js/sq2display_constants.js @@ -30,6 +30,14 @@ let elem_chars = [ 'a' ] +let elem_names = [ + 'earth', + 'thunder', + 'water', + 'fire', + 'air' +] + let elem_colors = [ "#00AA00", "#FFFF55", diff --git a/js/utils.js b/js/utils.js index 10bb4e6..b421fbe 100644 --- a/js/utils.js +++ b/js/utils.js @@ -409,3 +409,7 @@ async function hardReload() { location.reload(true); } + +function capitalizeFirst(str) { + return str.charAt(0).toUpperCase + str.slice(1); +} \ No newline at end of file