Skip to content

Commit 9a45a50

Browse files
committed
group build function
1 parent 582f1b3 commit 9a45a50

File tree

15 files changed

+137
-130
lines changed

15 files changed

+137
-130
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import com.lambda.graphics.renderer.esp.DirectionMask
2121
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2222
import com.lambda.graphics.renderer.esp.ShapeBuilder
2323
import com.lambda.interaction.material.StackSelection
24-
import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext
2524
import com.lambda.interaction.request.LogContext
2625
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
26+
import com.lambda.interaction.request.LogContext.Companion.toLogContext
2727
import com.lambda.interaction.request.breaking.BreakConfig
2828
import com.lambda.interaction.request.hotbar.HotbarManager
2929
import com.lambda.interaction.request.rotating.RotationRequest
@@ -79,15 +79,15 @@ data class BreakContext(
7979

8080
override fun toLogContext() =
8181
buildLogContext {
82-
text("Break Context:")
83-
pushTab()
84-
text(blockPos.toLogContext())
85-
text(result.toLogContext())
86-
text(rotation.toLogContext())
87-
value("Hotbar Index", hotbarIndex)
88-
value("Instant Break", instantBreak)
89-
value("Cached State", cachedState)
90-
value("Expected State", expectedState)
91-
value("Sort Mode", sortMode)
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+
}
9292
}
9393
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package com.lambda.interaction.construction.context
1919

2020
import com.lambda.graphics.renderer.esp.DirectionMask.mask
2121
import com.lambda.graphics.renderer.esp.ShapeBuilder
22-
import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext
2322
import com.lambda.interaction.request.LogContext
2423
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
24+
import com.lambda.interaction.request.LogContext.Companion.toLogContext
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
@@ -74,13 +74,13 @@ class InteractionContext(
7474

7575
override fun toLogContext() =
7676
buildLogContext {
77-
text("Interaction Context:")
78-
pushTab()
79-
text(blockPos.toLogContext())
80-
text(result.toLogContext())
81-
text(rotation.toLogContext())
82-
value("Hotbar Index", hotbarIndex)
83-
value("Cached State", cachedState)
84-
value("Expected State", expectedState)
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+
}
8585
}
8686
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ package com.lambda.interaction.construction.context
2020
import com.lambda.Lambda.mc
2121
import com.lambda.graphics.renderer.esp.DirectionMask.mask
2222
import com.lambda.graphics.renderer.esp.ShapeBuilder
23-
import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext
2423
import com.lambda.interaction.request.LogContext
2524
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
25+
import com.lambda.interaction.request.LogContext.Companion.toLogContext
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
@@ -85,16 +85,16 @@ data class PlaceContext(
8585

8686
override fun toLogContext() =
8787
buildLogContext {
88-
text("Place Context:")
89-
pushTab()
90-
text(blockPos.toLogContext())
91-
text(result.toLogContext())
92-
text(rotation.toLogContext())
93-
value("Hotbar Index", hotbarIndex)
94-
value("Cached State", cachedState)
95-
value("Expected State", expectedState)
96-
value("Sneak", sneak)
97-
value("Inside Block", insideBlock)
98-
value("Current Dir Is Invalid", currentDirIsValid)
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+
}
9999
}
100100
}

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,6 @@ class DebugLogger(
138138
vararg val extraContext: String?
139139
) {
140140
val uuid = UUID.randomUUID().toString()
141-
companion object {
142-
fun BlockPos.toLogContext(): String {
143-
val pos = if (this is BlockPos.Mutable) toImmutable() else this
144-
return buildLogContext {
145-
value("Block Pos", pos.toShortString())
146-
}
147-
}
148-
149-
fun BlockHitResult.toLogContext() =
150-
buildLogContext {
151-
text("Block Hit Result:")
152-
pushTab()
153-
value("Side", side)
154-
value("Block Pos", blockPos)
155-
value("Pos", pos)
156-
}
157-
}
158141
}
159142

