diff --git a/changelog.md b/changelog.md index fcbd38d..322e668 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,7 @@ # The Modding Tree changelog: +- If an upgrade has both canAfford and cost, it checks both. + ## v2.6.0.1 - 6/4/21 - Removed excess NaN alerts (now only checks player, not temp). - Fixed background images covering up tree branches. diff --git a/docs/upgrades.md b/docs/upgrades.md index 3642e09..74f48fb 100644 --- a/docs/upgrades.md +++ b/docs/upgrades.md @@ -35,7 +35,7 @@ Individual upgrades can have these features: - fullDisplay(): **OVERRIDE**. Overrides the other displays and descriptions, and lets you set the full text for the upgrade. Can use basic HTML. -- cost: A Decimal for the cost of the upgrade. By default, upgrades cost the main prestige currency for the layer. +- cost: **sort of optional** A Decimal for the cost of the upgrade. By default, upgrades cost the main prestige currency for the layer. - unlocked(): **optional**. A function returning a bool to determine if the upgrade is visible or not. Default is unlocked. @@ -57,10 +57,12 @@ By default, upgrades use the main prestige currency for the layer. You can inclu - currencyLocation: **optional**. If your currency is stored in something inside a layer (e.g. a buyable's amount), you can access it this way. This is a function returning the object in "player" that contains the value (like `player[this.layer].buyables`) -If you want to do something more complicated like upgrades that cost two currencies, you can override the purchase system with these (and you need to use fullDisplay as well) +If you want to do something more complicated like upgrades that cost two currencies, or have extra requirements, you can override the purchase system with these. (and you need to use fullDisplay if you don't use "cost") -- canAfford(): **OVERRIDE**, a function determining if you are able to buy the upgrade +- canAfford(): **OVERRIDE**, a function determining if you are able to buy the upgrade. (If you also have a cost, it will check both the cost and this function) - pay(): **OVERRIDE**, a function that reduces your currencies when you buy the upgrade + + - branches: **optional**, This is primarially useful for upgrade trees. An array of upgrade ids. A line will appear from this upgrade to all of the upgrades in the list. Alternatively, an entry in the array can be a 2-element array consisting of the upgrade id and a color value. The color value can either be a string with a hex color code, or a number from 1-3 (theme-affected colors). \ No newline at end of file diff --git a/js/Demo/demoMod.js b/js/Demo/demoMod.js index 18f8fc9..8f8e528 100644 --- a/js/Demo/demoMod.js +++ b/js/Demo/demoMod.js @@ -11,7 +11,7 @@ let modInfo = { // Set your version in num and name let VERSION = { - num: "2.6", + num: "2.6.0.1", name: "Fixed Reality", } diff --git a/js/utils.js b/js/utils.js index 3d99cb8..76e2619 100644 --- a/js/utils.js +++ b/js/utils.js @@ -12,9 +12,12 @@ function respecBuyables(layer) { function canAffordUpgrade(layer, id) { let upg = tmp[layer].upgrades[id] if(tmp[layer].deactivated) return false - if (tmp[layer].upgrades[id].canAfford !== undefined) return tmp[layer].upgrades[id].canAfford + if (tmp[layer].upgrades[id].canAfford === false) return false let cost = tmp[layer].upgrades[id].cost - return canAffordPurchase(layer, upg, cost) + if (cost !== undefined) + return canAffordPurchase(layer, upg, cost) + + return true } function canBuyBuyable(layer, id) { @@ -25,7 +28,6 @@ function canBuyBuyable(layer, id) { function canAffordPurchase(layer, thing, cost) { - if (thing.currencyInternalName) { let name = thing.currencyInternalName if (thing.currencyLocation) {