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-09 00:00:09 +00:00
However, if you're creative, you can use them for basically anything. "canAfford()" is effectively "canClick()" and "buy()" is effectively "onClick()".
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
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
11: {
2020-10-03 19:45:47 +00:00
desc:() => "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-10 03:16:29 +00:00
- cost(): cost for buying xth buyable, can be 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-01 05:30:59 +00:00
for having x of this buyable. Can return a value or an object containing multiple values.
- display(): A function returning everything that should be displayed on the rebuyable 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
- unl(): A function returning a bool to determine if the buyable is visible or not.
- canAfford(): A function returning a bool to determine if you can buy one of the buyables.
- buy(): A function that implements buying one of the buyable.
2020-10-03 19:45:47 +00:00
- buyMax(): **optional** , A function that implements buying as many of the buyable as possible.
2020-10-10 03:26:27 +00:00
- style: **Optional** , A CSS object, which affects this buyable.
2020-10-07 20:41:45 +00:00
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
- id: **Assigned automagically** . It's the id for this buyable.