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

@@ -8,7 +8,7 @@ root = true
charset = utf-8 charset = utf-8
end_of_line = lf end_of_line = lf
indent_size = 4 indent_size = 4
indent_style = space indent_style = tab
insert_final_newline = true insert_final_newline = true
max_line_length = 120 max_line_length = 120

View File

@@ -8,6 +8,7 @@ import net.minecraft.text.Text
import moe.nea.firmament.apis.UrsaManager import moe.nea.firmament.apis.UrsaManager
import moe.nea.firmament.events.CommandEvent import moe.nea.firmament.events.CommandEvent
import moe.nea.firmament.events.FirmamentEventBus import moe.nea.firmament.events.FirmamentEventBus
import moe.nea.firmament.features.debug.DebugLogger
import moe.nea.firmament.features.debug.PowerUserTools import moe.nea.firmament.features.debug.PowerUserTools
import moe.nea.firmament.features.inventory.buttons.InventoryButtons import moe.nea.firmament.features.inventory.buttons.InventoryButtons
import moe.nea.firmament.features.inventory.storageoverlay.StorageOverlayScreen import moe.nea.firmament.features.inventory.storageoverlay.StorageOverlayScreen
@@ -28,242 +29,260 @@ import moe.nea.firmament.util.collections.WeakCache
fun firmamentCommand() = literal("firmament") { fun firmamentCommand() = literal("firmament") {
thenLiteral("config") { thenLiteral("config") {
thenExecute { thenExecute {
AllConfigsGui.showAllGuis() AllConfigsGui.showAllGuis()
} }
thenLiteral("toggle") { thenLiteral("toggle") {
thenArgument("config", string()) { config -> thenArgument("config", string()) { config ->
suggestsList { suggestsList {
AllConfigsGui.allConfigs.asSequence().map { it.name }.asIterable() AllConfigsGui.allConfigs.asSequence().map { it.name }.asIterable()
} }
thenArgument("property", string()) { property -> thenArgument("property", string()) { property ->
suggestsList { suggestsList {
(AllConfigsGui.allConfigs.find { it.name == this[config] } ?: return@suggestsList listOf()) (AllConfigsGui.allConfigs.find { it.name == this[config] } ?: return@suggestsList listOf())
.allOptions.entries.asSequence().filter { it.value.handler is BooleanHandler } .allOptions.entries.asSequence().filter { it.value.handler is BooleanHandler }
.map { it.key } .map { it.key }
.asIterable() .asIterable()
} }
thenExecute { thenExecute {
val config = this[config] val config = this[config]
val property = this[property] val property = this[property]
val configObj = AllConfigsGui.allConfigs.find { it.name == config } val configObj = AllConfigsGui.allConfigs.find { it.name == config }
if (configObj == null) { if (configObj == null) {
source.sendFeedback( source.sendFeedback(
Text.stringifiedTranslatable( Text.stringifiedTranslatable(
"firmament.command.toggle.no-config-found", "firmament.command.toggle.no-config-found",
config config
) )
) )
return@thenExecute return@thenExecute
} }
val propertyObj = configObj.allOptions[property] val propertyObj = configObj.allOptions[property]
if (propertyObj == null) { if (propertyObj == null) {
source.sendFeedback( source.sendFeedback(
Text.stringifiedTranslatable("firmament.command.toggle.no-property-found", property) Text.stringifiedTranslatable("firmament.command.toggle.no-property-found", property)
) )
return@thenExecute return@thenExecute
} }
if (propertyObj.handler !is BooleanHandler) { if (propertyObj.handler !is BooleanHandler) {
source.sendFeedback( source.sendFeedback(
Text.stringifiedTranslatable("firmament.command.toggle.not-a-toggle", property) Text.stringifiedTranslatable("firmament.command.toggle.not-a-toggle", property)
) )
return@thenExecute return@thenExecute
} }
propertyObj as ManagedOption<Boolean> propertyObj as ManagedOption<Boolean>
propertyObj.value = !propertyObj.value propertyObj.value = !propertyObj.value
configObj.save() configObj.save()
source.sendFeedback( source.sendFeedback(
Text.stringifiedTranslatable( Text.stringifiedTranslatable(
"firmament.command.toggle.toggled", configObj.labelText, "firmament.command.toggle.toggled", configObj.labelText,
propertyObj.labelText, propertyObj.labelText,
Text.translatable("firmament.toggle.${propertyObj.value}") Text.translatable("firmament.toggle.${propertyObj.value}")
) )
) )
} }
} }
} }
} }
} }
thenLiteral("buttons") { thenLiteral("buttons") {
thenExecute { thenExecute {
InventoryButtons.openEditor() InventoryButtons.openEditor()
} }
} }
thenLiteral("sendcoords") { thenLiteral("sendcoords") {
thenExecute { thenExecute {
val p = MC.player ?: return@thenExecute val p = MC.player ?: return@thenExecute
MC.sendServerChat("x: ${p.blockX}, y: ${p.blockY}, z: ${p.blockZ}") MC.sendServerChat("x: ${p.blockX}, y: ${p.blockY}, z: ${p.blockZ}")
} }
thenArgument("rest", RestArgumentType) { rest -> thenArgument("rest", RestArgumentType) { rest ->
thenExecute { thenExecute {
val p = MC.player ?: return@thenExecute val p = MC.player ?: return@thenExecute
MC.sendServerChat("x: ${p.blockX}, y: ${p.blockY}, z: ${p.blockZ} ${this[rest]}") MC.sendServerChat("x: ${p.blockX}, y: ${p.blockY}, z: ${p.blockZ} ${this[rest]}")
} }
} }
} }
thenLiteral("storageoverview") { thenLiteral("storageoverview") {
thenExecute { thenExecute {
ScreenUtil.setScreenLater(StorageOverviewScreen()) ScreenUtil.setScreenLater(StorageOverviewScreen())
MC.player?.networkHandler?.sendChatCommand("storage") MC.player?.networkHandler?.sendChatCommand("storage")
} }
} }
thenLiteral("storage") { thenLiteral("storage") {
thenExecute { thenExecute {
ScreenUtil.setScreenLater(StorageOverlayScreen()) ScreenUtil.setScreenLater(StorageOverlayScreen())
MC.player?.networkHandler?.sendChatCommand("storage") MC.player?.networkHandler?.sendChatCommand("storage")
} }
} }
thenLiteral("repo") { thenLiteral("repo") {
thenLiteral("reload") { thenLiteral("reload") {
thenLiteral("fetch") { thenLiteral("fetch") {
thenExecute { thenExecute {
source.sendFeedback(Text.translatable("firmament.repo.reload.network")) // TODO better reporting source.sendFeedback(Text.translatable("firmament.repo.reload.network")) // TODO better reporting
RepoManager.launchAsyncUpdate() RepoManager.launchAsyncUpdate()
} }
} }
thenExecute { thenExecute {
source.sendFeedback(Text.translatable("firmament.repo.reload.disk")) source.sendFeedback(Text.translatable("firmament.repo.reload.disk"))
RepoManager.reload() RepoManager.reload()
} }
} }
} }
thenLiteral("price") { thenLiteral("price") {
thenArgument("item", string()) { item -> thenArgument("item", string()) { item ->
suggestsList { RepoManager.neuRepo.items.items.keys } suggestsList { RepoManager.neuRepo.items.items.keys }
thenExecute { thenExecute {
val itemName = SkyblockId(get(item)) val itemName = SkyblockId(get(item))
source.sendFeedback(Text.stringifiedTranslatable("firmament.price", itemName.neuItem)) source.sendFeedback(Text.stringifiedTranslatable("firmament.price", itemName.neuItem))
val bazaarData = HypixelStaticData.bazaarData[itemName] val bazaarData = HypixelStaticData.bazaarData[itemName]
if (bazaarData != null) { if (bazaarData != null) {
source.sendFeedback(Text.translatable("firmament.price.bazaar")) source.sendFeedback(Text.translatable("firmament.price.bazaar"))
source.sendFeedback( source.sendFeedback(
Text.stringifiedTranslatable("firmament.price.bazaar.productid", bazaarData.productId.bazaarId) Text.stringifiedTranslatable("firmament.price.bazaar.productid", bazaarData.productId.bazaarId)
) )
source.sendFeedback( source.sendFeedback(
Text.stringifiedTranslatable( Text.stringifiedTranslatable(
"firmament.price.bazaar.buy.price", "firmament.price.bazaar.buy.price",
FirmFormatters.formatCommas(bazaarData.quickStatus.buyPrice, 1) FirmFormatters.formatCommas(bazaarData.quickStatus.buyPrice, 1)
) )
) )
source.sendFeedback( source.sendFeedback(
Text.stringifiedTranslatable( Text.stringifiedTranslatable(
"firmament.price.bazaar.buy.order", "firmament.price.bazaar.buy.order",
bazaarData.quickStatus.buyOrders bazaarData.quickStatus.buyOrders
) )
) )
source.sendFeedback( source.sendFeedback(
Text.stringifiedTranslatable( Text.stringifiedTranslatable(
"firmament.price.bazaar.sell.price", "firmament.price.bazaar.sell.price",
FirmFormatters.formatCommas(bazaarData.quickStatus.sellPrice, 1) FirmFormatters.formatCommas(bazaarData.quickStatus.sellPrice, 1)
) )
) )
source.sendFeedback( source.sendFeedback(
Text.stringifiedTranslatable( Text.stringifiedTranslatable(
"firmament.price.bazaar.sell.order", "firmament.price.bazaar.sell.order",
bazaarData.quickStatus.sellOrders bazaarData.quickStatus.sellOrders
) )
) )
} }
val lowestBin = HypixelStaticData.lowestBin[itemName] val lowestBin = HypixelStaticData.lowestBin[itemName]
if (lowestBin != null) { if (lowestBin != null) {
source.sendFeedback( source.sendFeedback(
Text.stringifiedTranslatable( Text.stringifiedTranslatable(
"firmament.price.lowestbin", "firmament.price.lowestbin",
FirmFormatters.formatCommas(lowestBin, 1) FirmFormatters.formatCommas(lowestBin, 1)
) )
) )
} }
} }
} }
} }
thenLiteral("dev") { thenLiteral("dev") {
thenLiteral("simulate") { thenLiteral("simulate") {
thenArgument("message", RestArgumentType) { message -> thenArgument("message", RestArgumentType) { message ->
thenExecute { thenExecute {
MC.instance.messageHandler.onGameMessage(Text.literal(get(message)), false) MC.instance.messageHandler.onGameMessage(Text.literal(get(message)), false)
} }
} }
} }
thenLiteral("sbdata") { thenLiteral("debuglog") {
thenExecute { thenLiteral("toggle") {
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.profile", SBData.profileId)) thenArgument("tag", string()) { tag ->
val locrawInfo = SBData.locraw suggestsList { DebugLogger.allInstances.getAll().map { it.tag } + DebugLogger.EnabledLogs.data }
if (locrawInfo == null) { thenExecute {
source.sendFeedback(Text.translatable("firmament.sbinfo.nolocraw")) val tagText = this[tag]
} else { val enabled = DebugLogger.EnabledLogs.data
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.server", locrawInfo.server)) if (tagText in enabled) {
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.gametype", locrawInfo.gametype)) enabled.remove(tagText)
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.mode", locrawInfo.mode)) source.sendFeedback(Text.literal("Disabled $tagText debug logging"))
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.map", locrawInfo.map)) } else {
} enabled.add(tagText)
} source.sendFeedback(Text.literal("Enabled $tagText debug logging"))
} }
thenLiteral("copyEntities") { }
thenExecute { }
val player = MC.player ?: return@thenExecute }
player.world.getOtherEntities(player, player.boundingBox.expand(12.0)) }
.forEach(PowerUserTools::showEntity) thenLiteral("sbdata") {
} thenExecute {
} source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.profile", SBData.profileId))
thenLiteral("callUrsa") { val locrawInfo = SBData.locraw
thenArgument("path", string()) { path -> if (locrawInfo == null) {
thenExecute { source.sendFeedback(Text.translatable("firmament.sbinfo.nolocraw"))
source.sendFeedback(Text.translatable("firmament.ursa.debugrequest.start")) } else {
val text = UrsaManager.request(this[path].split("/")).bodyAsText() source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.server", locrawInfo.server))
source.sendFeedback(Text.stringifiedTranslatable("firmament.ursa.debugrequest.result", text)) source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.gametype", locrawInfo.gametype))
} source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.mode", locrawInfo.mode))
} source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.map", locrawInfo.map))
} }
thenLiteral("events") { }
thenExecute { }
source.sendFeedback(Text.translatable("firmament.event.start")) thenLiteral("copyEntities") {
FirmamentEventBus.allEventBuses.forEach { eventBus -> thenExecute {
source.sendFeedback(Text.translatable( val player = MC.player ?: return@thenExecute
"firmament.event.bustype", player.world.getOtherEntities(player, player.boundingBox.expand(12.0))
eventBus.eventType.typeName.removePrefix("moe.nea.firmament"))) .forEach(PowerUserTools::showEntity)
eventBus.handlers.forEach { handler -> }
source.sendFeedback(Text.translatable( }
"firmament.event.handler", thenLiteral("callUrsa") {
handler.label)) thenArgument("path", string()) { path ->
} thenExecute {
} source.sendFeedback(Text.translatable("firmament.ursa.debugrequest.start"))
} val text = UrsaManager.request(this[path].split("/")).bodyAsText()
} source.sendFeedback(Text.stringifiedTranslatable("firmament.ursa.debugrequest.result", text))
thenLiteral("caches") { }
thenExecute { }
source.sendFeedback(Text.literal("Caches:")) }
WeakCache.allInstances.getAll().forEach { thenLiteral("events") {
source.sendFeedback(Text.literal(" - ${it.name}: ${it.size}")) thenExecute {
} source.sendFeedback(Text.translatable("firmament.event.start"))
source.sendFeedback(Text.translatable("Instance lists:")) FirmamentEventBus.allEventBuses.forEach { eventBus ->
InstanceList.allInstances.getAll().forEach { source.sendFeedback(Text.translatable(
source.sendFeedback(Text.literal(" - ${it.name}: ${it.size}")) "firmament.event.bustype",
} eventBus.eventType.typeName.removePrefix("moe.nea.firmament")))
} eventBus.handlers.forEach { handler ->
} source.sendFeedback(Text.translatable(
thenLiteral("mixins") { "firmament.event.handler",
thenExecute { handler.label))
source.sendFeedback(Text.translatable("firmament.mixins.start")) }
MixinPlugin.appliedMixins }
.map { it.removePrefix(MixinPlugin.mixinPackage) } }
.forEach { }
source.sendFeedback(Text.literal(" - ").withColor(0xD020F0) thenLiteral("caches") {
.append(Text.literal(it).withColor(0xF6BA20))) thenExecute {
} source.sendFeedback(Text.literal("Caches:"))
} WeakCache.allInstances.getAll().forEach {
} source.sendFeedback(Text.literal(" - ${it.name}: ${it.size}"))
} }
CommandEvent.SubCommand.publish(CommandEvent.SubCommand(this@literal)) source.sendFeedback(Text.translatable("Instance lists:"))
InstanceList.allInstances.getAll().forEach {
source.sendFeedback(Text.literal(" - ${it.name}: ${it.size}"))
}
}
}
thenLiteral("mixins") {
thenExecute {
source.sendFeedback(Text.translatable("firmament.mixins.start"))
MixinPlugin.appliedMixins
.map { it.removePrefix(MixinPlugin.mixinPackage) }
.forEach {
source.sendFeedback(Text.literal(" - ").withColor(0xD020F0)
.append(Text.literal(it).withColor(0xF6BA20)))
}
}
}
}
CommandEvent.SubCommand.publish(CommandEvent.SubCommand(this@literal))
} }
fun registerFirmamentCommand(dispatcher: CommandDispatcher<FabricClientCommandSource>) { fun registerFirmamentCommand(dispatcher: CommandDispatcher<FabricClientCommandSource>) {
val firmament = dispatcher.register(firmamentCommand()) val firmament = dispatcher.register(firmamentCommand())
dispatcher.register(literal("firm") { dispatcher.register(literal("firm") {
redirect(firmament) redirect(firmament)
}) })
} }

