From 6cbe54808461fd88f47f95b3b81e9263c80f2eb9 Mon Sep 17 00:00:00 2001 From: Harley White Date: Sat, 25 Jun 2022 19:53:48 -0400 Subject: [PATCH] Improved toValue --- changelog.md | 6 ++++-- docs/custom-tab-layouts.md | 2 +- js/game.js | 2 +- js/utils.js | 11 ++++++++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/changelog.md b/changelog.md index 143ffaf..d6f58b8 100644 --- a/changelog.md +++ b/changelog.md @@ -8,12 +8,14 @@ - Upgrade effectDisplay and grid tooltip no longer display if they return "". - devSpeed can be 0. +- Fixed an issue with text-input not converting types correctly. +- Text-input now goes back to the old value if an invalid value is entered. -# v2.6.6.2 = 9/9/21 +# v2.6.6.2 - 9/9/21 - nodeStyle can now be used to set fonts. -# v2.6.6.1 = 9/8/21 +# v2.6.6.1 - 9/8/21 - Fixed options not updating when new ones are added. # v2.6.6 - 9/7/21 diff --git a/docs/custom-tab-layouts.md b/docs/custom-tab-layouts.md index a20727d..3b00185 100644 --- a/docs/custom-tab-layouts.md +++ b/docs/custom-tab-layouts.md @@ -45,7 +45,7 @@ These are the existing components, but you can create more in [components.js](/j - prestige-button: The button to reset for a currency in this layer. -- text-input: A text input box. The argument is the name of the variable in player[layer] that the input is for, player[layer][argument] +- text-input: A text input box. The argument is the name of the variable in startData/player[layer] that the input is for, player[layer][argument] (Works with strings, numbers, and Decimals!) - slider: Lets the user input a value with a slider. The argument a 3-element array: [name, min, max]. diff --git a/js/game.js b/js/game.js index 3d6d989..78b6edb 100644 --- a/js/game.js +++ b/js/game.js @@ -1,5 +1,5 @@ let gameInfo = { - name: "The ??? Tree", + name: "The ??? Game", id: "mygame", author: "nobody", pointsName: "points", diff --git a/js/utils.js b/js/utils.js index 859ec57..dc31df3 100644 --- a/js/utils.js +++ b/js/utils.js @@ -345,15 +345,20 @@ function isPlainObject(obj) { document.title = gameInfo.name -// Converts a string value to whatever it's supposed to be +// Converts an input value to whatever it's supposed to be function toValue(value, oldValue) { if (oldValue instanceof Decimal) { value = new Decimal (value) - if (checkDecimalNaN(value)) return decimalZero + if (checkDecimalNaN(value)) return oldValue + return value + } + if (typeof oldValue === 'string' ) { + value = value.toString() return value } if (!isNaN(oldValue)) - return parseFloat(value) || 0 + value = parseFloat(value) + if (isNaN(value)) return oldValue return value }