aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/debug/DebugLogger.kt
blob: 52f6143626d830a0703aad13e70b274821a1f6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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.TestUtil
import moe.nea.firmament.util.collections.InstanceList
import moe.nea.firmament.util.data.Config
import moe.nea.firmament.util.data.DataHolder

class DebugLogger(val tag: String) {
	companion object {
		val allInstances = InstanceList<DebugLogger>("DebugLogger")
	}

	@Config
	object EnabledLogs : DataHolder<MutableSet<String>>(serializer(), "DebugLogs", ::mutableSetOf)

	init {
		allInstances.add(this)
	}

	fun isEnabled() = TestUtil.isInTest || EnabledLogs.data.contains(tag)
	fun log(text: String) = log { text }
	fun log(text: () -> String) {
		if (!isEnabled()) return
		MC.sendChat(Text.literal(text()))
	}
}