aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/debug/DebugLogger.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-09-25 15:27:22 +0200
committerLinnea Gräf <nea@nea.moe>2024-09-25 15:27:22 +0200
commitbeb14d73bd2d0d48513e540ff629b48f89b95ed9 (patch)
tree8b8840481a3e15c30c1b21b056503dd4b46e0d28 /src/main/kotlin/features/debug/DebugLogger.kt
parent420f2a61e1cc64d68bf03825e8fd70cf49ac6a01 (diff)
downloadFirmament-beb14d73bd2d0d48513e540ff629b48f89b95ed9.tar.gz
Firmament-beb14d73bd2d0d48513e540ff629b48f89b95ed9.tar.bz2
Firmament-beb14d73bd2d0d48513e540ff629b48f89b95ed9.zip
Add debug log enabling
Diffstat (limited to 'src/main/kotlin/features/debug/DebugLogger.kt')
-rw-r--r--src/main/kotlin/features/debug/DebugLogger.kt28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/main/kotlin/features/debug/DebugLogger.kt b/src/main/kotlin/features/debug/DebugLogger.kt
index 69a191d..2c6b962 100644
--- a/src/main/kotlin/features/debug/DebugLogger.kt
+++ b/src/main/kotlin/features/debug/DebugLogger.kt
@@ -1,20 +1,24 @@
-
package moe.nea.firmament.features.debug
+import kotlinx.serialization.serializer
import net.minecraft.text.Text
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.collections.InstanceList
+import moe.nea.firmament.util.data.DataHolder
class DebugLogger(val tag: String) {
- companion object {
- val allInstances = InstanceList<DebugLogger>("DebugLogger")
- }
- init {
- allInstances.add(this)
- }
- fun isEnabled() = DeveloperFeatures.isEnabled // TODO: allow filtering by tag
- fun log(text: () -> String) {
- if (!isEnabled()) return
- MC.sendChat(Text.literal(text()))
- }
+ companion object {
+ val allInstances = InstanceList<DebugLogger>("DebugLogger")
+ }
+ object EnabledLogs : DataHolder<MutableSet<String>>(serializer(), "DebugLogs", ::mutableSetOf)
+
+ init {
+ allInstances.add(this)
+ }
+
+ fun isEnabled() = DeveloperFeatures.isEnabled && EnabledLogs.data.contains(tag)
+ fun log(text: () -> String) {
+ if (!isEnabled()) return
+ MC.sendChat(Text.literal(text()))
+ }
}