@@ -2,7 +2,13 @@ package com.lambda.util
22
33import com.lambda.Lambda
44import com.lambda.Lambda.mc
5- import com.lambda.threading.runOnGameThread
5+ import com.lambda.command.CommandManager
6+ import com.lambda.command.LambdaCommand
7+ import com.lambda.config.Configuration
8+ import com.lambda.event.EventFlow
9+ import com.lambda.module.Module
10+ import com.lambda.module.ModuleRegistry
11+ import com.lambda.module.modules.client.GuiSettings
612import com.lambda.threading.runSafe
713import com.lambda.threading.runSafeOnGameThread
814import com.lambda.util.StringUtils.capitalize
@@ -73,23 +79,15 @@ object Communication {
7379 ) = buildText {
7480 text(logLevel.prefix())
7581
76- // if (this@source is LambdaCommand) {
77- // styled(color, italic = true) {
78- // literal("Command ")
79- // }
80- // }
81- //
82- // if (this@source is Module) {
83- // styled(color, italic = true) {
84- // literal("Module ")
85- // }
86- // }
87- //
88- // // ToDo: HUD elements
89- //
90- if (this @source is Nameable ) {
91- styled(color, italic = true ) {
92- literal(" ${name.capitalize()} " )
82+ // ToDo: HUD elements
83+
84+ when (this @source) {
85+ is LambdaCommand -> commandSource(this @source, color)
86+ is Module -> moduleSource(this @source, color)
87+ is Nameable -> {
88+ styled(color, italic = true ) {
89+ literal(" ${name.capitalize()} " )
90+ }
9391 }
9492 }
9593
@@ -104,14 +102,95 @@ object Communication {
104102 }
105103 }
106104
105+ private fun TextBuilder.commandSource (command : LambdaCommand , color : Color ) {
106+ hoverEvent(HoverEvents .showText(buildText {
107+ literal(command.description)
108+ literal(" \n " )
109+ literal(command.usage)
110+ literal(" \n " )
111+ literal(" Aliases: " )
112+ joinToText(command.aliases) {
113+ color(GuiSettings .primaryColor) {
114+ literal(it)
115+ }
116+ }
117+ })) {
118+ styled(color, italic = true ) {
119+ literal(" ${command.name.capitalize()} " )
120+ }
121+ }
122+ }
123+
124+ private fun TextBuilder.moduleSource (module : Module , color : Color ) {
125+ hoverEvent(HoverEvents .showText(buildText {
126+ literal(module.description)
127+ literal(" \n " )
128+ literal(" Keybind: " )
129+ color(GuiSettings .primaryColor) {
130+ literal(module.keybind.key.toString())
131+ }
132+ literal(" \n " )
133+ literal(" Default tags: " )
134+ joinToText(module.defaultTags) {
135+ color(GuiSettings .primaryColor) {
136+ literal(it.name)
137+ }
138+ }
139+ if (module.customTags.value.isNotEmpty()) {
140+ literal(" \n " )
141+ literal(" Custom tags: " )
142+ joinToText(module.customTags.value) {
143+ color(GuiSettings .primaryColor) {
144+ literal(it.name)
145+ }
146+ }
147+ }
148+ })) {
149+ styled(color, italic = true ) {
150+ literal(" ${module.name.capitalize()} " )
151+ }
152+ }
153+ }
154+
107155 private fun LogLevel.prefix () =
108156 buildText {
109- styled(logoColor) {
110- literal(Lambda .SYMBOL )
157+ hoverEvent(HoverEvents .showText(buildText {
158+ literal(" Lambda " )
159+ color(logoColor) {
160+ literal(Lambda .SYMBOL )
161+ }
162+ literal(" v${Lambda .VERSION } \n " )
163+ literal(" Modules: ${ModuleRegistry .modules.size} \n " )
164+ literal(" Commands: ${CommandManager .commands.size} \n " )
165+ literal(" Settings: ${Configuration .configurations.sumOf { config ->
166+ config.configurables.sumOf { it.settings.size }
167+ }} " )
168+ literal(" \n " )
169+ literal(" Synchronous listeners: ${EventFlow .syncListeners.size} \n " )
170+ literal(" Concurrent listeners: ${EventFlow .concurrentListeners.size} " )
171+
172+ })) {
173+ styled(logoColor) {
174+ literal(Lambda .SYMBOL )
175+ }
176+ literal(" " )
111177 }
112- literal( " " )
178+
113179 }
114180
181+ fun <T > TextBuilder.joinToText (
182+ elements : Collection <T >,
183+ separator : String = ", ",
184+ action : TextBuilder .(T ) -> Unit
185+ ) {
186+ elements.forEachIndexed { index, element ->
187+ if (index != 0 ) {
188+ literal(separator)
189+ }
190+ action(element)
191+ }
192+ }
193+
115194 enum class LogLevel (
116195 val logoColor : Color ,
117196 private val messageColor : Color ,
0 commit comments