Add debug log enabling

This commit is contained in:
Linnea Gräf
2024-09-25 15:27:22 +02:00
parent 420f2a61e1
commit beb14d73bd
4 changed files with 270 additions and 248 deletions

View File

@@ -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()))
}
}