Skip to content

Commit 61ebb81

Browse files
committed
all individual manager debug logger toggles inside one hud module
1 parent b4afde9 commit 61ebb81

File tree

8 files changed

+131
-77
lines changed

8 files changed

+131
-77
lines changed

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

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,30 @@
1717

1818
package com.lambda.interaction.request
1919

20+
import com.lambda.Lambda.mc
21+
import com.lambda.gui.LambdaScreen
2022
import com.lambda.gui.dsl.ImGuiBuilder
21-
import com.lambda.module.HudModule
22-
import com.lambda.module.tag.ModuleTag
23+
import com.lambda.module.hud.ManagerDebugLoggers.maxLogEntries
2324
import imgui.ImGui
2425
import imgui.flag.ImGuiWindowFlags
26+
import imgui.type.ImBoolean
27+
import imgui.type.ImFloat
2528
import java.awt.Color
2629
import java.util.*
2730

28-
abstract class DebugLogger(
29-
name: String,
30-
description: String
31-
) : HudModule(
32-
name,
33-
description,
34-
ModuleTag.HUD,
35-
customWindow = true
31+
class DebugLogger(
32+
val name: String
3633
) {
37-
private val logs = LinkedList<LogEntry>()
34+
private val autoScroll = ImBoolean(true)
35+
private val wrapText = ImBoolean(true)
36+
private val showDebug = ImBoolean(true)
37+
private val showSuccess = ImBoolean(true)
38+
private val showWarning = ImBoolean(true)
39+
private val showError = ImBoolean(true)
40+
private val showSystem = ImBoolean(true)
41+
private val backgroundAlpha = ImFloat(0.3f)
3842

39-
private val autoScroll by setting("Auto-Scroll", true, "Automatically scrolls to the bottom of the log")
40-
private val wrapText by setting("Wrap Text", false, "Wraps the text to the next line if it gets too long")
41-
private val showDebug by setting("Show Debug", true, "Shows debug logs")
42-
private val showSuccess by setting("Show Success", true, "Shows success logs")
43-
private val showWarning by setting("Show Warning", true, "Shows warning logs")
44-
private val showError by setting("Show Errors", true, "Shows error logs")
45-
private val maxLogEntries by setting("Max Log Entries", 100, 1..1000, 1, "Maximum amount of entries in the log")
46-
.onValueChange { from, to ->
47-
if (to < from) {
48-
while(logs.size > to) {
49-
logs.removeFirst()
50-
}
51-
}
52-
}
53-
private val backgroundAlpha by setting("Background Alpha", 0.3f, 0f..1f, 0.01f, "Sets the opacity for the elements background")
43+
val logs = LinkedList<LogEntry>()
5444

5545
private fun log(message: String, logColor: LogType) {
5646
logs.add(LogEntry(message, logColor))
@@ -65,14 +55,28 @@ abstract class DebugLogger(
6555
fun error(message: String) = log(message, LogType.Error)
6656
fun system(message: String) = log(message, LogType.System)
6757

68-
override fun ImGuiBuilder.buildLayout() {
58+
fun ImGuiBuilder.buildLayout() {
6959
ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY)
70-
ImGui.setNextWindowBgAlpha(backgroundAlpha)
60+
ImGui.setNextWindowBgAlpha(backgroundAlpha.get())
7161
window(name, flags = ImGuiWindowFlags.NoCollapse) {
72-
val noScroll = if (autoScroll) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0
73-
button("Clear") { clear() }
62+
val noScroll = if (autoScroll.get()) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0
63+
if (mc.currentScreen == LambdaScreen) {
64+
checkbox("Auto-Scroll", autoScroll)
65+
sameLine()
66+
checkbox("Warp Text", wrapText)
67+
sameLine()
68+
checkbox("Show Debug", showDebug)
69+
checkbox("Show Success", showSuccess)
70+
sameLine()
71+
checkbox("Show Warning", showWarning)
72+
sameLine()
73+
checkbox("Show Error", showError)
74+
checkbox("Show System", showSystem)
75+
slider("Background Alpha", backgroundAlpha, 0.0f, 1.0f)
76+
button("Clear") { clear() }
77+
}
7478
child("Log Content", extraFlags = noScroll) {
75-
if (wrapText) ImGui.pushTextWrapPos()
79+
if (wrapText.get()) ImGui.pushTextWrapPos()
7680

7781
logs.forEach { logEntry ->
7882
if (shouldDisplay(logEntry)) {
@@ -89,9 +93,9 @@ abstract class DebugLogger(
8993
}
9094
}
9195

92-
if (wrapText) ImGui.popTextWrapPos()
96+
if (wrapText.get()) ImGui.popTextWrapPos()
9397

94-
if (autoScroll) {
98+
if (autoScroll.get()) {
9599
ImGui.setScrollHereY(1f)
96100
}
97101
}
@@ -100,11 +104,11 @@ abstract class DebugLogger(
100104

101105
fun shouldDisplay(logEntry: LogEntry) =
102106
when (logEntry.type) {
103-
LogType.Debug -> showDebug
104-
LogType.Success -> showSuccess
105-
LogType.Warning -> showWarning
106-
LogType.Error -> showError
107-
LogType.System -> true
107+
LogType.Debug -> showDebug.get()
108+
LogType.Success -> showSuccess.get()
109+
LogType.Warning -> showWarning.get()
110+
LogType.Error -> showError.get()
111+
LogType.System -> showSystem.get()
108112
}
109113

110114
fun clear() = logs.clear()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import com.lambda.interaction.request.hotbar.HotbarRequest
7373
import com.lambda.interaction.request.interacting.InteractionManager
7474
import com.lambda.interaction.request.placing.PlaceManager
7575
import com.lambda.interaction.request.rotating.RotationRequest
76-
import com.lambda.module.hud.BreakManagerDebug
76+
import com.lambda.module.hud.ManagerDebugLoggers.breakManagerLogger
7777
import com.lambda.threading.runSafe
7878
import com.lambda.util.BlockUtils.blockState
7979
import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
@@ -107,7 +107,7 @@ object BreakManager : RequestHandler<BreakRequest>(
107107
TickEvent.Player.Post,
108108
onOpen = {
109109
if (activeInfos.isNotEmpty() || breaks.isNotEmpty() || instantBreaks.isNotEmpty())
110-
BreakManager.logger.newTick()
110+
BreakManager.logger.system("Tick stage ${BreakManager.tickStage?.run { this::class.qualifiedName }}")
111111
processRequest(activeRequest)
112112
simulateAbandoned()
113113
},
@@ -172,7 +172,7 @@ object BreakManager : RequestHandler<BreakRequest>(
172172
field = value
173173
}
174174

175-
override val logger = BreakManagerDebug
175+
override val logger = breakManagerLogger
176176

177177
fun Any.onBreak(
178178
alwaysListen: Boolean = false,
@@ -187,7 +187,7 @@ object BreakManager : RequestHandler<BreakRequest>(
187187

188188
listen<TickEvent.Pre>(priority = Int.MAX_VALUE) {
189189
if (activeInfos.isEmpty() && breaks.isEmpty() && instantBreaks.isEmpty()) return@listen
190-
logger.system("------------- New Tick -------------")
190+
logger.newTick()
191191
}
192192

193193
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {

src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import com.lambda.event.EventFlow.post
2323
import com.lambda.event.events.TickEvent
2424
import com.lambda.event.events.UpdateManagerEvent
2525
import com.lambda.event.listener.SafeListener.Companion.listen
26+
import com.lambda.interaction.request.Logger
2627
import com.lambda.interaction.request.RequestHandler
2728
import com.lambda.interaction.request.hotbar.HotbarManager.checkResetSwap
29+
import com.lambda.module.hud.ManagerDebugLoggers.hotbarManagerLogger
2830
import com.lambda.threading.runSafe
2931

3032
object HotbarManager : RequestHandler<HotbarRequest>(
@@ -34,7 +36,7 @@ object HotbarManager : RequestHandler<HotbarRequest>(
3436
TickEvent.Input.Post,
3537
TickEvent.Player.Post,
3638
onClose = { checkResetSwap() }
37-
) {
39+
), Logger {
3840
val serverSlot get() = runSafe {
3941
interaction.lastSelectedSlot
4042
} ?: 0
@@ -45,6 +47,8 @@ object HotbarManager : RequestHandler<HotbarRequest>(
4547

4648
var activeRequest: HotbarRequest? = null
4749

50+
override val logger = hotbarManagerLogger
51+
4852
override fun load(): String {
4953
super.load()
5054

src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.lambda.event.events.TickEvent
2525
import com.lambda.event.events.UpdateManagerEvent
2626
import com.lambda.event.listener.SafeListener.Companion.listen
2727
import com.lambda.interaction.construction.context.InteractionContext
28+
import com.lambda.interaction.request.Logger
2829
import com.lambda.interaction.request.ManagerUtils.isPosBlocked
2930
import com.lambda.interaction.request.PositionBlocking
3031
import com.lambda.interaction.request.RequestHandler
@@ -35,6 +36,7 @@ import com.lambda.interaction.request.interacting.InteractedBlockHandler.startPe
3536
import com.lambda.interaction.request.interacting.InteractionManager.activeRequest
3637
import com.lambda.interaction.request.interacting.InteractionManager.processRequest
3738
import com.lambda.interaction.request.placing.PlaceManager
39+
import com.lambda.module.hud.ManagerDebugLoggers.interactionManagerLogger
3840
import com.lambda.util.player.MovementUtils.sneaking
3941
import com.lambda.util.player.swingHand
4042
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket
@@ -47,7 +49,7 @@ object InteractionManager : RequestHandler<InteractRequest>(
4749
TickEvent.Input.Post,
4850
TickEvent.Player.Post,
4951
onOpen = { activeRequest?.let { processRequest(it) } }
50-
), PositionBlocking {
52+
), PositionBlocking, Logger {
5153
private var activeRequest: InteractRequest? = null
5254
private var potentialInteractions = mutableListOf<InteractionContext>()
5355

@@ -57,6 +59,8 @@ object InteractionManager : RequestHandler<InteractRequest>(
5759
override val blockedPositions
5860
get() = pendingActions.map { it.context.blockPos }
5961

62+
override val logger = interactionManagerLogger
63+
6064
override fun load(): String {
6165
super.load()
6266

src/main/kotlin/com/lambda/interaction/request/inventory/InventoryManager.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ import com.lambda.context.SafeContext
2121
import com.lambda.event.EventFlow.post
2222
import com.lambda.event.events.TickEvent
2323
import com.lambda.event.events.UpdateManagerEvent
24+
import com.lambda.interaction.request.Logger
2425

2526
import com.lambda.interaction.request.RequestHandler
2627
import com.lambda.interaction.request.inventory.InventoryManager.activeRequest
2728
import com.lambda.interaction.request.inventory.InventoryManager.processRequest
29+
import com.lambda.module.hud.ManagerDebugLoggers.inventoryManagerLogger
2830

2931
object InventoryManager : RequestHandler<InventoryRequest>(
3032
1,
@@ -33,9 +35,11 @@ object InventoryManager : RequestHandler<InventoryRequest>(
3335
TickEvent.Input.Post,
3436
TickEvent.Player.Post,
3537
onOpen = { activeRequest?.let { processRequest(it) } }
36-
) {
38+
), Logger {
3739
var activeRequest: InventoryRequest? = null
3840

41+
override val logger = inventoryManagerLogger
42+
3943
override fun load(): String {
4044
super.load()
4145

src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import com.lambda.interaction.request.placing.PlaceManager.processRequest
4141
import com.lambda.interaction.request.placing.PlacedBlockHandler.pendingActions
4242
import com.lambda.interaction.request.placing.PlacedBlockHandler.setPendingConfigs
4343
import com.lambda.interaction.request.placing.PlacedBlockHandler.startPending
44-
import com.lambda.module.hud.PlaceManagerDebug
44+
import com.lambda.module.hud.ManagerDebugLoggers.placeManagerLogger
4545
import com.lambda.util.BlockUtils.blockState
4646
import com.lambda.util.Communication.warn
4747
import com.lambda.util.player.MovementUtils.sneaking
@@ -90,7 +90,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
9090
override val blockedPositions
9191
get() = pendingActions.map { it.context.blockPos }
9292

93-
override val logger = PlaceManagerDebug
93+
override val logger = placeManagerLogger
9494

9595
fun Any.onPlace(
9696
alwaysListen: Boolean = false,

src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ import com.lambda.event.events.TickEvent
2727
import com.lambda.event.events.UpdateManagerEvent
2828
import com.lambda.event.listener.SafeListener.Companion.listen
2929
import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe
30+
import com.lambda.interaction.request.Logger
3031
import com.lambda.interaction.request.RequestHandler
3132
import com.lambda.interaction.request.rotating.Rotation.Companion.slerp
3233
import com.lambda.interaction.request.rotating.Rotation.Companion.wrap
3334
import com.lambda.interaction.request.rotating.visibilty.lookAt
35+
import com.lambda.module.hud.ManagerDebugLoggers.rotationManagerLogger
3436
import com.lambda.module.modules.client.Baritone
3537
import com.lambda.threading.runGameScheduled
3638
import com.lambda.threading.runSafe
@@ -53,14 +55,16 @@ object RotationManager : RequestHandler<RotationRequest>(
5355
TickEvent.Input.Pre,
5456
TickEvent.Input.Post,
5557
TickEvent.Player.Post,
56-
) {
58+
), Logger {
5759
var activeRotation = Rotation.ZERO
5860
var serverRotation = Rotation.ZERO
5961
var prevServerRotation = Rotation.ZERO
6062

6163
var activeRequest: RotationRequest? = null
6264
private var changedThisTick = false
6365

66+
override val logger = rotationManagerLogger
67+
6468
override fun load(): String {
6569
super.load()
6670

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

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,68 @@
1717

1818
package com.lambda.module.hud
1919

20+
import com.lambda.gui.dsl.ImGuiBuilder
2021
import com.lambda.interaction.request.DebugLogger
22+
import com.lambda.module.HudModule
23+
import com.lambda.module.tag.ModuleTag
24+
import com.lambda.util.NamedEnum
2125

22-
object BreakManagerDebug : DebugLogger(
23-
"Break Manager Logger",
24-
"Logs actions performed in the break manager to aid in debugging"
25-
)
26-
27-
object PlaceManagerDebug : DebugLogger(
28-
"Place Manager Logger",
29-
"Logs actions performed in the place manager to aid in debugging"
30-
)
31-
32-
object InteractManagerDebug : DebugLogger(
33-
"Interact Manager Logger",
34-
"Logs actions performed in the interact manager to aid in debugging"
35-
)
36-
37-
object RotationManagerDebug : DebugLogger(
38-
"Rotation Manager Logger",
39-
"Logs actions performed in the rotation manager to aid in debugging"
40-
)
41-
42-
object HotbarManagerDebug : DebugLogger(
43-
"Hotbar Manager Logger",
44-
"Logs actions performed in the hotbar manager to aid in debugging"
45-
)
46-
47-
object InventoryManagerDebug : DebugLogger(
48-
"Inventory Manager Logger",
49-
"Logs actions performed in the inventory manager to aid in debugging"
50-
)
26+
@Suppress("Unused")
27+
object ManagerDebugLoggers : HudModule(
28+
"Manager Debug Loggers",
29+
"debug loggers for all action managers in lambda",
30+
ModuleTag.HUD,
31+
customWindow = true
32+
) {
33+
enum class Group(override val displayName: String) : NamedEnum {
34+
General("General"),
35+
Break("Break"),
36+
Place("Place"),
37+
Interact("Interact"),
38+
Rotation("Rotation"),
39+
Hotbar("Hotbar"),
40+
Inventory("Inventory")
41+
}
42+
43+
private val loggers = mutableMapOf<() -> Boolean, DebugLogger>()
44+
45+
val maxLogEntries by setting("Max Log Entries", 100, 1..1000, 1, "Maximum amount of entries in the log").group(Group.General)
46+
.onValueChange { from, to ->
47+
if (to < from) {
48+
loggers.values.forEach { logger ->
49+
while(logger.logs.size > to) {
50+
logger.logs.removeFirst()
51+
}
52+
}
53+
}
54+
}
55+
56+
private val showBreakManager by setting("Show Break Manager Logger", false).group(Group.Break)
57+
val breakManagerLogger = DebugLogger("Break Manager Logger").store { showBreakManager }
58+
59+
private val showPlaceManager by setting("Show Place Manager Logger", false).group(Group.Place)
60+
val placeManagerLogger = DebugLogger("Place Manager Logger").store { showPlaceManager }
61+
62+
private val showInteractionManager by setting("Show Interaction Manager Logger", false).group(Group.Interact)
63+
val interactionManagerLogger = DebugLogger("Interaction Manager Logger").store { showInteractionManager }
64+
65+
private val showRotationManager by setting("Show Rotation Manager Logger", false).group(Group.Rotation)
66+
val rotationManagerLogger = DebugLogger("Rotation Manager Logger").store { showRotationManager }
67+
68+
private val showHotbarManager by setting("Show Hotbar Manager Logger", false).group(Group.Hotbar)
69+
val hotbarManagerLogger = DebugLogger("Hotbar Manager Logger").store { showHotbarManager }
70+
71+
private val showInventoryManager by setting("Show Inventory Manager Logger", false).group(Group.Inventory)
72+
val inventoryManagerLogger = DebugLogger("Inventory Manager Logger").store { showInventoryManager }
73+
74+
private fun DebugLogger.store(show: () -> Boolean) =
75+
also { loggers.put(show, this) }
76+
77+
override fun ImGuiBuilder.buildLayout() {
78+
loggers.entries.forEach { entry ->
79+
if (entry.key()) with(entry.value) {
80+
buildLayout()
81+
}
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)