View File

@@ -1,20 +1,24 @@
package moe.nea.firmament.features.debug package moe.nea.firmament.features.debug
import kotlinx.serialization.serializer
import net.minecraft.text.Text import net.minecraft.text.Text
import moe.nea.firmament.util.MC import moe.nea.firmament.util.MC
import moe.nea.firmament.util.collections.InstanceList import moe.nea.firmament.util.collections.InstanceList
import moe.nea.firmament.util.data.DataHolder
class DebugLogger(val tag: String) { class DebugLogger(val tag: String) {
companion object { companion object {
val allInstances = InstanceList<DebugLogger>("DebugLogger") val allInstances = InstanceList<DebugLogger>("DebugLogger")
} }
init { object EnabledLogs : DataHolder<MutableSet<String>>(serializer(), "DebugLogs", ::mutableSetOf)
allInstances.add(this)
} init {
fun isEnabled() = DeveloperFeatures.isEnabled // TODO: allow filtering by tag allInstances.add(this)
fun log(text: () -> String) { }
if (!isEnabled()) return
MC.sendChat(Text.literal(text())) fun isEnabled() = DeveloperFeatures.isEnabled && EnabledLogs.data.contains(tag)
} fun log(text: () -> String) {
if (!isEnabled()) return
MC.sendChat(Text.literal(text()))
}
} }

View File

@@ -1,5 +1,3 @@
package moe.nea.firmament.features.debug package moe.nea.firmament.features.debug
import java.nio.file.Path 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.gui.config.ManagedConfig
import moe.nea.firmament.util.MC import moe.nea.firmament.util.MC
import moe.nea.firmament.util.TimeMark import moe.nea.firmament.util.TimeMark
import moe.nea.firmament.util.errorBoundary
import moe.nea.firmament.util.iterate import moe.nea.firmament.util.iterate
object DeveloperFeatures : FirmamentFeature { object DeveloperFeatures : FirmamentFeature {
@@ -43,7 +40,9 @@ object DeveloperFeatures : FirmamentFeature {
MC.player?.sendMessage(Text.translatable("firmament.dev.resourcerebuild.start")) MC.player?.sendMessage(Text.translatable("firmament.dev.resourcerebuild.start"))
val startTime = TimeMark.now() val startTime = TimeMark.now()
process.toHandle().onExit().thenApply { 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 Unit
} }
} else { } else {