feat: Add repo debug information

This commit is contained in:
Linnea Gräf
2024-11-18 15:59:40 +01:00
parent fba91100cb
commit 68948baff3
4 changed files with 84 additions and 2 deletions

View File

@@ -3,7 +3,14 @@ package moe.nea.firmament.commands
import com.mojang.brigadier.CommandDispatcher import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.arguments.StringArgumentType.string import com.mojang.brigadier.arguments.StringArgumentType.string
import io.ktor.client.statement.bodyAsText import io.ktor.client.statement.bodyAsText
import java.nio.file.Path
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import kotlin.io.path.exists
import kotlin.io.path.fileSize
import kotlin.io.path.isDirectory
import kotlin.io.path.isReadable
import kotlin.io.path.isRegularFile
import kotlin.io.path.listDirectoryEntries
import net.minecraft.nbt.NbtOps import net.minecraft.nbt.NbtOps
import net.minecraft.text.Text import net.minecraft.text.Text
import net.minecraft.text.TextCodecs import net.minecraft.text.TextCodecs
@@ -21,8 +28,12 @@ import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.gui.config.ManagedOption import moe.nea.firmament.gui.config.ManagedOption
import moe.nea.firmament.init.MixinPlugin import moe.nea.firmament.init.MixinPlugin
import moe.nea.firmament.repo.HypixelStaticData import moe.nea.firmament.repo.HypixelStaticData
import moe.nea.firmament.repo.ItemCache
import moe.nea.firmament.repo.RepoDownloadManager
import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.FirmFormatters import moe.nea.firmament.util.FirmFormatters
import moe.nea.firmament.util.FirmFormatters.debugPath
import moe.nea.firmament.util.FirmFormatters.formatBool
import moe.nea.firmament.util.MC import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SBData import moe.nea.firmament.util.SBData
import moe.nea.firmament.util.ScreenUtil import moe.nea.firmament.util.ScreenUtil
@@ -30,7 +41,11 @@ import moe.nea.firmament.util.SkyblockId
import moe.nea.firmament.util.accessors.messages import moe.nea.firmament.util.accessors.messages
import moe.nea.firmament.util.collections.InstanceList import moe.nea.firmament.util.collections.InstanceList
import moe.nea.firmament.util.collections.WeakCache import moe.nea.firmament.util.collections.WeakCache
import moe.nea.firmament.util.darkGreen
import moe.nea.firmament.util.lime
import moe.nea.firmament.util.mc.SNbtFormatter import moe.nea.firmament.util.mc.SNbtFormatter
import moe.nea.firmament.util.purple
import moe.nea.firmament.util.red
import moe.nea.firmament.util.tr import moe.nea.firmament.util.tr
import moe.nea.firmament.util.unformattedString import moe.nea.firmament.util.unformattedString
@@ -300,6 +315,23 @@ fun firmamentCommand() = literal("firmament") {
} }
} }
} }
thenLiteral("repo") {
thenExecute {
source.sendFeedback(tr("firmament.repo.info.ref", "Repo Upstream: ${RepoManager.getRepoRef()}"))
source.sendFeedback(tr("firmament.repo.info.downloadedref",
"Downloaded ref: ${RepoDownloadManager.latestSavedVersionHash}"))
source.sendFeedback(tr("firmament.repo.info.location",
"Saved location: ${debugPath(RepoDownloadManager.repoSavedLocation)}"))
source.sendFeedback(tr("firmament.repo.info.reloadstatus",
"Incomplete: ${formatBool(RepoManager.neuRepo.isIncomplete, trueIsGood = false)}, Unstable ${formatBool(RepoManager.neuRepo.isUnstable, trueIsGood = false)}"))
source.sendFeedback(tr("firmament.repo.info.items",
"Loaded items: ${RepoManager.neuRepo.items?.items?.size}"))
source.sendFeedback(tr("firmament.repo.info.itemcache",
"ItemCache flawless: ${formatBool(ItemCache.isFlawless)}"))
source.sendFeedback(tr("firmament.repo.info.itemdir",
"Items on disk: ${debugPath(RepoDownloadManager.repoSavedLocation.resolve("items"))}"))
}
}
} }
CommandEvent.SubCommand.publish(CommandEvent.SubCommand(this@literal)) CommandEvent.SubCommand.publish(CommandEvent.SubCommand(this@literal))
} }

View File

