From 0bed0dab917e145ffd98d8ab2333740343d50448 Mon Sep 17 00:00:00 2001 From: ferricles Date: Sun, 22 May 2022 14:09:32 -0700 Subject: [PATCH 1/2] added copy hash button, removed craft button, added automatic craft upon input, lightened user input fields --- crafter/index.html | 40 ++++++++++++++++++++-------------------- js/crafter.js | 33 ++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/crafter/index.html b/crafter/index.html index 2c6d8c0..645d2b6 100644 --- a/crafter/index.html +++ b/crafter/index.html @@ -46,7 +46,7 @@

Type:

- +
@@ -56,7 +56,7 @@

Lv:

- +
@@ -71,17 +71,17 @@

Attack Speed

-
+
-
+
-
+
@@ -132,7 +132,7 @@

Ing 1:

- +
@@ -144,7 +144,7 @@

Ing 2:

- +
@@ -158,7 +158,7 @@

Ing 3:

- +
@@ -170,7 +170,7 @@

Ing 4:

- +
@@ -184,7 +184,7 @@

Ing 5:

- +
@@ -196,7 +196,7 @@

Ing 6:

- +
@@ -204,23 +204,23 @@ -
-
- -
-
+
+
-
+
+ +
+
-
+
diff --git a/js/crafter.js b/js/crafter.js index e48c598..7fb26be 100644 --- a/js/crafter.js +++ b/js/crafter.js @@ -44,12 +44,26 @@ function init_crafter() { try { document.getElementById("recipe-choice").addEventListener("change", (event) => { updateMaterials(); + calculateCraft(); }); document.getElementById("level-choice").addEventListener("change", (event) => { updateMaterials(); + calculateCraft(); }); document.getElementById("recipe-choice").setAttribute("oninput", "updateCraftedImage()"); + for (let i = 1; i < 4; ++i) { + document.getElementById("mat-1-"+i).setAttribute("onclick", document.getElementById("mat-1-"+i).getAttribute("onclick") + "; calculateCraft();"); + document.getElementById("mat-2-"+i).setAttribute("onclick", document.getElementById("mat-2-"+i).getAttribute("onclick") + "; calculateCraft();"); + } + for (let i = 1; i < 7; ++i) { + document.getElementById("ing-choice-" + i ).setAttribute("oninput", "calculateCraft();"); + } + for (const str of ["slow", "normal", "fast"]) { + document.getElementById(str + "-atk-button").setAttribute("onclick", document.getElementById(str + "-atk-button").getAttribute("onclick") + "; calculateCraft();"); + } + + populateFields(); decodeCraft(ing_url_tag); } catch (error) { @@ -230,11 +244,20 @@ function populateFields() { } - - -/* Copy the link +/* + Copies the CR Hash (CR-blahblahblah) */ -function copyRecipe(){ +function copyRecipeHash() { + if (player_craft) { + copyTextToClipboard("CR-"+location.hash); + document.getElementById("copy-hash-button").textContent = "Copied!"; + } +} + +/* + Copies the link (hppeng-wynn.github.io/crafter/#blahblah) +*/ +function copyRecipe() { if (player_craft) { copyTextToClipboard(ing_url_base+location.hash); document.getElementById("copy-button").textContent = "Copied!"; @@ -243,7 +266,7 @@ function copyRecipe(){ /* Copy the link AND a display of all ingredients */ -function shareRecipe(){ +function shareRecipe() { if (player_craft) { let copyString = ing_url_base+location.hash + "\n"; let name = player_craft.recipe.get("name").split("-"); From 9ebc65ff90885df0c6b402d491c3c9857cf7f9c4 Mon Sep 17 00:00:00 2001 From: ferricles Date: Sun, 22 May 2022 14:27:57 -0700 Subject: [PATCH 2/2] calculateCraftSchedule added --- js/crafter.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/js/crafter.js b/js/crafter.js index 7fb26be..dbbbfd6 100644 --- a/js/crafter.js +++ b/js/crafter.js @@ -44,23 +44,24 @@ function init_crafter() { try { document.getElementById("recipe-choice").addEventListener("change", (event) => { updateMaterials(); - calculateCraft(); + calculateCraftSchedule(); }); document.getElementById("level-choice").addEventListener("change", (event) => { updateMaterials(); - calculateCraft(); + calculateCraftSchedule(); }); document.getElementById("recipe-choice").setAttribute("oninput", "updateCraftedImage()"); + document.getElementById("recipe-choice").setAttribute("change", "updateCraftedImage()"); for (let i = 1; i < 4; ++i) { - document.getElementById("mat-1-"+i).setAttribute("onclick", document.getElementById("mat-1-"+i).getAttribute("onclick") + "; calculateCraft();"); - document.getElementById("mat-2-"+i).setAttribute("onclick", document.getElementById("mat-2-"+i).getAttribute("onclick") + "; calculateCraft();"); + document.getElementById("mat-1-"+i).setAttribute("onclick", document.getElementById("mat-1-"+i).getAttribute("onclick") + "; calculateCraftSchedule();"); + document.getElementById("mat-2-"+i).setAttribute("onclick", document.getElementById("mat-2-"+i).getAttribute("onclick") + "; calculateCraftSchedule();"); } for (let i = 1; i < 7; ++i) { - document.getElementById("ing-choice-" + i ).setAttribute("oninput", "calculateCraft();"); + document.getElementById("ing-choice-" + i ).setAttribute("oninput", "calculateCraftSchedule();"); } for (const str of ["slow", "normal", "fast"]) { - document.getElementById(str + "-atk-button").setAttribute("onclick", document.getElementById(str + "-atk-button").getAttribute("onclick") + "; calculateCraft();"); + document.getElementById(str + "-atk-button").setAttribute("onclick", document.getElementById(str + "-atk-button").getAttribute("onclick") + "; calculateCraftSchedule();"); } @@ -102,6 +103,20 @@ function toggleAtkSpd(buttonId) { } } +let doCraftTask = null; + +function calculateCraftSchedule(){ + console.log("Craft Schedule called"); + if (doCraftTask !== null) { + clearTimeout(doCraftTask); + } + doCraftTask = setTimeout(function(){ + doCraftTask = null; + calculateCraft(); + window.dispatchEvent(new Event('resize')); + }, 250); +} + function calculateCraft() { //Make things display. for (let i of document.getElementsByClassName("hide-container-block")) {