From beb14d73bd2d0d48513e540ff629b48f89b95ed9 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Wed, 25 Sep 2024 15:27:22 +0200 Subject: Add debug log enabling --- src/main/kotlin/features/debug/DebugLogger.kt | 28 ++++++++++++---------- .../kotlin/features/debug/DeveloperFeatures.kt | 7 +++--- 2 files changed, 19 insertions(+), 16 deletions(-) (limited to 'src/main/kotlin/features/debug') 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") - } - 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") + } + object EnabledLogs : DataHolder>(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())) + } } diff --git a/src/main/kotlin/features/debug/DeveloperFeatures.kt b/src/main/kotlin/features/debug/DeveloperFeatures.kt index 20c0cfd..56ee398 100644 --- a/src/main/kotlin/features/debug/DeveloperFeatures.kt +++ b/src/main/kotlin/features/debug/DeveloperFeatures.kt @@ -1,5 +1,3 @@ - - package moe.nea.firmament.features.debug import java.nio.file.Path @@ -13,7 +11,6 @@ import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.util.MC import moe.nea.firmament.util.TimeMark -import moe.nea.firmament.util.errorBoundary import moe.nea.firmament.util.iterate object DeveloperFeatures : FirmamentFeature { @@ -43,7 +40,9 @@ object DeveloperFeatures : FirmamentFeature { MC.player?.sendMessage(Text.translatable("firmament.dev.resourcerebuild.start")) val startTime = TimeMark.now() process.toHandle().onExit().thenApply { - MC.player?.sendMessage(Text.stringifiedTranslatable("firmament.dev.resourcerebuild.done", startTime.passedTime())) + MC.player?.sendMessage(Text.stringifiedTranslatable( + "firmament.dev.resourcerebuild.done", + startTime.passedTime())) Unit } } else { -- cgit