160143
enum class LogType(val color: Color) {

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

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

1818
package com.lambda.interaction.request
1919

20+
import net.minecraft.util.hit.BlockHitResult
21+
import net.minecraft.util.math.BlockPos
22+
2023
interface LogContext {
2124
fun toLogContext(): String
2225

2326
companion object {
2427
@DslMarker
2528
private annotation class LogContextDsl
2629

30+
fun BlockPos.toLogContext(): String {
31+
val pos = if (this is BlockPos.Mutable) toImmutable() else this
32+
return buildLogContext {
33+
value("Block Pos", pos.toShortString())
34+
}
35+
}
36+
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+
}
44+
}
45+
2746
@LogContextDsl
28-
fun buildLogContext(builder: LogContextBuilder.() -> Unit): String =
29-
LogContextBuilder().apply(builder).build()
47+
fun buildLogContext(tabMin: Int = 0, builder: LogContextBuilder.() -> Unit): String =
48+
LogContextBuilder(tabMin).apply(builder).build()
3049

3150
private fun LogContextBuilder.build() = logContext
3251

33-
class LogContextBuilder {
52+
class LogContextBuilder(val tabMin: Int = 0) {
3453
var logContext = ""
3554

36-
private var tabs = 0
55+
private var tabs = tabMin
3756

3857
@LogContextDsl
3958
fun sameLine() =
@@ -55,6 +74,12 @@ interface LogContext {
5574
text("$name: $value")
5675
}
5776

77+
@LogContextDsl
78+
fun group(name: String, builder: LogContextBuilder.() -> Unit) {
79+
text("$name:")
80+
text(LogContextBuilder(tabs + 1).apply(builder).build())
81+
}
82+
5883
@LogContextDsl
5984
fun pushTab() {
6085
tabs++
@@ -63,6 +88,7 @@ interface LogContext {
6388
@LogContextDsl
6489
fun popTab() {
6590
tabs--
91+
if (tabs < tabMin) throw IllegalStateException("Cannot reduce tabs beneath the minimum tab count")
6692
}
6793
}
6894
}

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.lambda.interaction.request.breaking
1919

2020
import com.lambda.interaction.construction.context.BreakContext
2121
import com.lambda.interaction.request.ActionInfo
22-
import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext
2322
import com.lambda.interaction.request.LogContext
2423
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
2524
import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary
@@ -153,26 +152,25 @@ data class BreakInfo(
153152

154153
override fun toLogContext() =
155154
buildLogContext {
156-
text("Break Info:")
157-
pushTab()
158-
value("Type", type)
159-
text(context.blockPos.toLogContext())
160-
text(context.toLogContext())
161-
text("Details:")
162-
pushTab()
163-
value("Should Progress", shouldProgress)
164-
value("Rebreak Potential", rebreakPotential)
165-
text(swapInfo.toLogContext())
166-
value("Swap Stack", swapStack)
167-
value("Updated This Tick", updatedThisTick)
168-
value("Updated Pre-Processing This Tick", updatedPreProcessingThisTick)
169-
value("Progressed This Tick", progressedThisTick)
170-
value("Breaking", breaking)
171-
value("Abandoned", abandoned)
172-
value("Breaking Ticks", breakingTicks)
173-
value("Sounds Cooldown", soundsCooldown)
174-
value("Vanilla Instant Breakable", vanillaInstantBreakable)
175-
value("Rebreakable", rebreakable)
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+
}
173+
}
176174
}
177175

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

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ data class BreakRequest(
6262

6363
override fun toLogContext() =
6464
buildLogContext {
65-
text("Break Request")
66-
pushTab()
67-
value("Request ID", requestID)
68-
value("Contexts", contexts.size)
69-
text("Callbacks:")
70-
pushTab()
71-
value("onStart", onStart != null)
72-
value("onUpdate", onUpdate != null)
73-
value("onStop", onStop != null)
74-
value("onCancel", onCancel != null)
75-
value("onItemDrop", onItemDrop != null)
76-
value("onReBreakStart", onReBreakStart != null)
77-
value("onReBreak", onReBreak != null)
65+
group("Break Request") {
66+
value("Request ID", requestID)
67+
value("Contexts", contexts.size)
68+
group("Callbacks") {
69+
value("onStart", onStart != null)
70+
value("onUpdate", onUpdate != null)
71+
value("onStop", onStop != null)
72+
value("onCancel", onCancel != null)
73+
value("onItemDrop", onItemDrop != null)
74+
value("onReBreakStart", onReBreakStart != null)
75+
value("onReBreak", onReBreak != null)
76+
}
77+
}
7878
}
7979

8080
@DslMarker

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ data class SwapInfo(
4545

4646
override fun toLogContext() =
4747
buildLogContext {
48-
text("Swap Info:")
49-
pushTab()
50-
value("Type", type)
51-
value("Swap", swap)
52-
value("Min Keep Ticks", minKeepTicks)
53-
value("Valid Swap", validSwap)
48+
group("Swap Info") {
49+
value("Type", type)
50+
value("Swap", swap)
51+
value("Min Keep Ticks", minKeepTicks)
52+
value("Valid Swap", validSwap)
53+
}
5454
}
5555

5656
companion object {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ class HotbarRequest(
4444

4545
override fun toLogContext() =
4646
buildLogContext {
47-
text("Hotbar Request:")
48-
pushTab()
49-
value("Request ID", requestID)
50-
value("Slot", slot)
51-
value("Keep Ticks", keepTicks)
52-
value("Swap Pause", swapPause)
53-
value("Swap Pause Age", swapPauseAge)
54-
value("Active Request Age", activeRequestAge)
47+
group("Hotbar Request") {
48+
value("Request ID", requestID)
49+
value("Slot", slot)
50+
value("Keep Ticks", keepTicks)
51+
value("Swap Pause", swapPause)
52+
value("Swap Pause Age", swapPauseAge)
53+
value("Active Request Age", activeRequestAge)
54+
}
5555
}
5656

5757
companion object {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ data class InteractRequest(
4848

4949
override fun toLogContext() =
5050
buildLogContext {
51-
text("Interact Request:")
52-
pushTab()
53-
value("Request ID", requestID)
54-
value("Contexts", contexts.size)
51+
group("Interact Request") {
52+
value("Request ID", requestID)
53+
value("Contexts", contexts.size)
54+
}
5555
}
5656

5757
companion object {

0 commit comments

Comments
 (0)