From 78216614df40f76fee03e1f186360f70f7a5601e Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Thu, 26 Aug 2021 08:31:47 -0400 Subject: [PATCH 01/14] some ini function cleanup --- main.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index dae8f74..bd20d21 100644 --- a/main.js +++ b/main.js @@ -751,18 +751,22 @@ function parseIniFromText(text) { if (section === null) { throw "Assignment outside of a section"; } + var eq = line.indexOf("="); if (eq === -1) { throw "Expected '='"; } + var lquot = line.indexOf('"'); if (lquot === -1) { throw "Expected '\"'"; } + var rquot = line.slice(lquot + 1).indexOf('"') + lquot + 1; if (rquot === -1) { throw "Unterminated value string"; } + var value = line.slice(lquot + 1, rquot); var key = line.slice(0, eq); ini[section][key] = value; @@ -821,7 +825,7 @@ function updatePersistentDataForm(iniobj) { document.getElementById("ini-love").value = Number(iniobj.General.Love.trim()); if (iniobj.FFFFF) { if (iniobj.FFFFF.F) { - document.getElementById("ini-omega-flowey-trapped").checked = (Number(iniobj.FFFFF.F.trim()) === 1); + document.getElementById("ini-omega-flowey-trapped").checked = Number(iniobj.FFFFF.F.trim()); } if (iniobj.FFFFF.P) { updateSelection("ini-omega-flowey-soul", iniobj.FFFFF.P); @@ -834,7 +838,7 @@ function updatePersistentDataForm(iniobj) { } if (iniobj.reset) { if (iniobj.reset.s_key) { - document.getElementById("ini-dodged-all-special-thanks").checked = (Number(iniobj.reset.s_key.trim()) === 1); + document.getElementById("ini-dodged-all-special-thanks").checked = Number(iniobj.reset.s_key.trim()); } } else { document.getElementById("ini-dodged-all-special-thanks").checked = false; @@ -873,9 +877,7 @@ function updateIniFromForm(ini) { if (!ini.FFFFF) { ini.FFFFF = {}; } - if (ini.FFFFF) { - ini.FFFFF.D = timesDied; - } + ini.FFFFF.D = timesDied; } if (document.getElementById("ini-dodged-all-special-thanks").checked) { if (!ini.reset) { From 7e10b7a03984baa4fb161303d37ecde3c34e4c5b Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Thu, 26 Aug 2021 09:42:28 -0400 Subject: [PATCH 02/14] Add local function to simplify updateIniFromForm --- main.js | 66 +++++++++++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/main.js b/main.js index bd20d21..972f461 100644 --- a/main.js +++ b/main.js @@ -851,48 +851,36 @@ function updatePersistentDataForm(iniobj) { // Update an ini object from the persistent data form. function updateIniFromForm(ini) { "use strict"; - ini.General.Name = document.getElementById("ini-name").value; - ini.General.Room = document.getElementById("ini-location").value; - ini.General.Kills = document.getElementById("ini-kills").value; - ini.General.Love = document.getElementById("ini-love").value; - if (document.getElementById("ini-omega-flowey-trapped").checked) { - if (!ini.FFFFF) { - ini.FFFFF = {}; - } - ini.FFFFF.F = "1"; - } else { - if (ini.FFFFF) { - ini.FFFFF.F = "0"; - } - } - var upcomingSoul = Number(document.getElementById("ini-omega-flowey-soul").value); - if (upcomingSoul) { - if (!ini.FFFFF) { - ini.FFFFF = {}; - } - ini.FFFFF.P = upcomingSoul; - } - var timesDied = Number(document.getElementById("ini-omega-flowey-deaths").value); - if (timesDied) { - if (!ini.FFFFF) { - ini.FFFFF = {}; - } - ini.FFFFF.D = timesDied; - } - if (document.getElementById("ini-dodged-all-special-thanks").checked) { - if (!ini.reset) { - ini.reset = {}; + + function formItemToObj(section, key, id) { + var value = 0; + if (document.getElementById(id).type === "checkbox") { + value = Number(document.getElementById(id).checked); + } else { + value = Number(document.getElementById(id).value); } - ini.reset.s_key = "1"; - } else { - if (ini.reset) { - ini.reset.s_key = "0"; + + if (value) { + if (!ini[section]) { + ini[section] = {}; + } + ini[section][key] = String(value); + } else { + if (ini[section]) { + ini[section][key] = "0"; + } } } - var fun = Number(document.getElementById("ini-fun").value); - if (fun) { - ini.General.fun = fun; - } + + formItemToObj("General", "Name", "ini-name"); + formItemToObj("General", "Room", "ini-location"); + formItemToObj("General", "Kills", "ini-kills"); + formItemToObj("General", "Love", "ini-love"); + formItemToObj("General", "fun", "ini-fun"); + formItemToObj("FFFFF", "F", "ini-omega-flowey-trapped"); + formItemToObj("FFFFF", "P", "ini-omega-flowey-soul"); + formItemToObj("FFFFF", "D", "ini-omega-flowey-deaths"); + formItemToObj("reset", "s_key", "ini-dodged-all-special-thanks"); } function updateSelection(id, value, newChoiceArray) { From 7e7bebe3373dd2faeb8eac4041106349e0fa7176 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Fri, 5 Nov 2021 10:19:50 -0400 Subject: [PATCH 03/14] Add boxes, keys, file8 Not functional yet. Working on #11, #34, and #74. --- index.html | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/index.html b/index.html index e047eb1..27f4a53 100644 --- a/index.html +++ b/index.html @@ -160,6 +160,9 @@

Persistent Data (undertale.ini)

>Trapped in Flowey's World +
@@ -407,6 +410,78 @@

SAVE Data (file0)

+ +
+ Keychain +
+ + + + + + +

True Lab keys

+ + + + + + + + +
+
+ +
+ Dimensional Box A +
+ + + + + + + + + + + + + + + + + + + + +
+
+
+ Dimensional Box B +
+ + + + + + + + + + + + + + + + + + + + +
+
Other @@ -487,6 +562,7 @@

SAVE Data (file0)

+
Advanced
From 2bc9a444a0cfa33ee3aac25fedfd04ad29b56631 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Fri, 5 Nov 2021 10:27:28 -0400 Subject: [PATCH 04/14] [m] Hacky padding fix --- index.html | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index 27f4a53..fc5469d 100644 --- a/index.html +++ b/index.html @@ -414,21 +414,20 @@

SAVE Data (file0)

Keychain
- - - - - - -

True Lab keys

- - - - - - - - + + + + + + + + + + + + + +
From b84f77c41e35a3ad7bdc4f9db41e5a2e915afb48 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Fri, 5 Nov 2021 16:17:17 -0400 Subject: [PATCH 05/14] solve three issues and rely more heavily on arrays Engineer gaming --- main.js | 138 +++++++++++++++++++++++++------------------------------- 1 file changed, 62 insertions(+), 76 deletions(-) diff --git a/main.js b/main.js index 972f461..d0ea5ca 100644 --- a/main.js +++ b/main.js @@ -517,9 +517,21 @@ var flagFor = { // Link flags with inputs "sav-muffetstate": 397, "sav-broguardsstate": 402, "sav-mettatonstate": 425, - "sav-undyne-cell": 465 + "sav-asgkey1": 452, + "sav-asgkey2": 453, + "sav-undyne-cell": 465, + "sav-redkey": 481, + "sav-blukey": 482, + "sav-grnkey": 483, + "sav-ylwkey": 484, + "sav-sanskey": 497 }; +for (var i = 1; i <= 10; i++) { + flagFor["sav-boxa" + i] = 299 + i; + flagFor["sav-boxb" + i] = 311 + i; +} + var inputForFlag = {}; // and vice versa for (var id in flagFor) { inputForFlag["sav-flag-" + flagFor[id]] = id; @@ -530,12 +542,6 @@ var killedBool = [ "Killed" ]; -var simpleDogStates = [ - "Initial state", - "Killed", - "Played fetch (Spared)" -]; - var stateChoiceArrays = { "sav-trainingdummystate": [ "Initial state", @@ -543,48 +549,13 @@ var stateChoiceArrays = { "Talked to", "Tired of your shenanigans" ], - "sav-torielstate": { - "0": "Initial state", - "1": "In basement", - "3": "Fled from", - "4": "Killed", - "5": "Spared" - }, - "sav-doggostate": simpleDogStates, - "sav-dogamydogaressastate": simpleDogStates, - "sav-greaterdogstate": [ - "Initial state", - "Killed", - "Played fetch (Spared)", - "Ignored" - ], - "sav-comedianstate": [ - "Initial state", - "Laughed at joke [Yellow credit]", - "Killed" - ], - "sav-papyrusstate": { - "-3": "Lost to thrice", - "-2": "Lost to twice", - "-1": "Lost to once", - "0": "Initial state", - "1": "Killed" - }, - "sav-shyrenstate": [ - "Initial state", - "Killed", - "Continued humming [Yellow credit]" - ], "sav-undynestate1": killedBool, // Undyne The Undying "sav-maddummystate": killedBool, // *Glad Dummy - "sav-undynestate2": [ // Undyne in general - "Initial state", - "Killed", - "Sick" - ], "sav-muffetstate": killedBool, "sav-broguardsstate": killedBool, "sav-mettatonstate": killedBool, + "sav-asgkey1": ["Initial state", "Got key"], + "sav-asgkey2": ["Initial state", "Got key"], "sav-weapon": weapons, "sav-armor": armors, "sav-plotvalue": { @@ -724,6 +695,12 @@ var stateChoiceArrays = { ] }; +for (var id in flagFor) { + if (!stateChoiceArrays[id]) { + stateChoiceArrays[id] = flags[flagFor[id]][2]; + } +} + for (var i = 1; i <= 8; i++) { stateChoiceArrays["sav-invslot" + i] = items; stateChoiceArrays["sav-cellslot" + i] = cellOpts; @@ -825,7 +802,12 @@ function updatePersistentDataForm(iniobj) { document.getElementById("ini-love").value = Number(iniobj.General.Love.trim()); if (iniobj.FFFFF) { if (iniobj.FFFFF.F) { + if (document.getElementById("ini-omega-flowey-trapped").checked != Number(iniobj.FFFFF.F.trim())) { + document.getElementById("sav-savefile8").classList.toggle('hidden'); + } document.getElementById("ini-omega-flowey-trapped").checked = Number(iniobj.FFFFF.F.trim()); + } else { + document.getElementById("sav-savefile8").classList.add('hidden'); } if (iniobj.FFFFF.P) { updateSelection("ini-omega-flowey-soul", iniobj.FFFFF.P); @@ -946,16 +928,20 @@ function updateSaveDataForm(values) { document.getElementById("sav-weaponat").value = values[5]; document.getElementById("sav-df").value = values[6]; document.getElementById("sav-armordf").value = values[7]; - document.getElementById("sav-undyne-cell").checked = (Number(values[495].trim()) === 1); - if (Number(values[495].trim()) === 1) { + + if (Number(values[495].trim())) { cellOpts[210] = "Papyrus and Undyne"; } else { cellOpts[210] = "Papyrus's Phone"; } + if (Number(values[545].trim()) != document.getElementById("sav-havecell").checked) { + document.getElementById("cellslots").classList.toggle('hidden'); + } for (var i = 1; i <= 8; i++) { updateSelection("sav-invslot" + i, values[10 + (i * 2)]); updateSelection("sav-cellslot" + i, values[11 + (i * 2)]); } + if (document.getElementById("allow-non-equipables").checked) { updateSelection("sav-weapon", values[28], items); updateSelection("sav-armor", values[29], items); @@ -963,41 +949,28 @@ function updateSaveDataForm(values) { updateSelection("sav-weapon", values[28], weapons); updateSelection("sav-armor", values[29], armors); } - updateSelection("sav-trainingdummystate", values[44]); - updateSelection("sav-torielstate", values[75]); - updateSelection("sav-doggostate", values[82]); - updateSelection("sav-dogamydogaressastate", values[83]); - updateSelection("sav-greaterdogstate", values[84]); - updateSelection("sav-comedianstate", values[87]); - updateSelection("sav-papyrusstate", values[97]); - updateSelection("sav-shyrenstate", values[111]); - document.getElementById("sav-ruinskills").value = values[232]; - document.getElementById("sav-snowdinkills").value = values[233]; - document.getElementById("sav-waterfallkills").value = values[234]; - document.getElementById("sav-hotlandkills").value = values[235]; - updateSelection("sav-undynestate1", values[281]); - updateSelection("sav-maddummystate", values[282]); - updateSelection("sav-undynestate2", values[380]); - updateSelection("sav-muffetstate", values[427]); - updateSelection("sav-broguardsstate", values[432]); - updateSelection("sav-mettatonstate", values[455]); + + for (var id in flagFor) { + if (document.getElementById(id).nodeName === "SELECT") { + updateSelection(id, values[30 + flagFor[id]]); + } else { + document.getElementById(id).value = Number(values[30 + flagFor[id]].trim()); + document.getElementById(id).checked = Number(values[30 + flagFor[id]].trim()); + } + } document.getElementById("sav-exitedtruelab").checked = (Number(values[523].trim()) === 12); - document.getElementById("sav-defeatedasriel").checked = (Number(values[37].trim()) === 1); updateSelection("sav-plotvalue", values[542]); - if (Number(values[545].trim()) != document.getElementById("sav-havecell").checked) { - document.getElementById("cellslots").classList.toggle('hidden'); - } document.getElementById("sav-havecell").checked = (Number(values[545].trim()) === 1); updateSelection("sav-location", values[547]); - document.getElementById("sav-fun").value = Number(values[35].trim()); + for (var i = 0; i < 512; i++) { if (document.getElementById("sav-flag-" + i).nodeName === "SELECT") { updateSelection("sav-flag-" + i, values[30 + i], flags[i][2]); } else { document.getElementById("sav-flag-" + i).value = values[30 + i]; + // Update checkboxes (should have no ill effects on non-checkbox-based flags) + document.getElementById("sav-flag-" + i).previousSibling.checked = Number(document.getElementById("sav-flag-" + i).value); } - // Update checkboxes (should have no ill effects on non-checkbox-based flags) - document.getElementById("sav-flag-" + i).previousSibling.checked = Number(document.getElementById("sav-flag-" + i).value); } } @@ -1022,6 +995,10 @@ function updateSaveValuesFromForm(values) { values[10 + (i * 2)] = document.getElementById("sav-invslot" + i).value; values[11 + (i * 2)] = document.getElementById("sav-cellslot" + i).value; } + for (var i = 1; i <= 10; i++) { + values[299 + i] = document.getElementById("sav-boxa" + i).value; + values[311 + i] = document.getElementById("sav-boxb" + i).value; + } values[28] = document.getElementById("sav-weapon").value; values[29] = document.getElementById("sav-armor").value; values[44] = document.getElementById("sav-trainingdummystate").value; @@ -1067,14 +1044,17 @@ function saveIniToFile(ini) { flowey_laugh_once(); } -function saveSaveValuesToFile(values) { +function saveSaveValuesToFile(values, slot) { "use strict"; + if (!slot) { + slot = "0"; + } var string = ""; for (var i = 0; i < values.length; i++) { string += values[i] + "\r\n"; } var blob = new Blob([string], {type: "application/octet-stream"}); - saveAs(blob, "file0", true); + saveAs(blob, "file" + slot, true); flowey_laugh_once(); } @@ -1244,6 +1224,10 @@ function start() { updateSaveValuesFromForm(saveLines); saveSaveValuesToFile(saveLines); }); + document.getElementById("sav-savefile8").addEventListener("click", function() { + updateSaveValuesFromForm(saveLines); + saveSaveValuesToFile(saveLines, "8"); + }); // system_information download document.getElementById("savesi2").addEventListener("click", function() { @@ -1307,9 +1291,8 @@ function start() { document.getElementById("sav-havecell").addEventListener("change", function() { document.getElementById("cellslots").classList.toggle('hidden'); }); - var callUndyne = document.getElementById("sav-undyne-cell"); - callUndyne.addEventListener("change", function() { - if (callUndyne.checked) { + document.getElementById("sav-undyne-cell").addEventListener("change", function() { + if (this.checked) { cellOpts[210] = "Papyrus and Undyne"; } else { cellOpts[210] = "Papyrus's Phone"; @@ -1318,6 +1301,9 @@ function start() { updateSelection("sav-cellslot" + i); } }); + document.getElementById("ini-omega-flowey-trapped").addEventListener("change", function() { + document.getElementById("sav-savefile8").classList.toggle('hidden'); + }); // Presets document.getElementById("builtinpresetload").addEventListener("click", function() { From f414cf3b040a82a736c89ebc9032d7c3eeac979a Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Fri, 5 Nov 2021 19:29:21 -0400 Subject: [PATCH 06/14] Use array + loop instead of function for ini read --- main.js | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/main.js b/main.js index d0ea5ca..076d60a 100644 --- a/main.js +++ b/main.js @@ -80,9 +80,8 @@ var weapons = { "49": "Empty Gun", "51": "Worn Dagger", "52": "Real Knife" -}; - -var armors = { +}, + armors = { // "0": "Empty", "4": "Bandage", "12": "Faded Ribbon", @@ -124,7 +123,7 @@ var weaponAts = { var armorAts = { "48": 5, // cowboy hat "64": 10 // temy armor -} +}; var armorDfs = { "4": 0, // bandage @@ -537,6 +536,20 @@ for (var id in flagFor) { inputForFlag["sav-flag-" + flagFor[id]] = id; } +var iniIDs = [ + // Element ID, section, key + // TODO: Consider restructuring as {section: {key: id}} or [id, values] or whatever + ["ini-name", "General", "Name" ], + ["ini-location", "General", "Room" ], + ["ini-kills", "General", "Kills"], + ["ini-love", "General", "Love" ], + ["ini-fun", "General", "fun" ], + ["ini-omega-flowey-trapped", "FFFFF", "F"], + ["ini-omega-flowey-soul", "FFFFF", "P"], + ["ini-omega-flowey-deaths", "FFFFF", "D"], + ["ini-dodged-all-special-thanks", "reset", "s_key"] +]; + var killedBool = [ "Initial state", "Killed" @@ -834,35 +847,25 @@ function updatePersistentDataForm(iniobj) { function updateIniFromForm(ini) { "use strict"; - function formItemToObj(section, key, id) { + for (var i in iniIDs) { // 0 -> element ID, 1 -> ini section, 2 -> ini key var value = 0; - if (document.getElementById(id).type === "checkbox") { - value = Number(document.getElementById(id).checked); + if (document.getElementById(iniIDs[i][0]).type === "checkbox") { + value = Number(document.getElementById(iniIDs[i][0]).checked); } else { - value = Number(document.getElementById(id).value); + value = Number(document.getElementById(iniIDs[i][0]).value); } if (value) { - if (!ini[section]) { - ini[section] = {}; + if (!ini[iniIDs[i][1]]) { + ini[iniIDs[i][1]] = {}; } - ini[section][key] = String(value); + ini[ iniIDs[i][1] ][ iniIDs[i][2] ] = String(value); } else { - if (ini[section]) { - ini[section][key] = "0"; + if (ini[iniIDs[i][1]]) { + ini[ iniIDs[i][1] ][ iniIDs[i][2] ] = "0"; } } } - - formItemToObj("General", "Name", "ini-name"); - formItemToObj("General", "Room", "ini-location"); - formItemToObj("General", "Kills", "ini-kills"); - formItemToObj("General", "Love", "ini-love"); - formItemToObj("General", "fun", "ini-fun"); - formItemToObj("FFFFF", "F", "ini-omega-flowey-trapped"); - formItemToObj("FFFFF", "P", "ini-omega-flowey-soul"); - formItemToObj("FFFFF", "D", "ini-omega-flowey-deaths"); - formItemToObj("reset", "s_key", "ini-dodged-all-special-thanks"); } function updateSelection(id, value, newChoiceArray) { From 6c919e8b52c345e7e3d71f5e099572dabca9d9b5 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Fri, 5 Nov 2021 19:48:08 -0400 Subject: [PATCH 07/14] fix room/item filtering turns out, null does not === undefined --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index 076d60a..6544130 100644 --- a/main.js +++ b/main.js @@ -875,7 +875,7 @@ function updateSelection(id, value, newChoiceArray) { // Sanitize value if (typeof value === "string") { value = Number(value.trim()); - } else if (value === undefined) { + } else if (value == undefined) { if (select.value === undefined) { window.alert("No value found for form input " + id + ", defaulting to 0."); value = 0; From 42978f1dc74da5ad05d603300e423cf9764abb76 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Fri, 5 Nov 2021 21:32:27 -0400 Subject: [PATCH 08/14] Remove flags added to basic menu --- help.html | 9 --------- 1 file changed, 9 deletions(-) diff --git a/help.html b/help.html index 549d79d..754de32 100644 --- a/help.html +++ b/help.html @@ -123,20 +123,11 @@

Advanced Mode

the True Lab. Finally, flag 7 (accessible in the basic menu) activates the post-Asriel epilogue. -
  • - Flags 300-324 contain the contents of your Dimensional Boxes. - If you want to hack in more than eight items, use these. -
  • Flags 130-156 control a great many of the yellow credits for sparing enemies in the right way. If you want an all-yellow-credits run (or to analyze one), look here first.
  • -
  • - The status of your keychain is contained in flags. Asgore's keys are - flags 452-454; True Lab keys are flags 481-484; - and Sans's room keys are flag 497. -
  • From f3daede16f81fb8d8d042724c78c06fded658423 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Sat, 6 Nov 2021 15:18:23 -0400 Subject: [PATCH 09/14] var -> let and const And use 'this', and define Blobs inline, and document uneditable values (of which there are like four). Oh, and use ternaries with those checkbox values so that we don't get random Number values in the middle of the save file. --- main.js | 456 ++++++++++++++++++++++++-------------------------------- 1 file changed, 198 insertions(+), 258 deletions(-) diff --git a/main.js b/main.js index 6544130..802c053 100644 --- a/main.js +++ b/main.js @@ -1,75 +1,8 @@ -var debugVars = {}; // Could be handy +let debugVars = {}; // Could be handy -var items = [ - "Empty", - "Monster Candy", - "Croquet Roll", - "Stick", - "Bandage", - "Rock Candy", - "Pumpkin Rings", - "Spider Donut", - "Stoic Onion", - "Ghost Fruit", - "Spider Cider", - "Butterscotch Pie", - "Faded Ribbon", - "Toy Knife", - "Tough Glove", - "Manly Bandana", - "Snowman Piece", - "Nice Cream", - "Puppydough Icecream", - "Bisicle", - "Unisicle", - "Cinnamon Bun", - "Temmie Flakes", - "Abandoned Quiche", - "Old Tutu", - "Ballet Shoes", - "Punch Card", - "Annoying Dog", - "Dog Salad", - "Dog Residue (1)", - "Dog Residue (2)", - "Dog Residue (3)", - "Dog Residue (4)", - "Dog Residue (5)", - "Dog Residue (6)", - "Astronaut Food", - "Instant Noodles", - "Crab Apple", - "Hot Dog...?", - "Hot Cat", - "Glamburger", - "Sea Tea", - "Starfait", - "Legendary Hero", - "Cloudy Glasses", - "Torn Notebook", - "Stained Apron", - "Burnt Pan", - "Cowboy hat", - "Empty Gun", - "Heart Locket", - "Worn Dagger", - "Real Knife", - "The Locket", - "Bad Memory", - "Dream", - "Undyne's Letter", - "Undyne Letter EX", - "Potato Chisps", - "Junk Food", - "Mystery Key", - "Face Steak", - "Hush Puppy", - "Snail Pie", - "temy armor", - "" -]; +// items defined in flags.js (soon to be data.js) -var weapons = { +const weapons = { // "0": "Empty", "3": "Stick", "13": "Toy Knife", @@ -93,22 +26,8 @@ var weapons = { "50": "Heart Locket", "53": "The Locket", "64": "temy armor" -}; - -var cellOpts = { - "0": "Empty", - "201": "Say Hello", - "202": "Puzzle Help", - "203": "About Yourself", - "204": "Call Her \"Mom\"", - "205": "Flirt", - "206": "Toriel's Phone", - "210": "Papyrus's Phone", - "220": "Dimensional Box A", - "221": "Dimensional Box B" -}; - -var weaponAts = { +}, + weaponAts = { "3": 0, // stick "13": 3, // toy knife "14": 5, // tough glove @@ -118,14 +37,12 @@ var weaponAts = { "49": 12, // empty gun "51": 15, // worn dagger "52": 99 // Real Knife -}; - -var armorAts = { +}, + armorAts = { "48": 5, // cowboy hat "64": 10 // temy armor -}; - -var armorDfs = { +}, + armorDfs = { "4": 0, // bandage "12": 3, // faded ribbon "15": 7, // manly bandana @@ -138,7 +55,20 @@ var armorDfs = { "64": 20 // temy armor }; -var rooms = [[], [], []]; +let cellOpts = { + "0": "Empty", + "201": "Say Hello", + "202": "Puzzle Help", + "203": "About Yourself", + "204": "Call Her \"Mom\"", + "205": "Flirt", + "206": "Toriel's Phone", + "210": "Papyrus's Phone", + "220": "Dimensional Box A", + "221": "Dimensional Box B" +}; + +let rooms = [[], [], []]; rooms[2] = [ "Initializer [Dogchecked]", "Introduction [Dogchecked]", @@ -478,7 +408,7 @@ rooms[2] = [ "Snowdin - Dog Shrine [Dogchecked]" ]; -for (var i = 0; i < rooms[2].length; i++) { +for (let i = 0; i < rooms[2].length; i++) { if (rooms[2][i].indexOf("[SAVE]") !== -1) { rooms[0][i] = rooms[2][i]; rooms[1][i] = rooms[2][i]; @@ -488,14 +418,14 @@ for (var i = 0; i < rooms[2].length; i++) { } // rooms[0] is SAVE points only, rooms[1] is non-Dogchecked only, rooms[2] contains all rooms. -var roomSelectOptions = [ +const roomSelectOptions = [ "SAVE points only", "Accessible rooms only", "All rooms" ]; // Flags initialized in flags.js -var flagFor = { // Link flags with inputs +let flagFor = { // Link flags with inputs "sav-fun": 5, "sav-defeatedasriel": 7, "sav-trainingdummystate": 14, @@ -526,17 +456,17 @@ var flagFor = { // Link flags with inputs "sav-sanskey": 497 }; -for (var i = 1; i <= 10; i++) { +for (let i = 1; i <= 10; i++) { flagFor["sav-boxa" + i] = 299 + i; flagFor["sav-boxb" + i] = 311 + i; } -var inputForFlag = {}; // and vice versa -for (var id in flagFor) { +let inputForFlag = {}; // and vice versa +for (const id in flagFor) { inputForFlag["sav-flag-" + flagFor[id]] = id; } -var iniIDs = [ +const iniIDs = [ // Element ID, section, key // TODO: Consider restructuring as {section: {key: id}} or [id, values] or whatever ["ini-name", "General", "Name" ], @@ -550,12 +480,12 @@ var iniIDs = [ ["ini-dodged-all-special-thanks", "reset", "s_key"] ]; -var killedBool = [ +const killedBool = [ "Initial state", "Killed" ]; -var stateChoiceArrays = { +let stateChoiceArrays = { "sav-trainingdummystate": [ "Initial state", "Killed", @@ -708,31 +638,32 @@ var stateChoiceArrays = { ] }; -for (var id in flagFor) { +for (const id in flagFor) { if (!stateChoiceArrays[id]) { stateChoiceArrays[id] = flags[flagFor[id]][2]; } } -for (var i = 1; i <= 8; i++) { +for (let i = 1; i <= 8; i++) { stateChoiceArrays["sav-invslot" + i] = items; stateChoiceArrays["sav-cellslot" + i] = cellOpts; } function parseIniFromText(text) { "use strict"; - var lines = text.match(/[^\r\n]+/g); - var section = null; - var ini = {}; + let lines = text.match(/[^\r\n]+/g), + section = null, + ini = {}; + lines.forEach(function(line) { // Ignore empty lines if (line === "") { return; } // If line starts with [, it is a section header - var lbracket = line.indexOf("["); + const lbracket = line.indexOf("["); if (lbracket !== -1) { - var rbracket = line.slice(lbracket).indexOf("]") + lbracket; + const rbracket = line.slice(lbracket).indexOf("]") + lbracket; if (rbracket !== -1) { section = line.slice(lbracket + 1, rbracket); ini[section] = {}; @@ -742,23 +673,23 @@ function parseIniFromText(text) { throw "Assignment outside of a section"; } - var eq = line.indexOf("="); + const eq = line.indexOf("="); if (eq === -1) { throw "Expected '='"; } - var lquot = line.indexOf('"'); + const lquot = line.indexOf('"'); if (lquot === -1) { throw "Expected '\"'"; } - var rquot = line.slice(lquot + 1).indexOf('"') + lquot + 1; + const rquot = line.slice(lquot + 1).indexOf('"') + lquot + 1; if (rquot === -1) { throw "Unterminated value string"; } - var value = line.slice(lquot + 1, rquot); - var key = line.slice(0, eq); + const value = line.slice(lquot + 1, rquot), + key = line.slice(0, eq); ini[section][key] = value; } }); @@ -769,8 +700,8 @@ function flowey_laugh_once() { "use strict"; if (localStorage.getItem("laughed") !== "true") { document.getElementById("floweyimg").src = "res/flowey_evil.png"; - if(!document.getElementById("mute").checked) { - var audio = new Audio("res/flowey_laugh.mp3"); + if (!document.getElementById("mute").checked) { + let audio = new Audio("res/flowey_laugh.mp3"); audio.play(); } localStorage.setItem("laughed", "true"); @@ -781,9 +712,9 @@ function flowey_laugh_once() { // Load undertale.ini data into an ini object and execute a closure on it. function loadIniFromFile(file, closure) { "use strict"; - var reader = new FileReader(); + let reader = new FileReader(); reader.onload = function(e) { - var text = e.target.result; + const text = e.target.result; try { closure(parseIniFromText(text)); } catch (err) { @@ -796,9 +727,9 @@ function loadIniFromFile(file, closure) { // Load save data from a file into an array of values, and execute a closure on it. function loadSaveFromFile(file, closure) { "use strict"; - var reader = new FileReader(); + let reader = new FileReader(); reader.onload = function(e) { - var text = e.target.result; + const text = e.target.result; closure(text.match(/[^\r\n]+/g).map(function(line) { return line.trim(); })); @@ -847,22 +778,22 @@ function updatePersistentDataForm(iniobj) { function updateIniFromForm(ini) { "use strict"; - for (var i in iniIDs) { // 0 -> element ID, 1 -> ini section, 2 -> ini key - var value = 0; - if (document.getElementById(iniIDs[i][0]).type === "checkbox") { - value = Number(document.getElementById(iniIDs[i][0]).checked); + for (const [elementID, section, key] of iniIDs) { + let value = 0; + if (document.getElementById(elementID).type === "checkbox") { + value = Number(document.getElementById(elementID).checked); } else { - value = Number(document.getElementById(iniIDs[i][0]).value); + value = document.getElementById(elementID).value; } if (value) { - if (!ini[iniIDs[i][1]]) { - ini[iniIDs[i][1]] = {}; + if (!ini[section]) { + ini[section] = {}; } - ini[ iniIDs[i][1] ][ iniIDs[i][2] ] = String(value); + ini[section][key] = String(value); } else { - if (ini[iniIDs[i][1]]) { - ini[ iniIDs[i][1] ][ iniIDs[i][2] ] = "0"; + if (ini[section]) { + ini[section][key] = "0"; } } } @@ -870,7 +801,7 @@ function updateIniFromForm(ini) { function updateSelection(id, value, newChoiceArray) { "use strict"; - var select = document.getElementById(id); + let select = document.getElementById(id); // Sanitize value if (typeof value === "string") { @@ -906,10 +837,10 @@ function updateSelection(id, value, newChoiceArray) { } // Create options - for (var key of Object.keys(stateChoiceArrays[id]).sort((a, b) => a - b)) { // (Decimal keys don't automatically sort correctly) - var newOption = document.createElement("option"); + for (const key of Object.keys(stateChoiceArrays[id]).sort((a, b) => a - b)) { // (Decimal keys don't automatically sort correctly) + let newOption = document.createElement("option"), + newContent = document.createTextNode(stateChoiceArrays[id][key]); newOption.setAttribute("value", key); - var newContent = document.createTextNode(stateChoiceArrays[id][key]); newOption.appendChild(newContent); select.appendChild(newOption); } @@ -922,15 +853,17 @@ function updateSelection(id, value, newChoiceArray) { function updateSaveDataForm(values) { "use strict"; document.getElementById("sav-name").value = values[0]; - document.getElementById("sav-kills").value = values[11]; document.getElementById("sav-love").value = values[1]; document.getElementById("sav-hp").value = values[2]; - document.getElementById("sav-exp").value = values[9]; - document.getElementById("sav-gold").value = values[10]; + // global.maxen is values[3] document.getElementById("sav-at").value = values[4]; document.getElementById("sav-weaponat").value = values[5]; document.getElementById("sav-df").value = values[6]; document.getElementById("sav-armordf").value = values[7]; + // global.sp is values[8] + document.getElementById("sav-exp").value = values[9]; + document.getElementById("sav-gold").value = values[10]; + document.getElementById("sav-kills").value = values[11]; if (Number(values[495].trim())) { cellOpts[210] = "Papyrus and Undyne"; @@ -940,7 +873,7 @@ function updateSaveDataForm(values) { if (Number(values[545].trim()) != document.getElementById("sav-havecell").checked) { document.getElementById("cellslots").classList.toggle('hidden'); } - for (var i = 1; i <= 8; i++) { + for (let i = 1; i <= 8; i++) { // values[12] through values[27] updateSelection("sav-invslot" + i, values[10 + (i * 2)]); updateSelection("sav-cellslot" + i, values[11 + (i * 2)]); } @@ -953,7 +886,7 @@ function updateSaveDataForm(values) { updateSelection("sav-armor", values[29], armors); } - for (var id in flagFor) { + for (const id in flagFor) { if (document.getElementById(id).nodeName === "SELECT") { updateSelection(id, values[30 + flagFor[id]]); } else { @@ -962,11 +895,8 @@ function updateSaveDataForm(values) { } } document.getElementById("sav-exitedtruelab").checked = (Number(values[523].trim()) === 12); - updateSelection("sav-plotvalue", values[542]); - document.getElementById("sav-havecell").checked = (Number(values[545].trim()) === 1); - updateSelection("sav-location", values[547]); - for (var i = 0; i < 512; i++) { + for (let i = 0; i < 512; i++) { if (document.getElementById("sav-flag-" + i).nodeName === "SELECT") { updateSelection("sav-flag-" + i, values[30 + i], flags[i][2]); } else { @@ -975,75 +905,72 @@ function updateSaveDataForm(values) { document.getElementById("sav-flag-" + i).previousSibling.checked = Number(document.getElementById("sav-flag-" + i).value); } } + + updateSelection("sav-plotvalue", values[542]); + // Access to ITEM and STAT menus is values 543 and 544, respectively. + document.getElementById("sav-havecell").checked = (Number(values[545].trim()) === 1); + // global.currentsong is values[546] + updateSelection("sav-location", values[547]); + // global.time is values[548], stored in frames } // Update an array of values from the save data form. function updateSaveValuesFromForm(values) { "use strict"; - values[523] = "0"; // Initialize correctly - for (var i = 0; i < flags.length; i++) { + values[523] = "0"; // Initialize correctly, can be overridden by flag entry OR True Lab checkbox + for (let i = 0; i < flags.length; i++) { values[30 + i] = document.getElementById("sav-flag-" + i).value; } values[0] = document.getElementById("sav-name").value; values[1] = document.getElementById("sav-love").value; values[2] = document.getElementById("sav-hp").value; + // global.maxen is values[3] values[4] = document.getElementById("sav-at").value; values[5] = document.getElementById("sav-weaponat").value; values[6] = document.getElementById("sav-df").value; values[7] = document.getElementById("sav-armordf").value; + // global.sp is values[8] values[9] = document.getElementById("sav-exp").value; values[10] = document.getElementById("sav-gold").value; values[11] = document.getElementById("sav-kills").value; - for (var i = 1; i <= 8; i++) { + for (let i = 1; i <= 8; i++) { values[10 + (i * 2)] = document.getElementById("sav-invslot" + i).value; values[11 + (i * 2)] = document.getElementById("sav-cellslot" + i).value; } - for (var i = 1; i <= 10; i++) { - values[299 + i] = document.getElementById("sav-boxa" + i).value; - values[311 + i] = document.getElementById("sav-boxb" + i).value; - } values[28] = document.getElementById("sav-weapon").value; values[29] = document.getElementById("sav-armor").value; - values[44] = document.getElementById("sav-trainingdummystate").value; - values[75] = document.getElementById("sav-torielstate").value; - values[82] = document.getElementById("sav-doggostate").value; - values[83] = document.getElementById("sav-dogamydogaressastate").value; - values[84] = document.getElementById("sav-greaterdogstate").value; - values[87] = document.getElementById("sav-comedianstate").value; - values[97] = document.getElementById("sav-papyrusstate").value; - values[111] = document.getElementById("sav-shyrenstate").value; - values[232] = document.getElementById("sav-ruinskills").value; - values[233] = document.getElementById("sav-snowdinkills").value; - values[234] = document.getElementById("sav-waterfallkills").value; - values[235] = document.getElementById("sav-hotlandkills").value; - values[281] = document.getElementById("sav-undynestate1").value; - values[282] = document.getElementById("sav-maddummystate").value; - values[380] = document.getElementById("sav-undynestate2").value; - values[427] = document.getElementById("sav-muffetstate").value; - values[432] = document.getElementById("sav-broguardsstate").value; - values[455] = document.getElementById("sav-mettatonstate").value; - values[495] = Number(document.getElementById("sav-undyne-cell").checked); + + for (const id in flagFor) { + if (document.getElementById(id).type === "checkbox") { + values[flagFor[id]] = document.getElementById(id).checked ? "1" : "0"; + } else { + values[flagFor[id]] = document.getElementById(id).value; + } + } + if (document.getElementById("sav-exitedtruelab").checked) { values[523] = "12"; } - values[37] = Number(document.getElementById("sav-defeatedasriel").checked); values[542] = document.getElementById("sav-plotvalue").value; - values[545] = Number(document.getElementById("sav-havecell").checked); + values[545] = document.getElementById("sav-havecell").checked ? "1" : "0"; values[547] = document.getElementById("sav-location").value; - values[35] = document.getElementById("sav-fun").value; } function saveIniToFile(ini) { "use strict"; - var string = ""; - for (var section in ini) { + let string = ""; + for (const section in ini) { string += "[" + section + "]\r\n"; - for (var key in ini[section]) { + for (const key in ini[section]) { string += key + "=\"" + ini[section][key] + "\"\r\n"; } } - var blob = new Blob([string], {type: "text/plain;charset=utf-8"}); - saveAs(blob, "undertale.ini", true); + + saveAs( + new Blob([string], {type: "text/plain;charset=utf-8"}), + "undertale.ini", + true + ); flowey_laugh_once(); } @@ -1052,21 +979,25 @@ function saveSaveValuesToFile(values, slot) { if (!slot) { slot = "0"; } - var string = ""; - for (var i = 0; i < values.length; i++) { + let string = ""; + for (let i = 0; i < values.length; i++) { string += values[i] + "\r\n"; } - var blob = new Blob([string], {type: "application/octet-stream"}); - saveAs(blob, "file" + slot, true); + + saveAs( + new Blob([string], {type: "text/plain;charset=utf-8"}), + "file" + slot, + true + ); flowey_laugh_once(); } function loadPresetSelect() { "use strict"; - var selectNode = document.getElementById("builtinpresetselect"); - for (var k in presets) { - var newOption = document.createElement("option"); - var newContent = document.createTextNode(k); + let selectNode = document.getElementById("builtinpresetselect"); + for (const k in presets) { + let newOption = document.createElement("option"), + newContent = document.createTextNode(k); newOption.appendChild(newContent); selectNode.appendChild(newOption); } @@ -1074,15 +1005,15 @@ function loadPresetSelect() { function start() { "use strict"; - var userPresets = localStorage.getItem("userPresets"); - var advancedMode = (localStorage.getItem("advanced") == "true"); + let userPresets = localStorage.getItem("userPresets"), + advancedMode = (localStorage.getItem("advanced") == "true"); if (userPresets === null) { localStorage.setItem("userPresets", JSON.stringify({})); } else { - for (var key in JSON.parse(userPresets)) { - var presetSelect2 = document.getElementById("userpresetselect"); - var option2 = document.createElement("option"); - var text2 = document.createTextNode(key); + for (const key in JSON.parse(userPresets)) { + let presetSelect2 = document.getElementById("userpresetselect"), + option2 = document.createElement("option"), + text2 = document.createTextNode(key); option2.appendChild(text2); presetSelect2.appendChild(option2); } @@ -1090,7 +1021,7 @@ function start() { if (localStorage.getItem("laughed") === "true") { document.getElementById("floweyimg").src = "res/flowey_evil.png"; } - var ini, saveLines; + let ini, saveLines; function loadPreset(name) { ini = presets[name].ini; saveLines = presets[name].lines; @@ -1100,15 +1031,15 @@ function start() { // Initialize form updateSelection("allowed-locations", 1); updateSelection("allowed-locations-2", 1); - var advanced = document.getElementById("advanced"); + let advanced = document.getElementById("advanced"); if (advancedMode) { advanced.classList.remove('hidden'); document.getElementById("hide-advanced").innerHTML = "Hide"; } - for (var i = 0; i < flags.length; i += 3) { - for (var j = 0; j < 3; j++) { - var checkDesc = false; - var newLabel = document.createElement("label"); + for (let i = 0; i < flags.length; i += 3) { + for (let j = 0; j < 3; j++) { + let checkDesc = false, + newLabel = document.createElement("label"); newLabel.setAttribute("for", "sav-flag-" + (i + j)); newLabel.innerHTML = "[" + (i + j) + "] " + flags[i + j][0]; if (typeof flags[i + j][1] === "string") { @@ -1128,14 +1059,14 @@ function start() { advanced.appendChild(newLabel); } - for (var j = 0; j < 3; j++) { - var newField; + for (let j = 0; j < 3; j++) { + let newField; if (typeof flags[i + j][2] === "object") { // Options listed newField = document.createElement("select"); - for (var key of Object.keys(flags[i + j][2]).sort((a, b) => a - b)) { // (Decimal keys don't automatically sort correctly) - var newOption = document.createElement("option"); + for (const key of Object.keys(flags[i + j][2]).sort((a, b) => a - b)) { // (Decimal keys don't automatically sort correctly) + let newOption = document.createElement("option"), + newContent = document.createTextNode(flags[i + j][2][key]); newOption.setAttribute("value", key); - var newContent = document.createTextNode(flags[i + j][2][key]); newOption.appendChild(newContent); newField.appendChild(newOption); } @@ -1148,12 +1079,14 @@ function start() { newField = document.createElement("div"); newField.setAttribute("class", "checkbox"); newField.style.marginTop = 0; - var newOption = document.createElement("input"); + + let newOption = document.createElement("input"); newOption.setAttribute("type", "checkbox"); newOption.addEventListener("change", function() { this.nextSibling.value = Number(this.checked); }); newField.appendChild(newOption); + newOption = document.createElement("input"); newOption.setAttribute("type", "number"); newOption.addEventListener("change", function() { @@ -1176,12 +1109,12 @@ function start() { loadPreset("Ruins Start"); // Selecting a file - var iniFile, saveFile; + let iniFile, saveFile; document.getElementById("ini-file").addEventListener("change", function(evt) { iniFile = evt.target.files[0]; if (iniFile) { document.getElementById("ini-loadbutton").classList.remove('disabled'); - document.querySelector(`label[for="${event.target.id}"]`).style = "border-color: #fff" + document.querySelector(`label[for="${evt.target.id}"]`).style = "border-color: #fff"; } else { document.getElementById("ini-loadbutton").classList.add('disabled'); } @@ -1190,7 +1123,7 @@ function start() { saveFile = evt.target.files[0]; if (saveFile) { document.getElementById("sav-loadbutton").classList.remove('disabled'); - document.querySelector(`label[for="${event.target.id}"]`).style = "border-color: #fff" + document.querySelector(`label[for="${evt.target.id}"]`).style = "border-color: #fff"; } else { document.getElementById("sav-loadbutton").classList.add('disabled'); } @@ -1234,34 +1167,39 @@ function start() { // system_information download document.getElementById("savesi2").addEventListener("click", function() { - var blob = new Blob([], {type: "application/octet-stream"}); - saveAs(blob, "system_information_962", true); + saveAs( + new Blob([], {type: "application/octet-stream"}), + "system_information_962", + true + ); flowey_laugh_once(); }); document.getElementById("savesi3").addEventListener("click", function() { - var blob = new Blob([], {type: "application/octet-stream"}); - saveAs(blob, "system_information_963", true); + saveAs( + new Blob([], {type: "application/octet-stream"}), + "system_information_963", + true + ); flowey_laugh_once(); }); // Weapon/armor AT/DF calculation - var weaponSelect = document.getElementById("sav-weapon"); - var armorSelect = document.getElementById("sav-armor"); + let weaponSelect = document.getElementById("sav-weapon"), + armorSelect = document.getElementById("sav-armor"); weaponSelect.addEventListener("change", function() { - var weaponAt = weaponAts[weaponSelect.value]; - var armorAt = armorAts[armorSelect.value] || 0; // Cowboy Hat, Temmie Armor + const weaponAt = weaponAts[this.value], + armorAt = armorAts[armorSelect.value] || 0; // Cowboy Hat, Temmie Armor if (typeof weaponAt !== "undefined") { document.getElementById("sav-weaponat").value = weaponAt + armorAt; } - }); armorSelect.addEventListener("change", function() { - var df = armorDfs[armorSelect.value]; + const df = armorDfs[this.value]; if (typeof df !== "undefined") { document.getElementById("sav-armordf").value = df; } - var weaponAt = weaponAts[weaponSelect.value]; - var armorAt = armorAts[armorSelect.value] || 0; + const weaponAt = weaponAts[weaponSelect.value], + armorAt = armorAts[this.value] || 0; if (typeof weaponAt !== "undefined") { document.getElementById("sav-weaponat").value = weaponAt + armorAt; } else { @@ -1270,17 +1208,17 @@ function start() { }); // Interface-altering options - var allowedLocations1 = document.getElementById("allowed-locations"); - var allowedLocations2 = document.getElementById("allowed-locations-2"); + let allowedLocations1 = document.getElementById("allowed-locations"), + allowedLocations2 = document.getElementById("allowed-locations-2"); allowedLocations1.addEventListener("change", function() { - allowedLocations2.value = allowedLocations1.value; - updateSelection("ini-location", null, rooms[allowedLocations1.value]); - updateSelection("sav-location", null, rooms[allowedLocations1.value]); + allowedLocations2.value = this.value; + updateSelection("ini-location", null, rooms[this.value]); + updateSelection("sav-location", null, rooms[this.value]); }); allowedLocations2.addEventListener("change", function() { - allowedLocations1.value = allowedLocations2.value; - updateSelection("ini-location", null, rooms[allowedLocations1.value]); - updateSelection("sav-location", null, rooms[allowedLocations1.value]); + allowedLocations1.value = this.value; + updateSelection("ini-location", null, rooms[this.value]); + updateSelection("sav-location", null, rooms[this.value]); }); document.getElementById("allow-non-equipables").addEventListener("change", function() { if (document.getElementById("allow-non-equipables").checked) { @@ -1300,7 +1238,7 @@ function start() { } else { cellOpts[210] = "Papyrus's Phone"; } - for (var i = 1; i <= 8; i++) { + for (let i = 1; i <= 8; i++) { updateSelection("sav-cellslot" + i); } }); @@ -1310,29 +1248,28 @@ function start() { // Presets document.getElementById("builtinpresetload").addEventListener("click", function() { - var name = document.getElementById("builtinpresetselect").value; - loadPreset(name); + loadPreset(this.value); }); function saveUserPreset(name) { updateIniFromForm(ini); updateSaveValuesFromForm(saveLines); - var obj = { + let obj = { "ini": ini, "lines": saveLines, - }; - var presets = JSON.parse(localStorage.getItem("userPresets")); + }, + presets = JSON.parse(localStorage.getItem("userPresets")); presets[name] = obj; - localStorage.setItem("userPresets",JSON.stringify(presets)); + localStorage.setItem("userPresets", JSON.stringify(presets)); } document.getElementById("userpresetnew").addEventListener("click", function() { - var name = window.prompt("Enter the name for your new preset"); + const name = window.prompt("Enter the name for your new preset"); if (name === null || name === "") { window.alert("You did not enter a valid name, preset not created."); } else { saveUserPreset(name); - var presetSelect = document.getElementById("userpresetselect"); - var option = document.createElement("option"); - var text = document.createTextNode(name); + let presetSelect = document.getElementById("userpresetselect"), + option = document.createElement("option"), + text = document.createTextNode(name); option.appendChild(text); presetSelect.appendChild(option); presetSelect.value = name; @@ -1343,7 +1280,7 @@ function start() { } }); document.getElementById("userpresetsave").addEventListener("click", function() { - var name = document.getElementById("userpresetselect").value; + const name = document.getElementById("userpresetselect").value; if (name !== null && name !== "") { saveUserPreset(name); } else { @@ -1351,11 +1288,11 @@ function start() { } }); document.getElementById("userpresetload").addEventListener("click", function() { - var name = document.getElementById("userpresetselect").value; + const name = document.getElementById("userpresetselect").value; if (name !== null && name !== "") { - var item = localStorage.getItem("userPresets"); - var presets = JSON.parse(item); - var obj = presets[name]; + let item = localStorage.getItem("userPresets"), + presets = JSON.parse(item), + obj = presets[name]; ini = obj.ini; saveLines = obj.lines; updateSaveDataForm(saveLines); @@ -1365,17 +1302,17 @@ function start() { } }); document.getElementById("userpresetdelete").addEventListener("click", function() { - var selection = document.getElementById("userpresetselect"); - var name = selection.value; - var children = selection.childNodes; - for (var i = 0; i < children.length; i++) { + let selection = document.getElementById("userpresetselect"), + name = selection.value, + children = selection.childNodes; + for (let i = 0; i < children.length; i++) { if (children[i].value === name) { selection.removeChild(children[i]); break; } } - var item = localStorage.getItem("userPresets"); - var presets = JSON.parse(item); + let item = localStorage.getItem("userPresets"), + presets = JSON.parse(item); delete presets[name]; localStorage.setItem("userPresets", JSON.stringify(presets)); if (document.getElementById("userpresetselect").value === "") { @@ -1392,17 +1329,20 @@ function start() { document.getElementById("userpresetexport").classList.remove('disabled'); } document.getElementById("userpresetexport").addEventListener("click", function() { - var presets = JSON.parse(localStorage.getItem("userPresets")); - var name = document.getElementById("userpresetselect").value; + let presets = JSON.parse(localStorage.getItem("userPresets")), + name = document.getElementById("userpresetselect").value; saveUserPreset(name); - var preset = presets[name]; - var string = "presets[\"" + name + "\"] = " + JSON.stringify(preset) + ";"; - var blob = new Blob([string], {type: "application/octet-stream"}); - saveAs(blob, name + ".js", true); + const preset = presets[name], + string = "presets[\"" + name + "\"] = " + JSON.stringify(preset) + ";"; + saveAs( + new Blob([string], {type: "application/octet-stream"}), + name + ".js", + true + ); }); document.getElementById("floweyimg").addEventListener("click", function() { - document.getElementById("floweyimg").src = "res/flowey_wink.png"; + this.src = "res/flowey_wink.png"; localStorage.setItem("laughed", false); }); document.getElementById("hide-advanced").addEventListener("click", function() { @@ -1419,8 +1359,8 @@ function start() { } }); - var saveElements = document.querySelectorAll("input[id^=\"sav-\"],select[id^=\"sav-\"]"); - for (var i = 0; i < saveElements.length; i++) { + let saveElements = document.querySelectorAll("input[id^=\"sav-\"],select[id^=\"sav-\"]"); + for (let i = 0; i < saveElements.length; i++) { if (flagFor[saveElements[i].id] >= 0) { saveElements[i].addEventListener("change", function() { if (this.type == "checkbox") { @@ -1431,7 +1371,7 @@ function start() { }); } else if (inputForFlag[saveElements[i].id]) { saveElements[i].addEventListener("change", function() { - var targetElement = document.getElementById(inputForFlag[this.id]); + let targetElement = document.getElementById(inputForFlag[this.id]); if (targetElement.type == "checkbox") { targetElement.checked = Number(this.value); } else if (targetElement.type == "number") { From 9753395d3f58499094eb873e99de57b44b523af5 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Mon, 8 Nov 2021 16:48:55 -0500 Subject: [PATCH 10/14] correct offset in exporting flags whoops --- main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 802c053..a584886 100644 --- a/main.js +++ b/main.js @@ -902,7 +902,7 @@ function updateSaveDataForm(values) { } else { document.getElementById("sav-flag-" + i).value = values[30 + i]; // Update checkboxes (should have no ill effects on non-checkbox-based flags) - document.getElementById("sav-flag-" + i).previousSibling.checked = Number(document.getElementById("sav-flag-" + i).value); + document.getElementById("sav-flag-" + i).previousSibling.checked = Number(values[30 + i]); } } @@ -942,9 +942,9 @@ function updateSaveValuesFromForm(values) { for (const id in flagFor) { if (document.getElementById(id).type === "checkbox") { - values[flagFor[id]] = document.getElementById(id).checked ? "1" : "0"; + values[30 + flagFor[id]] = document.getElementById(id).checked ? "1" : "0"; } else { - values[flagFor[id]] = document.getElementById(id).value; + values[30 + flagFor[id]] = document.getElementById(id).value; } } From ec2f6946cb0a906eca298174c1833a6ca15e793b Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Mon, 8 Nov 2021 17:11:13 -0500 Subject: [PATCH 11/14] [m] keep save file type whoops x(like 5 or something that's a code moment) --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index a584886..c4c5fbc 100644 --- a/main.js +++ b/main.js @@ -985,7 +985,7 @@ function saveSaveValuesToFile(values, slot) { } saveAs( - new Blob([string], {type: "text/plain;charset=utf-8"}), + new Blob([string], {type: "application/octet-stream"}), "file" + slot, true ); From 972e2547cc32eb846dd3e6521a21149db695bf24 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Mon, 15 Nov 2021 18:10:49 -0500 Subject: [PATCH 12/14] rm nested functions; working on loadPreset failure --- main.js | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/main.js b/main.js index c4c5fbc..b83d004 100644 --- a/main.js +++ b/main.js @@ -1003,6 +1003,26 @@ function loadPresetSelect() { } } +function loadPreset(name) { + console.log("Loading preset: " + name); + let ini = presets[name].ini, + saveLines = presets[name].lines; + updateSaveDataForm(saveLines); + updatePersistentDataForm(ini); +} + +function saveUserPreset(name) { + updateIniFromForm(ini); + updateSaveValuesFromForm(saveLines); + let obj = { + "ini": ini, + "lines": saveLines, + }, + presets = JSON.parse(localStorage.getItem("userPresets")); + presets[name] = obj; + localStorage.setItem("userPresets", JSON.stringify(presets)); +} + function start() { "use strict"; let userPresets = localStorage.getItem("userPresets"), @@ -1021,13 +1041,7 @@ function start() { if (localStorage.getItem("laughed") === "true") { document.getElementById("floweyimg").src = "res/flowey_evil.png"; } - let ini, saveLines; - function loadPreset(name) { - ini = presets[name].ini; - saveLines = presets[name].lines; - updateSaveDataForm(saveLines); - updatePersistentDataForm(ini); - } + // Initialize form updateSelection("allowed-locations", 1); updateSelection("allowed-locations-2", 1); @@ -1250,17 +1264,7 @@ function start() { document.getElementById("builtinpresetload").addEventListener("click", function() { loadPreset(this.value); }); - function saveUserPreset(name) { - updateIniFromForm(ini); - updateSaveValuesFromForm(saveLines); - let obj = { - "ini": ini, - "lines": saveLines, - }, - presets = JSON.parse(localStorage.getItem("userPresets")); - presets[name] = obj; - localStorage.setItem("userPresets", JSON.stringify(presets)); - } + document.getElementById("userpresetnew").addEventListener("click", function() { const name = window.prompt("Enter the name for your new preset"); if (name === null || name === "") { From b4eceee369d1eeb6ec50002c0f99abf6afa1f837 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Mon, 15 Nov 2021 18:16:30 -0500 Subject: [PATCH 13/14] rv over-zealous "this"ing one major problem, down. Gonna keep testing. --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index b83d004..f4195ae 100644 --- a/main.js +++ b/main.js @@ -1262,7 +1262,7 @@ function start() { // Presets document.getElementById("builtinpresetload").addEventListener("click", function() { - loadPreset(this.value); + loadPreset(document.getElementById("builtinpresetselect").value); }); document.getElementById("userpresetnew").addEventListener("click", function() { From 579f55fe969bb309474a2084c41223c80fe685a7 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Mon, 15 Nov 2021 18:32:11 -0500 Subject: [PATCH 14/14] global ini + saveLines to fix saving presets --- main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index f4195ae..2619eaa 100644 --- a/main.js +++ b/main.js @@ -1003,10 +1003,12 @@ function loadPresetSelect() { } } +let ini, saveLines; + function loadPreset(name) { console.log("Loading preset: " + name); - let ini = presets[name].ini, - saveLines = presets[name].lines; + ini = presets[name].ini; + saveLines = presets[name].lines; updateSaveDataForm(saveLines); updatePersistentDataForm(ini); }