2020-10-01 05:30:59 +00:00
|
|
|
# Buyables
|
|
|
|
|
2020-10-09 00:00:09 +00:00
|
|
|
Buyables are usually things that can be bought multiple times with scaling costs. If you set a respec function,
|
2020-10-01 05:30:59 +00:00
|
|
|
the player can reset the purchases to get their currency back.
|
|
|
|
|
2020-10-11 20:16:36 +00:00
|
|
|
The amount of a buyable owned is a Decimal.
|
|
|
|
You can get or set the amount of a buyable with getBuyableAmt(layer, id) and setBuyableAmt(layer, id, amt).
|
2020-10-05 21:11:15 +00:00
|
|
|
You can use buyableEffect(layer, id) to get the current effects of a buyable.
|
|
|
|
|
2020-10-01 05:30:59 +00:00
|
|
|
Buyables should be formatted like this:
|
|
|
|
|
2020-10-01 19:57:47 +00:00
|
|
|
```js
|
2020-10-01 05:45:05 +00:00
|
|
|
buyables: {
|
|
|
|
rows: # of rows
|
|
|
|
cols: # of columns
|
2020-10-16 15:39:39 +00:00
|
|
|
respec() {}, //**optional**, implement it to reset things and give back your currency.
|
|
|
|
// Having this function makes a respec button appear
|
|
|
|
respecText:// **optional**, text that appears on the respec button
|
|
|
|
showRespecButton(){} //**optional**, a function determining whether or not to show the button. Defaults to true if absent.
|
2020-10-17 19:50:30 +00:00
|
|
|
sellOneText, sellAllText:// **optional**, text that appears on the "sell one" and "sell all" buttons respectively (if you are using them)
|
2020-10-01 05:45:05 +00:00
|
|
|
11: {
|
2020-10-13 03:28:02 +00:00
|
|
|
display() {return "Blah"},
|
2020-10-01 05:45:05 +00:00
|
|
|
etc
|
|
|
|
}
|
2020-10-01 05:41:25 +00:00
|
|
|
etc
|
|
|
|
}
|
2020-10-01 19:57:47 +00:00
|
|
|
```
|
2020-10-01 05:30:59 +00:00
|
|
|
|
|
|
|
Features:
|
|
|
|
|
|
|
|
- title: **optional**, displayed at the top in a larger font
|
2020-10-03 19:45:47 +00:00
|
|
|
It can also be a function that returns updating text.
|
2020-10-01 05:30:59 +00:00
|
|
|
|
2020-10-11 19:09:30 +00:00
|
|
|
- cost(): cost for buying the next buyable. Can have an optional argument "x" to calculate the cost of the x+1th object,
|
2020-10-13 03:08:19 +00:00
|
|
|
but needs to use "current amount" as a default value for x. (x is a Decimal).
|
|
|
|
Can return an object if there are multiple currencies.
|
2020-10-01 05:30:59 +00:00
|
|
|
|
2020-10-10 03:16:29 +00:00
|
|
|
- effect(): **optional**, A function that calculates and returns the current values of bonuses
|
2020-10-11 19:09:30 +00:00
|
|
|
of this buyable. Can return a value or an object containing multiple values.
|
2020-10-01 05:30:59 +00:00
|
|
|
|
2020-10-11 20:16:36 +00:00
|
|
|
- display(): A function returning everything that should be displayed on the buyable after the title, likely
|
2020-10-07 20:41:45 +00:00
|
|
|
including the description, amount bought, cost, and current effect. Can use basic HTML.
|
2020-10-01 05:30:59 +00:00
|
|
|
|
2020-10-13 03:08:19 +00:00
|
|
|
- unlocked(): **optional**, A function returning a bool to determine if the buyable is visible or not. Default is unlocked.
|
2020-10-01 05:30:59 +00:00
|
|
|
|
|
|
|
- canAfford(): A function returning a bool to determine if you can buy one of the buyables.
|
|
|
|
|
2020-10-13 03:08:19 +00:00
|
|
|
- buy(): A function that implements buying one of the buyable, including spending the currency.
|
2020-10-01 05:30:59 +00:00
|
|
|
|
2020-10-03 19:45:47 +00:00
|
|
|
- buyMax(): **optional**, A function that implements buying as many of the buyable as possible.
|
|
|
|
|
2020-10-13 03:08:19 +00:00
|
|
|
- style: **Optional**, Applies CSS to this buyable, in the form of an object where the keys are CSS attributes,
|
|
|
|
and the values are the values for those attributes (both as strings)
|
|
|
|
|
2020-10-03 19:45:47 +00:00
|
|
|
- layer: **Assigned automagically**. It's the same value as the name of this layer, so you can do player[this.layer].points or similar
|
|
|
|
|
2020-10-13 03:08:19 +00:00
|
|
|
- id: **Assigned automagically**. It's the "key" which the buyable was stored under, for convenient access.
|
2020-10-17 19:50:30 +00:00
|
|
|
The buyable in the example's id is 11.
|
|
|
|
|
|
|
|
Sell One/Sell All:
|
|
|
|
|
|
|
|
Including a sellOne or sellAll function will cause an additional button to appear beneath the buyable.
|
|
|
|
They are functionally identical, but "sell one" appears above "sell all". You can also use them for other things.
|
|
|
|
|
|
|
|
sellOne/sellAll(): **optional**, Called when the button is pressed. The standard use would be to decrease/reset the amount of the buyable,
|
|
|
|
And possibly return some currency to the player.
|
|
|
|
|
|
|
|
canSellOne/canSellAll(): **optional**, booleans determining whether or not to show the buttons. If "canSellOne/All" is absent but
|
|
|
|
"sellOne/All" is present, the appropriate button will always show.
|