Skip to content

Commit 52f3af1

Browse files
committed
settings in the module
1 parent 2fccb8c commit 52f3af1

File tree

4 files changed

+28
-46
lines changed

4 files changed

+28
-46
lines changed

src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,26 @@ import com.lambda.gui.dsl.ImGuiBuilder
2121
import com.lambda.module.HudModule
2222
import com.lambda.module.tag.ModuleTag
2323
import imgui.ImGui
24-
import imgui.type.ImBoolean
2524
import java.awt.Color
2625
import java.util.*
2726

28-
class DebugLogger(name: String, description: String) : HudModule(
29-
name, description, ModuleTag.HUD
30-
) {
27+
abstract class DebugLogger(name: String, description: String) : HudModule(name, description, ModuleTag.HUD) {
3128
private val logs = LinkedList<LogEntry>()
32-
private var maxLogEntries: Int = 100
3329

34-
private val autoScroll = ImBoolean(true)
35-
private val wrapText = ImBoolean(false)
36-
private val showDebug = ImBoolean(true)
37-
private val showSuccess = ImBoolean(true)
38-
private val showWarning = ImBoolean(true)
39-
private val showError = ImBoolean(true)
30+
private val autoScroll by setting("Auto-Scroll", true, "Automatically scrolls to the bottom of the log")
31+
private val wrapText by setting("Wrap Text", false, "Wraps the text to the next line if it gets too long")
32+
private val showDebug by setting("Show Debug", true, "Shows debug logs")
33+
private val showSuccess by setting("Show Success", true, "Shows success logs")
34+
private val showWarning by setting("Show Warning", true, "Shows warning logs")
35+
private val showError by setting("Show Errors", true, "Shows error logs")
36+
private val maxLogEntries by setting("Max Log Entries", 100, 1..1000, 1, "Maximum amount of entries in the log")
37+
.onValueChange { from, to ->
38+
if (to < from) {
39+
while(logs.size > to) {
40+
logs.removeFirst()
41+
}
42+
}
43+
}
4044

4145
private fun log(message: String, logColor: LogType) {
4246
logs.add(LogEntry(message, logColor))
@@ -51,22 +55,8 @@ class DebugLogger(name: String, description: String) : HudModule(
5155
fun error(message: String) = log(message, LogType.Error)
5256

5357
override fun ImGuiBuilder.buildLayout() {
54-
checkbox("Auto-scroll", autoScroll)
55-
sameLine()
56-
checkbox("Wrap Text", wrapText)
57-
sameLine()
58-
checkbox("Debug", showDebug)
59-
sameLine()
60-
checkbox("Info", showSuccess)
61-
sameLine()
62-
checkbox("Warn", showWarning)
63-
sameLine()
64-
checkbox("Error", showError)
65-
66-
separator()
67-
6858
child("Log Content") {
69-
if (wrapText.get()) ImGui.pushTextWrapPos()
59+
if (wrapText) ImGui.pushTextWrapPos()
7060

7161
logs.forEach { logEntry ->
7262
if (shouldDisplay(logEntry)) {
@@ -82,9 +72,9 @@ class DebugLogger(name: String, description: String) : HudModule(
8272
}
8373
}
8474

85-
if (wrapText.get()) ImGui.popTextWrapPos()
75+
if (wrapText) ImGui.popTextWrapPos()
8676

87-
if (autoScroll.get()) {
77+
if (autoScroll) {
8878
ImGui.setScrollHereY(1f)
8979
}
9080
}
@@ -94,10 +84,10 @@ class DebugLogger(name: String, description: String) : HudModule(
9484

9585
fun shouldDisplay(logEntry: LogEntry) =
9686
when (logEntry.type) {
97-
LogType.Debug -> showDebug.get()
98-
LogType.Success -> showSuccess.get()
99-
LogType.Warning -> showWarning.get()
100-
LogType.Error -> showError.get()
87+
LogType.Debug -> showDebug
88+
LogType.Success -> showSuccess
89+
LogType.Warning -> showWarning
90+
LogType.Error -> showError
10191
}
10292

10393
fun clear() = logs.clear()

src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ object ManagerUtils {
2424
val managers = getInstances<RequestHandler<*>>()
2525
val accumulatedManagerPriority = managers.map { it.stagePriority }.reduce { acc, priority -> acc + priority }
2626
val positionBlockingManagers = getInstances<PositionBlocking>()
27-
val loggingManagers = getInstances<Logger>()
2827

2928
fun isPosBlocked(pos: BlockPos) =
3029
positionBlockingManagers.any { manager -> manager.blockedPositions.any { blocked -> blocked == pos } }

src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ object BreakManager : RequestHandler<BreakRequest>(
105105
TickEvent.Player.Post,
106106
onOpen = { processRequest(activeRequest); simulateAbandoned() },
107107
onClose = { checkForCancels() }
108-
), PositionBlocking, Logger by BreakManagerDebug {
108+
), PositionBlocking, Logger {
109109
private val breakInfos = arrayOfNulls<BreakInfo>(2)
110110

111111
private val activeInfos
@@ -165,6 +165,8 @@ object BreakManager : RequestHandler<BreakRequest>(
165165
field = value
166166
}
167167

168+
override val logger = BreakManagerDebug
169+
168170
fun Any.onBreak(
169171
alwaysListen: Boolean = false,
170172
priority: Int = 0,

src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,9 @@
1717

1818
package com.lambda.module.hud
1919

20-
import com.lambda.gui.dsl.ImGuiBuilder
2120
import com.lambda.interaction.request.DebugLogger
22-
import com.lambda.interaction.request.Logger
23-
import com.lambda.module.HudModule
24-
import com.lambda.module.tag.ModuleTag
2521

26-
object BreakManagerDebug : HudModule(
22+
object BreakManagerDebug : DebugLogger(
2723
"Break Manager Logger",
28-
"Logs most of the actions performed in the break manager to aid in debugging",
29-
ModuleTag.HUD
30-
), Logger {
31-
override val logger = DebugLogger(name, description)
32-
33-
override fun ImGuiBuilder.buildLayout() = with(logger) { buildLayout() }
34-
}
24+
"Logs most of the actions performed in the break manager to aid in debugging"
25+
)

0 commit comments

Comments
 (0)