aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/repo
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-07-01 03:42:51 +0200
committerLinnea Gräf <nea@nea.moe>2024-07-03 21:05:51 +0200
commit5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e (patch)
treea5b0a6fbc8878ae62bb2c3a01dbb255388353fda /src/main/kotlin/moe/nea/firmament/repo
parentdff1f9c0e2b728dba902d72816104abccc61f511 (diff)
downloadFirmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.gz
Firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.bz2
Firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.zip
[WIP] Remove LibGUI
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/repo')
-rw-r--r--src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt41
-rw-r--r--src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt23
2 files changed, 41 insertions, 23 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt b/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt
index adeb1c5..21d264c 100644
--- a/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt
+++ b/src/main/kotlin/moe/nea/firmament/repo/ItemCache.kt
@@ -8,12 +8,12 @@
package moe.nea.firmament.repo
import com.mojang.serialization.Dynamic
-import io.github.cottonmc.cotton.gui.client.CottonHud
import io.github.moulberry.repo.IReloadable
import io.github.moulberry.repo.NEURepository
import io.github.moulberry.repo.data.NEUItem
+import io.github.notenoughupdates.moulconfig.xml.Bind
import java.text.NumberFormat
-import java.util.*
+import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
import org.apache.logging.log4j.LogManager
import kotlinx.coroutines.Job
@@ -32,6 +32,9 @@ import net.minecraft.nbt.NbtElement
import net.minecraft.nbt.NbtOps
import net.minecraft.text.Text
import moe.nea.firmament.Firmament
+import moe.nea.firmament.gui.config.HudMeta
+import moe.nea.firmament.gui.config.HudPosition
+import moe.nea.firmament.gui.hud.MoulConfigHud
import moe.nea.firmament.util.LegacyTagParser
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SkyblockId
@@ -135,6 +138,30 @@ object ItemCache : IReloadable {
fun NEUItem.getIdentifier() = skyblockId.identifier
var job: Job? = null
+ object ReloadProgressHud : MoulConfigHud(
+ "repo_reload", HudMeta(HudPosition(0.0, 0.0, 1F), Text.literal("Repo Reload"), 180, 18)) {
+
+
+ var isEnabled = false
+ override fun shouldRender(): Boolean {
+ return isEnabled
+ }
+
+ @get:Bind("current")
+ var current: Double = 0.0
+
+ @get:Bind("label")
+ var label: String = ""
+
+ @get:Bind("max")
+ var max: Double = 0.0
+
+ fun reportProgress(label: String, current: Int, max: Int) {
+ this.label = label
+ this.current = current.toDouble()
+ this.max = max.toDouble()
+ }
+ }
override fun reload(repository: NEURepository) {
val j = job
@@ -147,18 +174,18 @@ object ItemCache : IReloadable {
job = Firmament.coroutineScope.launch {
val items = repository.items?.items
if (items == null) {
- CottonHud.remove(RepoManager.progressBar)
+ ReloadProgressHud.isEnabled = false
return@launch
}
val recacheItems = I18n.translate("firmament.repo.cache")
- RepoManager.progressBar.reportProgress(recacheItems, 0, items.size)
- CottonHud.add(RepoManager.progressBar)
+ ReloadProgressHud.reportProgress(recacheItems, 0, items.size)
+ ReloadProgressHud.isEnabled = true
var i = 0
items.values.forEach {
it.asItemStack() // Rebuild cache
- RepoManager.progressBar.reportProgress(recacheItems, i++, items.size)
+ ReloadProgressHud.reportProgress(recacheItems, i++, items.size)
}
- CottonHud.remove(RepoManager.progressBar)
+ ReloadProgressHud.isEnabled = false
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt b/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt
index db17e6a..f556a8b 100644
--- a/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt
+++ b/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt
@@ -6,7 +6,6 @@
package moe.nea.firmament.repo
-import io.github.cottonmc.cotton.gui.client.CottonHud
import io.github.moulberry.repo.NEURecipeCache
import io.github.moulberry.repo.NEURepository
import io.github.moulberry.repo.NEURepositoryException
@@ -21,7 +20,6 @@ import net.minecraft.text.Text
import moe.nea.firmament.Firmament
import moe.nea.firmament.Firmament.logger
import moe.nea.firmament.gui.config.ManagedConfig
-import moe.nea.firmament.hud.ProgressBar
import moe.nea.firmament.rei.PetData
import moe.nea.firmament.util.MinecraftDispatcher
import moe.nea.firmament.util.SkyblockId
@@ -54,12 +52,6 @@ object RepoManager {
var recentlyFailedToUpdateItemList = false
- val progressBar by lazy {
- ProgressBar("", null, 0).also {
- it.setSize(180, 22)
- }
- }
-
val neuRepo: NEURepository = NEURepository.of(RepoDownloadManager.repoSavedLocation).apply {
registerReloadListener(ItemCache)
registerReloadListener(ExpLadders)
@@ -98,14 +90,13 @@ object RepoManager {
fun launchAsyncUpdate(force: Boolean = false) {
Firmament.coroutineScope.launch {
- progressBar.reportProgress("Downloading", 0, null)
- CottonHud.add(progressBar)
+ ItemCache.ReloadProgressHud.reportProgress("Downloading", 0, -1) // TODO: replace with a proper boundy bar
+ ItemCache.ReloadProgressHud.isEnabled = true
try {
RepoDownloadManager.downloadUpdate(force)
- progressBar.reportProgress("Download complete", 1, 1)
+ ItemCache.ReloadProgressHud.reportProgress("Download complete", 1, 1)
} finally {
- CottonHud.remove(progressBar)
-
+ ItemCache.ReloadProgressHud.isEnabled = false
}
reload()
}
@@ -113,14 +104,14 @@ object RepoManager {
fun reload() {
try {
- progressBar.reportProgress("Reloading from Disk", 0, null)
- CottonHud.add(progressBar)
+ ItemCache.ReloadProgressHud.reportProgress("Reloading from Disk", 0, -1) // TODO: replace with a proper boundy bar
+ ItemCache.ReloadProgressHud.isEnabled = true
neuRepo.reload()
} catch (exc: NEURepositoryException) {
MinecraftClient.getInstance().player?.sendMessage(
Text.literal("Failed to reload repository. This will result in some mod features not working.")
)
- CottonHud.remove(progressBar)
+ ItemCache.ReloadProgressHud.isEnabled = false
exc.printStackTrace()
}
}