Skip to content

Commit aa6966c

Browse files
committed
better break manager logs and fancy styling
1 parent 42eef99 commit aa6966c

File tree

17 files changed

+195
-193
lines changed

17 files changed

+195
-193
lines changed

src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2222
import com.lambda.graphics.renderer.esp.ShapeBuilder
2323
import com.lambda.interaction.material.StackSelection
2424
import com.lambda.interaction.request.LogContext
25-
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
26-
import com.lambda.interaction.request.LogContext.Companion.toLogContext
25+
import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder
26+
import com.lambda.interaction.request.LogContext.Companion.getLogContextBuilder
2727
import com.lambda.interaction.request.breaking.BreakConfig
2828
import com.lambda.interaction.request.hotbar.HotbarManager
2929
import com.lambda.interaction.request.rotating.RotationRequest
@@ -77,17 +77,16 @@ data class BreakContext(
7777
box(blockPos, cachedState, baseColor, sideColor, DirectionMask.ALL.exclude(result.side))
7878
}
7979

80-
override fun toLogContext() =
81-
buildLogContext {
82-
group("Break Context") {
83-
text(blockPos.toLogContext())
84-
text(result.toLogContext())
85-
text(rotation.toLogContext())
86-
value("Hotbar Index", hotbarIndex)
87-
value("Instant Break", instantBreak)
88-
value("Cached State", cachedState)
89-
value("Expected State", expectedState)
90-
value("Sort Mode", sortMode)
91-
}
80+
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
81+
group("Break Context") {
82+
text(blockPos.getLogContextBuilder())
83+
text(result.getLogContextBuilder())
84+
text(rotation.getLogContextBuilder())
85+
value("Hotbar Index", hotbarIndex)
86+
value("Instant Break", instantBreak)
87+
value("Cached State", cachedState)
88+
value("Expected State", expectedState)
89+
value("Sort Mode", sortMode)
9290
}
91+
}
9392
}

src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ package com.lambda.interaction.construction.context
2020
import com.lambda.graphics.renderer.esp.DirectionMask.mask
2121
import com.lambda.graphics.renderer.esp.ShapeBuilder
2222
import com.lambda.interaction.request.LogContext
23-
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
24-
import com.lambda.interaction.request.LogContext.Companion.toLogContext
23+
import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder
24+
import com.lambda.interaction.request.LogContext.Companion.getLogContextBuilder
2525
import com.lambda.interaction.request.Request.Companion.submit
2626
import com.lambda.interaction.request.hotbar.HotbarManager
2727
import com.lambda.interaction.request.hotbar.HotbarRequest
@@ -72,15 +72,14 @@ class InteractionContext(
7272
return hotbarRequest.done && validRotation
7373
}
7474

75-
override fun toLogContext() =
76-
buildLogContext {
77-
group("Interaction Context") {
78-
text(blockPos.toLogContext())
79-
text(result.toLogContext())
80-
text(rotation.toLogContext())
81-
value("Hotbar Index", hotbarIndex)
82-
value("Cached State", cachedState)
83-
value("Expected State", expectedState)
84-
}
75+
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
76+
group("Interaction Context") {
77+
text(blockPos.getLogContextBuilder())
78+
text(result.getLogContextBuilder())
79+
text(rotation.getLogContextBuilder())
80+
value("Hotbar Index", hotbarIndex)
81+
value("Cached State", cachedState)
82+
value("Expected State", expectedState)
8583
}
84+
}
8685
}

src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import com.lambda.Lambda.mc
2121
import com.lambda.graphics.renderer.esp.DirectionMask.mask
2222
import com.lambda.graphics.renderer.esp.ShapeBuilder
2323
import com.lambda.interaction.request.LogContext
24-
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
25-
import com.lambda.interaction.request.LogContext.Companion.toLogContext
24+
import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder
25+
import com.lambda.interaction.request.LogContext.Companion.getLogContextBuilder
2626
import com.lambda.interaction.request.Request.Companion.submit
2727
import com.lambda.interaction.request.hotbar.HotbarManager
2828
import com.lambda.interaction.request.hotbar.HotbarRequest
@@ -83,18 +83,17 @@ data class PlaceContext(
8383
return hotbarRequest.done && validRotation
8484
}
8585

