Actually load versioning.config

This commit is contained in:
DBotThePony 2024-04-02 21:57:53 +07:00
parent 66a3f0304a
commit 3b2e1d06c3
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 16 additions and 0 deletions

View File

@ -568,6 +568,7 @@ object Starbound : ISBFileLocator {
tasks.addAll(Registries.load(ext2files)) tasks.addAll(Registries.load(ext2files))
tasks.addAll(RecipeRegistry.load(ext2files)) tasks.addAll(RecipeRegistry.load(ext2files))
tasks.addAll(GlobalDefaults.load()) tasks.addAll(GlobalDefaults.load())
tasks.add(VersionRegistry.load())
val total = tasks.size.toDouble() val total = tasks.size.toDouble()

View File

@ -1,10 +1,12 @@
package ru.dbotthepony.kstarbound package ru.dbotthepony.kstarbound
import com.google.gson.JsonElement import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.google.gson.TypeAdapter import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonReader
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
import ru.dbotthepony.kstarbound.json.VersionedJson import ru.dbotthepony.kstarbound.json.VersionedJson
import java.util.concurrent.Future
object VersionRegistry { object VersionRegistry {
private val versions = Object2IntOpenHashMap<String>() private val versions = Object2IntOpenHashMap<String>()
@ -28,4 +30,15 @@ object VersionRegistry {
} }
private val adapter by lazy { Starbound.gson.getAdapter(VersionedJson::class.java) } private val adapter by lazy { Starbound.gson.getAdapter(VersionedJson::class.java) }
fun load(): Future<*> {
return Starbound.EXECUTOR.submit(Runnable {
val json = Starbound.loadJsonAsset("/versioning.config") ?: throw NoSuchElementException("Unable to load /versioning.config! Expect HUGE problems!")
json as JsonObject
for ((k, v) in json.entrySet()) {
versions[k] = v.asInt
}
})
}
} }

View File

@ -10,9 +10,11 @@ import com.google.gson.JsonNull
import com.google.gson.JsonObject import com.google.gson.JsonObject
import com.google.gson.TypeAdapter import com.google.gson.TypeAdapter
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.google.gson.stream.JsonReader
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
import ru.dbotthepony.kommons.gson.set import ru.dbotthepony.kommons.gson.set
import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.Starbound
import ru.dbotthepony.kstarbound.fromJson
inline fun <reified T> Gson.getAdapter(): TypeAdapter<T> { inline fun <reified T> Gson.getAdapter(): TypeAdapter<T> {
return getAdapter(object : TypeToken<T>() {}) return getAdapter(object : TypeToken<T>() {})