aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/debug/DebugLogger.kt
blob: 2c6b962e807ed79c23455c6541991ca8ff2cb5d2 (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
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")
	}
	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()))
	}
}