1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-12-04 22:01:31 +00:00
The-Modding-Tree/docs/clickables.md

63 lines
3.6 KiB
Markdown
Raw Normal View History

2020-10-11 20:16:36 +00:00
# Clickables
Clickables are any kind of thing that you can click for an effect. They're a more generalized version of Buyables.
DO NOT USE THESE TO MAKE THINGS THAT YOU CLICK REPEATEDLY FOR A BONUS BECAUSE THOSE ARE AWFUL.
2020-10-26 20:45:22 +00:00
There are several differences between the two. One is that a buyable's saved data is its amount as a `Decimal`, while Clickables store a "state" which can be a number or string, but not `Decimal`, array, or object). Buyables have a number of extra features which you can see on their page. Clickables also have a smaller default size.
2020-10-11 20:16:36 +00:00
Useful functions for dealing with clickables and implementing their effects:
2020-10-26 20:45:22 +00:00
- getClickableState(layer, id): get the state of the clickable the player has
- setClickableState(layer, id, state): set the state of the clickable the player has
2020-10-26 20:45:22 +00:00
- clickableEffect(layer, id): Returns the current effects of the clickable, if any.
2020-10-11 20:16:36 +00:00
Clickables should be formatted like this:
```js
2020-10-26 20:45:22 +00:00
clickables: {
11: {
display() {return "Blah"},
2020-10-11 20:16:36 +00:00
etc
}
2020-10-26 20:45:22 +00:00
etc
}
2020-10-11 20:16:36 +00:00
```
Features:
2020-10-26 20:45:22 +00:00
- title: **optional**. displayed at the top in a larger font. It can also be a function that returns updating text.
2020-10-11 20:16:36 +00:00
2020-10-26 20:45:22 +00:00
- effect(): **optional**. A function that calculates and returns the current values of bonuses of this clickable. Can return a value or an object containing multiple values.
2020-10-11 20:16:36 +00:00
2020-10-26 20:45:22 +00:00
- display(): A function returning everything that should be displayed on the clickable after the title, likely changing based on its state. Can use basic HTML.
2020-10-11 20:16:36 +00:00
2020-10-26 20:45:22 +00:00
- unlocked(): **optional**. A function returning a bool to determine if the clickable is visible or not. Default is unlocked.
2020-10-11 20:16:36 +00:00
- canClick(): A function returning a bool to determine if you can click the clickable.
- onClick(): A function that implements clicking the clickable.
2020-10-11 20:16:36 +00:00
- onHold(): **optional** A function that is called 20x/sec when the button is held for at least 0.25 seconds.
2020-10-26 20:45:22 +00:00
- style: **optional**. Applies CSS to this clickable, in the form of an object where the keys are CSS attributes, and the values are the values for those attributes (both as strings).
2021-05-14 19:32:20 +00:00
- marked: **optional** Adds a mark to the corner of the clickable. If it's "true" it will be a star, but it can also be an image URL.
2021-06-10 04:54:36 +00:00
- tooltip: **optional**. Adds a tooltip to this clickable, appears when it is hovered over. Can use basic HTML. Default is no tooltip. If this returns an empty value, that also disables the tooltip.
2020-10-26 20:45:22 +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 "key" which the clickable was stored under, for convenient access. The clickable in the example's id is 11.
You can also use these features on the clickables object to add a button above all the clickables, for implementing a respec button or similar.
- masterButtonPress(): **optional**. If present, an additional button will appear above the clickables. Pressing it will call this function.
2020-10-11 20:16:36 +00:00
2020-10-26 20:45:22 +00:00
- masterButtonText: **optional**. Text to display on the Master Button.
2020-10-11 20:16:36 +00:00
2021-04-07 18:07:22 +00:00
- showMasterButton(): **optional**. A function determining whether or not to show the button, if masterButtonPress is defined. Defaults to true if absent.
2021-06-07 23:40:34 +00:00
- branches: **optional**, This is primarially useful for clickable trees. An array of clickable ids. A line will appear from this clickable to all of the clickables in the list. Alternatively, an entry in the array can be a 2-element array consisting of the clickable 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). A third element in the array optionally specifies line width.