Skip to content

Commit bbccf01

Browse files
committed
Module KDoc
1 parent fa50388 commit bbccf01

File tree

1 file changed

+76
-0
lines changed
  • common/src/main/kotlin/com/lambda/module

1 file changed

+76
-0
lines changed

common/src/main/kotlin/com/lambda/module/Module.kt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,83 @@ import com.lambda.event.listener.SafeListener.Companion.listener
77
import com.lambda.module.tag.ModuleTag
88
import com.lambda.util.KeyCode
99
import com.lambda.util.Nameable
10+
import com.lambda.config.AbstractSetting
11+
import com.lambda.config.Configuration
12+
import com.lambda.event.listener.Listener
13+
import com.lambda.event.listener.SafeListener
14+
import com.lambda.event.listener.UnsafeListener
15+
import com.lambda.config.settings.comparable.BooleanSetting
16+
import com.lambda.config.settings.numeric.DoubleSetting
1017

18+
/**
19+
* A [Module] is a feature or tool for the utility mod.
20+
* It represents a [Configurable] component of the mod,
21+
* with its own set of behaviors and properties.
22+
*
23+
* Each [Module] has a [name], which is displayed in-game.
24+
* The [description] of the module is shown when hovering over
25+
* the [ModuleButton] in the GUI and in [Command]s.
26+
* The [Module] can be associated with a [Set] of [ModuleTag]s to allow for
27+
* easier filtering and searching in the GUI.
28+
*
29+
* A [Module] can be activated by a [keybind], represented by a [KeyCode].
30+
* The default [keybind] is the key on which
31+
* the module will be activated by default.
32+
* If a module does not need to be activated by a key (like [ClickGUI]),
33+
* the default [keybind] should not be set (using [KeyCode.Unbound]).
34+
*
35+
* [Module]s are [Configurable] with [settings] (see [AbstractSetting] for all setting types).
36+
* For example, a [BooleanSetting] and a [DoubleSetting] can be defined like this:
37+
* ```kotlin
38+
* private val foo by setting("Foo", true)
39+
* private val bar by setting("Bar", 0.0, 0.1..5.0, 0.1)
40+
* ```
41+
* These settings are persisted in the `lambda/config/modules.json` config file.
42+
* See [ModuleConfig.primary] and [Configuration] for more details.
43+
*
44+
* In the `init` block, you can add triggers like [onEnable], [onDisable], [onToggle] and register [Listener].
45+
* For example:
46+
*
47+
* ```kotlin
48+
* init {
49+
* onEnable { // runs on module activation
50+
* LOG.info("I was enabled!")
51+
* }
52+
*
53+
* listener<TickEvent.Pre> { event -> // runs every game tick
54+
* LOG.info("I'm ${if (foo) "super boring ($bar)" else "boring"}!")
55+
* }
56+
* }
57+
* ```
58+
*
59+
* [Listener]s are only triggered if:
60+
* - [Module] is [isEnabled], otherwise it [isMuted] (see [Muteable])
61+
* - [Module] was configured to [alwaysListening]
62+
* - [Listener] was configured to [Listener.alwaysListen]
63+
*
64+
* For example:
65+
*
66+
* ```kotlin
67+
* listener<KeyPressEvent>(alwaysListen = true) { event ->
68+
* if (event.key == keybind.key) {
69+
* toggle()
70+
* }
71+
* }
72+
* ```
73+
*
74+
* See [SafeListener] and [UnsafeListener] for more details.
75+
*
76+
* @property name The name of the module, displayed in-game.
77+
* @property description The description of the module,
78+
* shown on hover over the module button in the GUI and in commands.
79+
* @property tags The set of [ModuleTag]s associated with the module.
80+
* @property alwaysListening If true, the module's listeners will be triggered even if the module is not enabled.
81+
* @property isEnabledSetting The setting that determines if the module is enabled.
82+
* @property keybindSetting The setting that determines the keybind for the module.
83+
* @property isEnabled The current enabled state of the module.
84+
* @property isMuted If true, the module's listeners will not be triggered.
85+
* @property keybind The current keybind for the module.
86+
* */
1187
abstract class Module(
1288
override val name: String,
1389
val description: String = "",

0 commit comments

Comments
 (0)