1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-23 17:01:47 +00:00

canAfford and cost can work together

This commit is contained in:
Harley White 2021-06-05 12:26:24 -04:00
parent 4bc8b7712a
commit 93b0fee963
4 changed files with 13 additions and 7 deletions

View file

@ -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.

View file

@ -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).

View file

@ -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",
}

View file

@ -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) {