From 384269c593452555649d498cfc22abf986486316 Mon Sep 17 00:00:00 2001 From: Harley White Date: Thu, 21 Jan 2021 17:52:09 -0500 Subject: [PATCH] Performance improvements and good tweaks --- changelog.md | 3 +++ docs/challenges.md | 3 ++- js/Demo/demoLayers.js | 21 ++++++++++----------- js/game.js | 8 ++++++-- js/technical/temp.js | 2 +- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/changelog.md b/changelog.md index 3f10b25..6cd0616 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,9 @@ # The Modding Tree changelog: ## v2.3.6 - +- Performance improvements. +- Added support for bulk challenge completions. +- "Best" is updated automatically. - Fixed keeping Decimal values on reset. ## v2.3.5 - 12/21/20 diff --git a/docs/challenges.md b/docs/challenges.md index aa417fb..ae52433 100644 --- a/docs/challenges.md +++ b/docs/challenges.md @@ -34,7 +34,8 @@ Individual Challenges can have these features: - goalDescription: A description of the win condition for the challenge. It can also be a function that returns updating text. Can use basic HTML. (Optional if using the old goal system) -- canComplete(): A function that returns true if you meet the win condition for the challenge. (Optional if using the old goal system) +- canComplete(): A function that returns true if you meet the win condition for the challenge. Returning a number will allow bulk completing the challenge. + (Optional if using the old goal system) - rewardDescription: A description of the reward's effect. *You will also have to implement the effect where it is applied.* It can also be a function that returns updating text. Can use basic HTML. diff --git a/js/Demo/demoLayers.js b/js/Demo/demoLayers.js index a7b6415..8f9050b 100644 --- a/js/Demo/demoLayers.js +++ b/js/Demo/demoLayers.js @@ -17,7 +17,7 @@ addLayer("c", { color: "#4BDC13", requires: new Decimal(10), // Can be a function that takes requirement increases into account resource: "lollipops", // Name of prestige currency - baseResource: "candies", // Name of resource prestige is based on + baseResource: "points", // Name of resource prestige is based on baseAmount() {return player.points}, // Get the current amount of baseResource type: "normal", // normal: cost to gain currency depends on amount gained. static: cost depends on how much you already have exponent: 0.5, // Prestige currency exponent @@ -83,11 +83,10 @@ addLayer("c", { completionLimit: 3, challengeDescription() {return "Makes the game 0% harder
"+challengeCompletions(this.layer, this.id) + "/" + this.completionLimit + " completions"}, unlocked() { return player[this.layer].best.gt(0) }, - goalDescription: 'Have 20 lollipops I guess', - goal: new Decimal("20"), - currencyDisplayName: "lollipops", // Use if using a nonstandard currency - currencyInternalName: "points", // Use if using a nonstandard currency - currencyLayer: this.layer, // Leave empty if not in a layer + goalDescription: 'Have 20 points I guess', + canComplete() { + return player.points.gte(20) + }, rewardEffect() { let ret = player[this.layer].points.add(1).tetrate(0.02) return ret; @@ -108,7 +107,7 @@ addLayer("c", { unlocked() { return player[this.layer].unlocked }, // The upgrade is only visible when this is true }, 12: { - description: "Candy generation is faster based on your unspent Lollipops.", + description: "Point generation is faster based on your unspent Lollipops.", cost: new Decimal(1), unlocked() { return (hasUpgrade(this.layer, 11))}, effect() { // Calculate bonuses from the upgrade. Can return a single value or an object with multiple values @@ -380,7 +379,7 @@ addLayer("f", { color: "#FE0102", requires() {return new Decimal(10)}, resource: "farm points", - baseResource: "candies", + baseResource: "points", baseAmount() {return player.points}, type: "static", exponent: 0.5, @@ -393,7 +392,7 @@ addLayer("f", { branches: ["c"], // When this layer appears, a branch will appear from this layer to any layers here. Each entry can be a pair consisting of a layer id and a color. tooltipLocked() { // Optional, tooltip displays when the layer is locked - return ("This weird farmer dinosaur will only see you if you have at least " + this.requires() + " candies. You only have " + formatWhole(player.points)) + return ("This weird farmer dinosaur will only see you if you have at least " + this.requires() + " points. You only have " + formatWhole(player.points)) }, midsection: [ "blank", ['display-image', 'https://images.beano.com/store/24ab3094eb95e5373bca1ccd6f330d4406db8d1f517fc4170b32e146f80d?auto=compress%2Cformat&dpr=1&w=390'], @@ -401,8 +400,8 @@ addLayer("f", { ], // The following are only currently used for "custom" Prestige type: prestigeButtonText() { //Is secretly HTML - if (!this.canBuyMax()) return "Hi! I'm a weird dinosaur and I'll give you a Farm Point in exchange for all of your candies and lollipops! (At least " + formatWhole(tmp[this.layer].nextAt) + " candies)" - if (this.canBuyMax()) return "Hi! I'm a weird dinosaur and I'll give you " + formatWhole(tmp[this.layer].resetGain) + " Farm Points in exchange for all of your candies and lollipops! (You'll get another one at " + formatWhole(tmp[layer].nextAtDisp) + " candies)" + if (!this.canBuyMax()) return "Hi! I'm a weird dinosaur and I'll give you a Farm Point in exchange for all of your points and lollipops! (At least " + formatWhole(tmp[this.layer].nextAt) + " points)" + if (this.canBuyMax()) return "Hi! I'm a weird dinosaur and I'll give you " + formatWhole(tmp[this.layer].resetGain) + " Farm Points in exchange for all of your points and lollipops! (You'll get another one at " + formatWhole(tmp[layer].nextAtDisp) + " points)" }, getResetGain() { return getResetGain(this.layer, useType = "static") diff --git a/js/game.js b/js/game.js index d60dc8b..a560763 100644 --- a/js/game.js +++ b/js/game.js @@ -288,13 +288,16 @@ function canCompleteChallenge(layer, x) function completeChallenge(layer, x) { var x = player[layer].activeChallenge if (!x) return - if (! canCompleteChallenge(layer, x)){ + + let completions = canCompleteChallenge(layer, x) + if (!completions){ player[layer].activeChallenge = null return } if (player[layer].challenges[x] < tmp[layer].challenges[x].completionLimit) { needCanvasUpdate = true - player[layer].challenges[x] += 1 + player[layer].challenges[x] += completions + player[layer].challenges[x] = Math.min(player[layer].challenges[x], tmp[layer].challenges[x].completionLimit) if (layers[layer].challenges[x].onComplete) run(layers[layer].challenges[x].onComplete, layers[layer].challenges[x]) } player[layer].activeChallenge = null @@ -362,6 +365,7 @@ function gameLoop(diff) { let layer = OTHER_LAYERS[row][item] if (tmp[layer].autoPrestige && tmp[layer].canReset) doReset(layer); if (layers[layer].automate) layers[layer].automate(); + player[layer].best = player[layer].best.max(player[layer].points) if (layers[layer].autoUpgrade) autobuyUpgrades(layer) } } diff --git a/js/technical/temp.js b/js/technical/temp.js index 535563e..ead0c8e 100644 --- a/js/technical/temp.js +++ b/js/technical/temp.js @@ -103,7 +103,7 @@ function updateTempData(layerData, tmpData) { else if ((!!layerData[item]) && (layerData[item].constructor === Object) || (typeof layerData[item] === "object") && traversableClasses.includes(layerData[item].constructor.name)){ updateTempData(layerData[item], tmpData[item]) } - else if (isFunction(layerData[item]) && !activeFunctions.includes(item)){ + else if (isFunction(layerData[item]) && !isFunction(tmpData[item])){ let value = layerData[item]() if (value !== value || value === decimalNaN){ if (NaNalert === true || confirm ("Invalid value found in tmp, named '" + item + "'. Please let the creator of this mod know! Would you like to try to auto-fix the save and keep going?")){