86-
override fun toLogContext() =
87-
buildLogContext {
88-
group("Place Context") {
89-
text(blockPos.toLogContext())
90-
text(result.toLogContext())
91-
text(rotation.toLogContext())
92-
value("Hotbar Index", hotbarIndex)
93-
value("Cached State", cachedState)
94-
value("Expected State", expectedState)
95-
value("Sneak", sneak)
96-
value("Inside Block", insideBlock)
97-
value("Current Dir Is Invalid", currentDirIsValid)
98-
}
86+
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
87+
group("Place Context") {
88+
text(blockPos.getLogContextBuilder())
89+
text(result.getLogContextBuilder())
90+
text(rotation.getLogContextBuilder())
91+
value("Hotbar Index", hotbarIndex)
92+
value("Cached State", cachedState)
93+
value("Expected State", expectedState)
94+
value("Sneak", sneak)
95+
value("Inside Block", insideBlock)
96+
value("Current Dir Is Invalid", currentDirIsValid)
9997
}
100-
}
98+
}
99+
}

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import imgui.flag.ImGuiCol
2828
import imgui.flag.ImGuiWindowFlags
2929
import imgui.type.ImBoolean
3030
import imgui.type.ImFloat
31-
import net.minecraft.util.hit.BlockHitResult
32-
import net.minecraft.util.math.BlockPos
3331
import java.awt.Color
3432
import java.util.*
3533

