aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/repo
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-05-24 02:29:20 +0200
committernea <nea@nea.moe>2023-05-24 02:29:20 +0200
commit5984383d2c48b4ae84bac1827bc6ca1891af8cf0 (patch)
tree90aaae93147ce7aad48777be488039626b70512a /src/main/kotlin/moe/nea/firmament/repo
parent5ff50799b6c8baf6dd87ecbf44860d19a4acceab (diff)
downloadfirmament-5984383d2c48b4ae84bac1827bc6ca1891af8cf0.tar.gz
firmament-5984383d2c48b4ae84bac1827bc6ca1891af8cf0.tar.bz2
firmament-5984383d2c48b4ae84bac1827bc6ca1891af8cf0.zip
Common config gui
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/repo')
-rw-r--r--src/main/kotlin/moe/nea/firmament/repo/RepoDownloadManager.kt4
-rw-r--r--src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt29
2 files changed, 18 insertions, 15 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/repo/RepoDownloadManager.kt b/src/main/kotlin/moe/nea/firmament/repo/RepoDownloadManager.kt
index 09b246a..611a4e1 100644
--- a/src/main/kotlin/moe/nea/firmament/repo/RepoDownloadManager.kt
+++ b/src/main/kotlin/moe/nea/firmament/repo/RepoDownloadManager.kt
@@ -50,7 +50,7 @@ object RepoDownloadManager {
private suspend fun requestLatestGithubSha(): String? {
val response =
- Firmament.httpClient.get("https://api.github.com/repos/${RepoManager.data.user}/${RepoManager.data.repo}/commits/${RepoManager.data.branch}")
+ Firmament.httpClient.get("https://api.github.com/repos/${RepoManager.Config.username}/${RepoManager.Config.reponame}/commits/${RepoManager.Config.branch}")
if (response.status.value != 200) {
return null
}
@@ -77,7 +77,7 @@ object RepoDownloadManager {
}
val currentSha = loadSavedVersionHash()
if (latestSha != currentSha || force) {
- val requestUrl = "https://github.com/${RepoManager.data.user}/${RepoManager.data.repo}/archive/$latestSha.zip"
+ val requestUrl = "https://github.com/${RepoManager.Config.username}/${RepoManager.Config.reponame}/archive/$latestSha.zip"
logger.info("Planning to upgrade repository from $currentSha to $latestSha from $requestUrl")
val zipFile = downloadGithubArchive(requestUrl)
logger.info("Download repository zip file to $zipFile. Deleting old repository")
diff --git a/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt b/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt
index b1091fc..ea77fc1 100644
--- a/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt
+++ b/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt
@@ -8,8 +8,6 @@ import io.github.moulberry.repo.data.NEUItem
import io.github.moulberry.repo.data.NEURecipe
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import kotlinx.coroutines.launch
-import kotlinx.serialization.Serializable
-import kotlinx.serialization.serializer
import net.minecraft.client.MinecraftClient
import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket
import net.minecraft.text.Text
@@ -17,16 +15,21 @@ import moe.nea.firmament.Firmament
import moe.nea.firmament.Firmament.logger
import moe.nea.firmament.hud.ProgressBar
import moe.nea.firmament.util.SkyblockId
-import moe.nea.firmament.util.data.DataHolder
-
-object RepoManager : DataHolder<RepoManager.Config>(serializer(), "repo", ::Config) {
- @Serializable
- data class Config(
- var user: String = "NotEnoughUpdates",
- var repo: String = "NotEnoughUpdates-REPO",
- var autoUpdate: Boolean = true,
- var branch: String = "dangerous",
- )
+import moe.nea.firmament.gui.config.ManagedConfig
+
+object RepoManager {
+ object Config : ManagedConfig("repo") {
+ var username by string("username") { "NotEnoughUpdates" }
+ var reponame by string("reponame") { "NotEnoughUpdates-REPO" }
+ var branch by string("branch") { "prerelease" }
+ val autoUpdate by toggle("autoUpdate") { true }
+ val reset by button("reset") {
+ username = "NotEnoughUpdates"
+ reponame = "NotEnoughUpdates-REPO"
+ branch = "prerelease"
+ save()
+ }
+ }
val currentDownloadedSha by RepoDownloadManager::latestSavedVersionHash
@@ -93,7 +96,7 @@ object RepoManager : DataHolder<RepoManager.Config>(serializer(), "repo", ::Conf
}
fun initialize() {
- if (data.autoUpdate) {
+ if (Config.autoUpdate) {
launchAsyncUpdate()
} else {
reload()