@@ -118,12 +118,20 @@ object RepoManager {
} }
fun reload() { fun reload() {
if (!TestUtil.isInTest && !MC.instance.isOnThread) {
MC.instance.send {
reload()
}
return
}
try { try {
ItemCache.ReloadProgressHud.reportProgress("Reloading from Disk", ItemCache.ReloadProgressHud.reportProgress("Reloading from Disk",
0, 0,
-1) // TODO: replace with a proper bouncy bar -1) // TODO: replace with a proper bouncy bar
ItemCache.ReloadProgressHud.isEnabled = true ItemCache.ReloadProgressHud.isEnabled = true
logger.info("Repo reload started.")
neuRepo.reload() neuRepo.reload()
logger.info("Repo reload completed.")
} catch (exc: NEURepositoryException) { } catch (exc: NEURepositoryException) {
ErrorUtil.softError("Failed to reload repository", exc) ErrorUtil.softError("Failed to reload repository", exc)
MC.sendChat( MC.sendChat(
@@ -171,4 +179,7 @@ object RepoManager {
return PetData(Rarity.entries[intIndex], petId, 0.0, true) return PetData(Rarity.entries[intIndex], petId, 0.0, true)
} }
fun getRepoRef(): String {
return "${Config.username}/${Config.reponame}#${Config.branch}"
}
} }

View File

@@ -1,9 +1,17 @@
package moe.nea.firmament.util package moe.nea.firmament.util
import com.google.common.math.IntMath.pow import com.google.common.math.IntMath.pow
import java.nio.file.Path
import kotlin.io.path.exists
import kotlin.io.path.fileSize
import kotlin.io.path.isDirectory
import kotlin.io.path.isReadable
import kotlin.io.path.isRegularFile
import kotlin.io.path.listDirectoryEntries
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
import kotlin.time.Duration import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds import kotlin.time.Duration.Companion.seconds
import net.minecraft.text.Text
object FirmFormatters { object FirmFormatters {
fun formatCommas(int: Int, segments: Int = 3): String = formatCommas(int.toLong(), segments) fun formatCommas(int: Int, segments: Int = 3): String = formatCommas(int.toLong(), segments)
@@ -62,4 +70,33 @@ object FirmFormatters {
return sb.toString() return sb.toString()
} }
fun debugPath(path: Path): Text {
if (!path.exists()) {
return tr("firmament.path.missing", "$path (missing)").red()
}
if (!path.isReadable()) {
return tr("firmament.path.unreadable", "$path (unreadable)").red()
}
if (path.isRegularFile()) {
return tr("firmament.path.regular",
"$path (exists ${formatFileSize(path.fileSize())})").lime()
}
if (path.isDirectory()) {
return tr("firmament.path.directory", "$path (${path.listDirectoryEntries().size} entries)").darkGreen()
}
return tr("firmament.path.unknown", "$path (unknown)").purple()
}
fun formatFileSize(fileSizeInBytes: Long): String {
return "${fileSizeInBytes / 1024} KiB"
}
fun formatBool(
boolean: Boolean,
trueIsGood: Boolean = true,
): Text {
val text = Text.literal(boolean.toString())
return if (boolean == trueIsGood) text.lime() else text.red()
}
} }

View File

@@ -130,6 +130,8 @@ fun MutableText.blue() = withColor(Formatting.BLUE)
fun MutableText.aqua() = withColor(Formatting.AQUA) fun MutableText.aqua() = withColor(Formatting.AQUA)
fun MutableText.lime() = withColor(Formatting.GREEN) fun MutableText.lime() = withColor(Formatting.GREEN)
fun MutableText.darkGreen() = withColor(Formatting.DARK_GREEN) fun MutableText.darkGreen() = withColor(Formatting.DARK_GREEN)
fun MutableText.purple() = withColor(Formatting.DARK_PURPLE)
fun MutableText.pink() = withColor(Formatting.LIGHT_PURPLE)
fun MutableText.yellow() = withColor(Formatting.YELLOW) fun MutableText.yellow() = withColor(Formatting.YELLOW)
fun MutableText.grey() = withColor(Formatting.GRAY) fun MutableText.grey() = withColor(Formatting.GRAY)
fun MutableText.red() = withColor(Formatting.RED) fun MutableText.red() = withColor(Formatting.RED)
@@ -165,6 +167,6 @@ fun Text.transformEachRecursively(function: (Text) -> Text): Text {
} }
} }
fun tr(key: String, default: String): Text = error("Compiler plugin did not run.") fun tr(key: String, default: String): MutableText = error("Compiler plugin did not run.")
fun trResolved(key: String, vararg args: Any) = Text.translatable(key, *args) fun trResolved(key: String, vararg args: Any): MutableText = Text.stringifiedTranslatable(key, *args)