@@ -47,18 +45,33 @@ class DebugLogger(
4745

4846
val logs = LinkedList<LogEntry>()
4947

50-
private fun log(message: String, logColor: LogType, vararg extraContext: String?) {
48+
private fun log(message: String, logColor: LogType, extraContext: List<String?>) {
5149
if (logs.size + 1 > maxLogEntries) {
5250
logs.removeFirst()
5351
}
54-
logs.add(LogEntry(message, logColor, *extraContext))
52+
logs.add(LogEntry(message, logColor, extraContext.filterNotNull()))
5553
}
5654

57-
fun debug(message: String, vararg extraContext: String?) = log(message, LogType.Debug, *extraContext)
58-
fun success(message: String, vararg extraContext: String?) = log(message, LogType.Success, *extraContext)
59-
fun warning(message: String, vararg extraContext: String?) = log(message, LogType.Warning, *extraContext)
60-
fun error(message: String, vararg extraContext: String?) = log(message, LogType.Error, *extraContext)
61-
fun system(message: String, vararg extraContext: String?) = log(message, LogType.System, *extraContext)
55+
fun debug(message: String) = log(message, LogType.Debug, emptyList())
56+
fun debug(message: String, vararg extraContext: String?) = log(message, LogType.Debug, extraContext.toList())
57+
fun debug(message: String, vararg extraContext: LogContext?) =
58+
log(message, LogType.Debug, extraContext.filterNotNull().map { buildLogContext(builder = it.getLogContextBuilder()) })
59+
fun success(message: String) = log(message, LogType.Success, emptyList())
60+
fun success(message: String, vararg extraContext: String?) = log(message, LogType.Success, extraContext.toList())
61+
fun success(message: String, vararg extraContext: LogContext?) =
62+
log(message, LogType.Success, extraContext.filterNotNull().map { buildLogContext(builder = it.getLogContextBuilder()) })
63+
fun warning(message: String) = log(message, LogType.Warning, emptyList())
64+
fun warning(message: String, vararg extraContext: String?) = log(message, LogType.Warning, extraContext.toList())
65+
fun warning(message: String, vararg extraContext: LogContext?) =
66+
log(message, LogType.Warning, extraContext.filterNotNull().map { buildLogContext(builder = it.getLogContextBuilder()) })
67+
fun error(message: String) = log(message, LogType.Error, emptyList())
68+
fun error(message: String, vararg extraContext: String?) = log(message, LogType.Error, extraContext.toList())
69+
fun error(message: String, vararg extraContext: LogContext?) =
70+
log(message, LogType.Error, extraContext.filterNotNull().map { buildLogContext(builder = it.getLogContextBuilder()) })
71+
fun system(message: String) = log(message, LogType.System, emptyList())
72+
fun system(message: String, vararg extraContext: String?) = log(message, LogType.System, extraContext.toList())
73+
fun system(message: String, vararg extraContext: LogContext?) =
74+
log(message, LogType.System, extraContext.filterNotNull().map { buildLogContext(builder = it.getLogContextBuilder()) })
6275

6376
fun ImGuiBuilder.buildLayout() {
6477
ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY)
@@ -135,7 +148,7 @@ class DebugLogger(
135148
class LogEntry(
136149
val message: String,
137150
val type: LogType,
138-
vararg val extraContext: String?
151+
val extraContext: Collection<String?>
139152
) {
140153
val uuid = UUID.randomUUID().toString()
141154
}

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,24 @@ import net.minecraft.util.hit.BlockHitResult
2121
import net.minecraft.util.math.BlockPos
2222

2323
interface LogContext {
24-
fun toLogContext(): String
24+
fun getLogContextBuilder(): LogContextBuilder.() -> Unit
2525

2626
companion object {
2727
@DslMarker
2828
private annotation class LogContextDsl
2929

30-
fun BlockPos.toLogContext(): String {
30+
fun BlockPos.getLogContextBuilder(): LogContextBuilder.() -> Unit {
3131
val pos = if (this is BlockPos.Mutable) toImmutable() else this
32-
return buildLogContext {
33-
value("Block Pos", pos.toShortString())
34-
}
32+
return { value("Block Pos", pos.toShortString()) }
3533
}
3634

37-
fun BlockHitResult.toLogContext() =
38-
buildLogContext {
39-
group("Block Hit Result") {
40-
value("Side", side)
41-
value("Block Pos", blockPos)
42-
value("Pos", pos)
43-
}
35+
fun BlockHitResult.getLogContextBuilder(): LogContextBuilder.() -> Unit = {
36+
group("Block Hit Result") {
37+
value("Side", side)
38+
value("Block Pos", blockPos)
39+
value("Pos", pos)
4440
}
41+
}
4542

4643
@LogContextDsl
4744
fun buildLogContext(tabMin: Int = 0, builder: LogContextBuilder.() -> Unit): String =
@@ -61,11 +58,15 @@ interface LogContext {
6158
@LogContextDsl
6259
fun text(text: String) {
6360
repeat(tabs) {
64-
logContext += "\t"
61+
logContext += "----"
6562
}
6663
logContext += "$text\n"
6764
}
6865

66+
fun text(builder: LogContextBuilder.() -> Unit) {
67+
logContext += LogContextBuilder(tabs).apply(builder).build()
68+
}
69+
6970
@LogContextDsl
7071
fun value(name: String, value: Any) {
7172
text("$name: $value")
@@ -78,8 +79,9 @@ interface LogContext {
7879

7980
@LogContextDsl
8081
fun group(name: String, builder: LogContextBuilder.() -> Unit) {
81-
text("$name:")
82-
text(LogContextBuilder(tabs + 1).apply(builder).build())
82+
text("$name {")
83+
logContext += LogContextBuilder(tabs + 1).apply(builder).build()
84+
text("}")
8385
}
8486

8587
@LogContextDsl

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package com.lambda.interaction.request.breaking
2020
import com.lambda.interaction.construction.context.BreakContext
2121
import com.lambda.interaction.request.ActionInfo
2222
import com.lambda.interaction.request.LogContext
23-
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
23+
import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder
2424
import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary
2525
import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Rebreak
2626
import com.lambda.interaction.request.breaking.BreakInfo.BreakType.RedundantSecondary
@@ -150,28 +150,27 @@ data class BreakInfo(
150150
)
151151
}
152152

153-
override fun toLogContext() =
154-
buildLogContext {
155-
group("Break Info") {
156-
value("Type", type)
157-
text(context.toLogContext())
158-
group("Details") {
159-
value("Should Progress", shouldProgress)
160-
value("Rebreak Potential", rebreakPotential)
161-
text(swapInfo.toLogContext())
162-
value("Swap Stack", swapStack)
163-
value("Updated This Tick", updatedThisTick)
164-
value("Updated Pre-Processing This Tick", updatedPreProcessingThisTick)
165-
value("Progressed This Tick", progressedThisTick)
166-
value("Breaking", breaking)
167-
value("Abandoned", abandoned)
168-
value("Breaking Ticks", breakingTicks)
169-
value("Sounds Cooldown", soundsCooldown)
170-
value("Vanilla Instant Breakable", vanillaInstantBreakable)
171-
value("Rebreakable", rebreakable)
172-
}
153+
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
154+
group("Break Info") {
155+
value("Type", type)
156+
text(context.getLogContextBuilder())
157+
group("Details") {
158+
value("Should Progress", shouldProgress)
159+
value("Rebreak Potential", rebreakPotential)
160+
text(swapInfo.getLogContextBuilder())
161+
value("Swap Stack", swapStack)
162+
value("Updated This Tick", updatedThisTick)
163+
value("Updated Pre-Processing This Tick", updatedPreProcessingThisTick)
164+
value("Progressed This Tick", progressedThisTick)
165+
value("Breaking", breaking)
166+
value("Abandoned", abandoned)
167+
value("Breaking Ticks", breakingTicks)
168+
value("Sounds Cooldown", soundsCooldown)
169+
value("Vanilla Instant Breakable", vanillaInstantBreakable)
170+
value("Rebreakable", rebreakable)
173171
}
174172
}
173+
}
175174

176175
override fun toString() = "$type, ${context.cachedState}, ${context.blockPos}"
177176
}

0 commit comments

Comments
 (0)