diff options
author | nea <nea@nea.moe> | 2023-07-11 21:01:58 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-07-11 21:01:58 +0200 |
commit | 4d93f475aadc42c4bf83c3a0749af41659235c71 (patch) | |
tree | c8e01710defe66e06c50fa962c72fdac66a35a1f /src/main/kotlin/moe/nea/firmament/features/debug/DebugView.kt | |
parent | 4444fcca44d9a53c8162d69e0e9f19fd214c2f54 (diff) | |
download | Firmament-4d93f475aadc42c4bf83c3a0749af41659235c71.tar.gz Firmament-4d93f475aadc42c4bf83c3a0749af41659235c71.tar.bz2 Firmament-4d93f475aadc42c4bf83c3a0749af41659235c71.zip |
Bulk commit
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features/debug/DebugView.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/features/debug/DebugView.kt | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/debug/DebugView.kt b/src/main/kotlin/moe/nea/firmament/features/debug/DebugView.kt new file mode 100644 index 0000000..e8c85d8 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/features/debug/DebugView.kt @@ -0,0 +1,53 @@ +package moe.nea.firmament.features.debug + +import io.github.cottonmc.cotton.gui.client.CottonHud +import io.github.cottonmc.cotton.gui.widget.WBox +import io.github.cottonmc.cotton.gui.widget.data.Axis +import java.util.Optional +import kotlin.time.Duration.Companion.seconds +import net.minecraft.scoreboard.Scoreboard +import net.minecraft.scoreboard.Team +import net.minecraft.text.StringVisitable +import net.minecraft.text.Style +import net.minecraft.text.Text +import net.minecraft.util.Formatting +import moe.nea.firmament.Firmament +import moe.nea.firmament.events.TickEvent +import moe.nea.firmament.features.FirmamentFeature +import moe.nea.firmament.util.MC +import moe.nea.firmament.util.TimeMark + +object DebugView : FirmamentFeature { + private data class StoredVariable<T>( + val obj: T, + val timer: TimeMark, + ) + + private val storedVariables: MutableMap<String, StoredVariable<*>> = mutableMapOf() + override val identifier: String + get() = "debug-view" + override val defaultEnabled: Boolean + get() = Firmament.DEBUG + + fun <T : Any?> showVariable(label: String, obj: T) { + synchronized(this) { + storedVariables[label] = StoredVariable(obj, TimeMark.now()) + } + } + + val debugWidget = WBox(Axis.VERTICAL) + + + override fun onLoad() { + TickEvent.subscribe { + synchronized(this) { + storedVariables.entries.removeIf { it.value.timer.passedTime() > 1.seconds } + if (storedVariables.isEmpty()) { + CottonHud.add(debugWidget, 20, 20) + } else { + CottonHud.remove(debugWidget) + } + } + } + } +} |