From 58f181e70fd8478a8880c2169a72c5b91360a312 Mon Sep 17 00:00:00 2001 From: Acamaeda Date: Sat, 17 Oct 2020 17:04:38 -0400 Subject: [PATCH] Added more capabilities in mod.js and fixed a number format issue --- changelog.md | 5 +++++ index.html | 30 ++++++++++++++++-------------- js/mod.js | 14 +++++++++++++- js/temp.js | 14 ++++++++++---- js/utils.js | 17 ++++++++++++++--- 5 files changed, 58 insertions(+), 22 deletions(-) diff --git a/changelog.md b/changelog.md index 027d197..f683093 100644 --- a/changelog.md +++ b/changelog.md @@ -1,9 +1,14 @@ # The Modding Tree changelog: +## v2.1: Non-nonsensical - 10/x/20 - Moved most of the code users will want to edit to mod.js. - Added getStartPoints() +- Added the ability to store non-layer-related data +- Added the ability to display more things at the top of the tree tab below points. - Added "sell one" and "sell all" buttons for buyables. - Fixed issues with version number +- Fixed number formatting issue making things like "10e9" appear. + ### v2.0.5 - 10/16/20 - Made more features (including prestige parameters) able to be dynamic. diff --git a/index.html b/index.html index e9438ba..34f519e 100644 --- a/index.html +++ b/index.html @@ -85,7 +85,7 @@ - + @@ -111,6 +111,7 @@ {{modInfo.pointsName}}
({{format(getPointGen())}}/sec) +
@@ -121,21 +122,22 @@




@@ -145,7 +147,7 @@
-
+



@@ -157,7 +159,7 @@ Your best {{tmp[layer].resource}} is {{formatWhole(player[layer].best)}}
You have made a total of {{formatWhole(player[layer].total)}} {{tmp[layer].resource}}
-
+
@@ -167,7 +169,7 @@

-
+
diff --git a/js/mod.js b/js/mod.js index 0f0f62a..ec83bec 100644 --- a/js/mod.js +++ b/js/mod.js @@ -15,7 +15,8 @@ let VERSION = { name: "Non-nonsensical!", } -// Add the names of functions that do something when you call them here. (The ones here are examples) +// If you add new functions anywhere inside of a layer, and those functions have an effect when called, add them here. +// (The ones here are examples, all official functions are already taken care of) var doNotCallTheseFunctionsEveryTick = ["doReset", "buy", "onPurchase", "blowUpEverything"] function getStartPoints(){ @@ -37,7 +38,18 @@ function getPointGen() { return gain } +// You can add non-layer related variables that should to into "player" and be saved here, along with default values +function addedPlayerData() { return { + weather: "Yes", + happiness: new Decimal(72), +}} +// Display extra things at the top of the page +var displayThings = [ + function() {if (player.points.eq(69)) return "Tee hee!"}, + function() {if (player.f.points.gt(1)) return `You have ${player.f.points} farm points. (Which do nothing.)`}, + function() {if (inChallenge("c", 11)) return "The game is currently

0%

harder."}, +] // Less important things beyond this point! diff --git a/js/temp.js b/js/temp.js index 8bc1fac..9ee51c3 100644 --- a/js/temp.js +++ b/js/temp.js @@ -14,8 +14,10 @@ for (item in noCall) { function setupTemp() { tmp = {} - setupTempData(layers, tmp) + tmp.pointGen = {} + tmp.displayThings = [] + setupTempData(layers, tmp) for (layer in layers){ tmp[layer].resetGain = {} tmp[layer].nextAt = {} @@ -28,9 +30,6 @@ function setupTemp() { } function setupTempData(layerData, tmpData) { - tmp.pointGen = {} - - for (item in layerData){ if (layerData[item] == null) { tmpData[item] = null @@ -70,6 +69,13 @@ function updateTemp() { } tmp.pointGen = getPointGen() + tmp.displayThings = [] + for (thing in displayThings){ + let text = displayThings[thing] + if (isFunction(text)) text = text() + tmp.displayThings.push(text) + } + } function updateTempData(layerData, tmpData) { diff --git a/js/utils.js b/js/utils.js index f22cd2d..a380a08 100644 --- a/js/utils.js +++ b/js/utils.js @@ -3,7 +3,11 @@ function exponentialFormat(num, precision) { let e = num.log10().floor() let m = num.div(Decimal.pow(10, e)) - return m.toStringWithDecimalPlaces(3)+"e"+e.toStringWithDecimalPlaces(0) + if(m.toStringWithDecimalPlaces(precision) == 10) { + m = new Decimal(1) + e = e.add(1) + } + return m.toStringWithDecimalPlaces(precision)+"e"+e.toStringWithDecimalPlaces(0) } function commaFormat(num, precision) { @@ -34,7 +38,7 @@ function format(decimal, precision=2) { var slog = decimal.slog() if (slog.gte(1e6)) return "F" + format(slog.floor()) else return Decimal.pow(10, slog.sub(slog.floor())).toStringWithDecimalPlaces(3) + "F" + commaFormat(slog.floor(), 0) - } else if (decimal.gte("1e1000")) return (Math.floor(decimal.mantissa + 0.01) + ("e"+formatWhole(decimal.log10().floor()))) + } else if (decimal.gte("1e1000")) return exponentialFormat(decimal, 0) else if (decimal.gte(1e9)) return exponentialFormat(decimal, precision) else if (decimal.gte(1e3)) return commaFormat(decimal, 0) else return commaFormat(decimal, precision) @@ -86,6 +90,11 @@ function startPlayerBase() { function getStartPlayer() { playerdata = startPlayerBase() + extradata = addedPlayerData() + + for (thing in extradata) + playerdata[thing] = extradata[thing] + for (layer in layers){ playerdata[layer] = layers[layer].startData() playerdata[layer].buyables = getStartBuyables(layer) @@ -500,7 +509,9 @@ function clickClickable(layer, id) { // Function to determine if the player is in a challenge function inChallenge(layer, id){ let challenge = player[layer].activeChallenge - if (challenge==toNumber(id)) return true + if (challenge == null) return + id = toNumber(id) + if (challenge==id) return true if (layers[layer].challenges[challenge].countsAs) return tmp[layer].challenges[id].countsAs.includes(id)