diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index 5212f2d6..4e4566cd 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -568,6 +568,7 @@ object Starbound : ISBFileLocator { tasks.addAll(Registries.load(ext2files)) tasks.addAll(RecipeRegistry.load(ext2files)) tasks.addAll(GlobalDefaults.load()) + tasks.add(VersionRegistry.load()) val total = tasks.size.toDouble() diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/VersionRegistry.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/VersionRegistry.kt index 17d9e0f7..7d15ce9c 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/VersionRegistry.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/VersionRegistry.kt @@ -1,10 +1,12 @@ package ru.dbotthepony.kstarbound import com.google.gson.JsonElement +import com.google.gson.JsonObject import com.google.gson.TypeAdapter import com.google.gson.stream.JsonReader import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap import ru.dbotthepony.kstarbound.json.VersionedJson +import java.util.concurrent.Future object VersionRegistry { private val versions = Object2IntOpenHashMap() @@ -28,4 +30,15 @@ object VersionRegistry { } 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 + } + }) + } } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/JsonUtils.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/JsonUtils.kt index f4165c4a..efb1c9f0 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/JsonUtils.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/json/JsonUtils.kt @@ -10,9 +10,11 @@ import com.google.gson.JsonNull import com.google.gson.JsonObject import com.google.gson.TypeAdapter import com.google.gson.reflect.TypeToken +import com.google.gson.stream.JsonReader import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet import ru.dbotthepony.kommons.gson.set import ru.dbotthepony.kstarbound.Starbound +import ru.dbotthepony.kstarbound.fromJson inline fun Gson.getAdapter(): TypeAdapter { return getAdapter(object : TypeToken() {})