mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
replace redirect delegate
Won't work out without fucking up jacksons internals
This commit is contained in:
parent
60036f7f9a
commit
ac63265e12
@ -77,8 +77,6 @@ class RedirectDelegateTest {
|
|||||||
val profile = create()
|
val profile = create()
|
||||||
profile.config.prop = Boxed(123, true)
|
profile.config.prop = Boxed(123, true)
|
||||||
val data = profile.serialize()
|
val data = profile.serialize()
|
||||||
assertEquals(data, mapOf("config" to mapOf("prop" to 123, "normal" to "test")))
|
assertEquals(data, mapOf("config" to mapOf("prop" to 123, "normal" to "test"), "key" to 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -74,4 +74,6 @@ class StorageProfileManagerTest {
|
|||||||
profile.key = 999
|
profile.key = 999
|
||||||
assertTrue(profile.isSaveQueued())
|
assertTrue(profile.isSaveQueued())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: test reload, delete and selected queue
|
||||||
}
|
}
|
||||||
|
@ -13,14 +13,27 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.config.profile.test.config
|
package de.bixilon.minosoft.config.profile.test.config
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import de.bixilon.kutil.observer.DataObserver.Companion.observe
|
||||||
import de.bixilon.minosoft.config.profile.Boxed
|
import de.bixilon.minosoft.config.profile.Boxed
|
||||||
import de.bixilon.minosoft.config.profile.delegate.types.RedirectDelegate
|
import de.bixilon.minosoft.config.profile.delegate.SimpleDelegate
|
||||||
|
import de.bixilon.minosoft.config.profile.delegate.primitive.IntDelegate
|
||||||
import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate
|
import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate
|
||||||
import de.bixilon.minosoft.config.profile.profiles.Profile
|
import de.bixilon.minosoft.config.profile.profiles.Profile
|
||||||
|
|
||||||
class ConfigC(profile: Profile) {
|
class ConfigC(profile: Profile) {
|
||||||
@get:JsonDeserialize(using = RedirectDelegate.RedirectDeserializer::class)
|
|
||||||
var prop by RedirectDelegate<Boxed?, Int?>(profile, { it?.value }, { it?.let { Boxed(it, false) } })
|
@get:JsonProperty("prop")
|
||||||
|
private var _prop by IntDelegate(profile, 0)
|
||||||
|
|
||||||
|
@get:JsonIgnore
|
||||||
|
var prop: Boxed? by SimpleDelegate(profile, null)
|
||||||
|
|
||||||
|
init {
|
||||||
|
this::prop.observe(this) { _prop = it?.value ?: 0 }
|
||||||
|
this::_prop.observe(this) { prop = Boxed(it, false) }
|
||||||
|
}
|
||||||
|
|
||||||
var normal by StringDelegate(profile, "test")
|
var normal by StringDelegate(profile, "test")
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import de.bixilon.kutil.concurrent.pool.ThreadPool
|
|||||||
import de.bixilon.kutil.concurrent.pool.runnable.ForcePooledRunnable
|
import de.bixilon.kutil.concurrent.pool.runnable.ForcePooledRunnable
|
||||||
import de.bixilon.kutil.concurrent.worker.task.TaskWorker
|
import de.bixilon.kutil.concurrent.worker.task.TaskWorker
|
||||||
import de.bixilon.kutil.concurrent.worker.task.WorkerTask
|
import de.bixilon.kutil.concurrent.worker.task.WorkerTask
|
||||||
import de.bixilon.kutil.file.watcher.FileWatcherService
|
|
||||||
import de.bixilon.kutil.latch.AbstractLatch
|
import de.bixilon.kutil.latch.AbstractLatch
|
||||||
import de.bixilon.kutil.latch.CallbackLatch
|
import de.bixilon.kutil.latch.CallbackLatch
|
||||||
import de.bixilon.kutil.latch.SimpleLatch
|
import de.bixilon.kutil.latch.SimpleLatch
|
||||||
@ -102,8 +101,7 @@ object Minosoft {
|
|||||||
val taskWorker = TaskWorker(errorHandler = { _, error -> error.printStackTrace(); error.crash() })
|
val taskWorker = TaskWorker(errorHandler = { _, error -> error.printStackTrace(); error.crash() })
|
||||||
|
|
||||||
taskWorker += WorkerTask(identifier = BootTasks.VERSIONS, priority = ThreadPool.HIGHER, executor = VersionLoader::load)
|
taskWorker += WorkerTask(identifier = BootTasks.VERSIONS, priority = ThreadPool.HIGHER, executor = VersionLoader::load)
|
||||||
taskWorker += WorkerTask(identifier = BootTasks.FILE_WATCHER, priority = ThreadPool.HIGHER, optional = true, executor = this::startFileWatcherService)
|
taskWorker += WorkerTask(identifier = BootTasks.PROFILES, priority = ThreadPool.HIGHEST, executor = ProfileManagers::load)
|
||||||
taskWorker += WorkerTask(identifier = BootTasks.PROFILES, priority = ThreadPool.HIGHER, dependencies = arrayOf(BootTasks.FILE_WATCHER), executor = ProfileManagers::load)
|
|
||||||
|
|
||||||
taskWorker += WorkerTask(identifier = BootTasks.LANGUAGE_FILES, dependencies = arrayOf(BootTasks.PROFILES), executor = this::loadLanguageFiles)
|
taskWorker += WorkerTask(identifier = BootTasks.LANGUAGE_FILES, dependencies = arrayOf(BootTasks.PROFILES), executor = this::loadLanguageFiles)
|
||||||
taskWorker += WorkerTask(identifier = BootTasks.ASSETS_PROPERTIES, dependencies = arrayOf(BootTasks.VERSIONS), executor = AssetsVersionProperties::load)
|
taskWorker += WorkerTask(identifier = BootTasks.ASSETS_PROPERTIES, dependencies = arrayOf(BootTasks.VERSIONS), executor = AssetsVersionProperties::load)
|
||||||
@ -172,12 +170,6 @@ object Minosoft {
|
|||||||
postBoot()
|
postBoot()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startFileWatcherService(latch: AbstractLatch?) {
|
|
||||||
Log.log(LogMessageType.GENERAL, LogLevels.VERBOSE) { "Starting file watcher service..." }
|
|
||||||
FileWatcherService.start()
|
|
||||||
Log.log(LogMessageType.GENERAL, LogLevels.VERBOSE) { "File watcher service started!" }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadLanguageFiles(latch: AbstractLatch?) {
|
private fun loadLanguageFiles(latch: AbstractLatch?) {
|
||||||
val language = ErosProfileManager.selected.general.language
|
val language = ErosProfileManager.selected.general.language
|
||||||
ErosProfileManager.selected.general::language.observe(this, true) {
|
ErosProfileManager.selected.general::language.observe(this, true) {
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Minosoft
|
|
||||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.bixilon.minosoft.config.profile.delegate.types
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParser
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
|
||||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
|
|
||||||
import de.bixilon.kutil.observer.DataObserver
|
|
||||||
import de.bixilon.minosoft.config.profile.delegate.AbstractProfileDelegate
|
|
||||||
import de.bixilon.minosoft.config.profile.profiles.Profile
|
|
||||||
import kotlin.reflect.KProperty
|
|
||||||
|
|
||||||
@JsonDeserialize(using = RedirectDelegate.RedirectDeserializer::class)
|
|
||||||
class RedirectDelegate<V, S>(
|
|
||||||
override val profile: Profile,
|
|
||||||
val serializer: (V?) -> S?,
|
|
||||||
val lookup: (S?) -> V?,
|
|
||||||
) : DataObserver<V?>(null), AbstractProfileDelegate<V?> {
|
|
||||||
|
|
||||||
|
|
||||||
override fun setValue(thisRef: Any, property: KProperty<*>, value: V?) {
|
|
||||||
super.setValue(thisRef, property, value)
|
|
||||||
invalidate()
|
|
||||||
}
|
|
||||||
|
|
||||||
// fun setValue(thisRef: Any, property: KProperty<*>, value: S?) {
|
|
||||||
// setValue(thisRef, property, lookup(value))
|
|
||||||
// }
|
|
||||||
|
|
||||||
object RedirectDeserializer : StdDeserializer<Any>(Any::class.java) {
|
|
||||||
|
|
||||||
override fun deserialize(parser: JsonParser, context: DeserializationContext?): Any {
|
|
||||||
return "test"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -14,6 +14,7 @@
|
|||||||
package de.bixilon.minosoft.config.profile.manager
|
package de.bixilon.minosoft.config.profile.manager
|
||||||
|
|
||||||
import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker
|
import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker
|
||||||
|
import de.bixilon.kutil.file.watcher.FileWatcherService
|
||||||
import de.bixilon.kutil.latch.AbstractLatch
|
import de.bixilon.kutil.latch.AbstractLatch
|
||||||
import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager
|
import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager
|
||||||
import de.bixilon.minosoft.config.profile.profiles.audio.AudioProfileManager
|
import de.bixilon.minosoft.config.profile.profiles.audio.AudioProfileManager
|
||||||
@ -30,6 +31,7 @@ import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfileMan
|
|||||||
import de.bixilon.minosoft.config.profile.storage.ProfileIOManager
|
import de.bixilon.minosoft.config.profile.storage.ProfileIOManager
|
||||||
import de.bixilon.minosoft.config.profile.storage.StorageProfileManager
|
import de.bixilon.minosoft.config.profile.storage.StorageProfileManager
|
||||||
import de.bixilon.minosoft.data.registries.factory.DefaultFactory
|
import de.bixilon.minosoft.data.registries.factory.DefaultFactory
|
||||||
|
import de.bixilon.minosoft.terminal.RunConfiguration
|
||||||
|
|
||||||
object ProfileManagers : DefaultFactory<StorageProfileManager<*>>(
|
object ProfileManagers : DefaultFactory<StorageProfileManager<*>>(
|
||||||
ErosProfileManager,
|
ErosProfileManager,
|
||||||
@ -48,6 +50,9 @@ object ProfileManagers : DefaultFactory<StorageProfileManager<*>>(
|
|||||||
|
|
||||||
|
|
||||||
fun load(latch: AbstractLatch?) {
|
fun load(latch: AbstractLatch?) {
|
||||||
|
if (RunConfiguration.PROFILES_HOT_RELOADING) {
|
||||||
|
FileWatcherService.start() // TODO: remove kutil race condition
|
||||||
|
}
|
||||||
val worker = UnconditionalWorker()
|
val worker = UnconditionalWorker()
|
||||||
for (manager in ProfileManagers) {
|
for (manager in ProfileManagers) {
|
||||||
worker += { manager.load() }
|
worker += { manager.load() }
|
||||||
|
@ -13,11 +13,14 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.config.profile.profiles.account
|
package de.bixilon.minosoft.config.profile.profiles.account
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude
|
import com.fasterxml.jackson.annotation.JsonInclude
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import de.bixilon.kutil.observer.DataObserver.Companion.observe
|
||||||
import de.bixilon.minosoft.config.profile.ProfileLock
|
import de.bixilon.minosoft.config.profile.ProfileLock
|
||||||
import de.bixilon.minosoft.config.profile.ProfileType
|
import de.bixilon.minosoft.config.profile.ProfileType
|
||||||
|
import de.bixilon.minosoft.config.profile.delegate.SimpleDelegate
|
||||||
import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate
|
import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate
|
||||||
import de.bixilon.minosoft.config.profile.delegate.types.RedirectDelegate
|
|
||||||
import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate
|
import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate
|
||||||
import de.bixilon.minosoft.config.profile.delegate.types.map.MapDelegate
|
import de.bixilon.minosoft.config.profile.delegate.types.map.MapDelegate
|
||||||
import de.bixilon.minosoft.config.profile.profiles.Profile
|
import de.bixilon.minosoft.config.profile.profiles.Profile
|
||||||
@ -58,7 +61,16 @@ class AccountProfile(
|
|||||||
var entries: MutableMap<String, Account> by MapDelegate(this, mutableMapOf())
|
var entries: MutableMap<String, Account> by MapDelegate(this, mutableMapOf())
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var selected: Account? by RedirectDelegate<Account?, String?>(this, { it?.id }, { entries[it] })
|
@get:JsonProperty("selected")
|
||||||
|
private var _selected: String? by SimpleDelegate(this, null)
|
||||||
|
|
||||||
|
@get:JsonIgnore
|
||||||
|
var selected: Account? by SimpleDelegate(this, null)
|
||||||
|
|
||||||
|
init {
|
||||||
|
this::selected.observe(this) { _selected = it?.id }
|
||||||
|
this::_selected.observe(this) { selected = entries[it] }
|
||||||
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return storage?.toString() ?: super.toString()
|
return storage?.toString() ?: super.toString()
|
||||||
|
@ -14,12 +14,14 @@
|
|||||||
package de.bixilon.minosoft.config.profile.profiles.eros.server.entries
|
package de.bixilon.minosoft.config.profile.profiles.eros.server.entries
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JacksonInject
|
import com.fasterxml.jackson.annotation.JacksonInject
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude
|
import com.fasterxml.jackson.annotation.JsonInclude
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import de.bixilon.kutil.observer.DataObserver.Companion.observe
|
||||||
import de.bixilon.minosoft.assets.util.HashTypes
|
import de.bixilon.minosoft.assets.util.HashTypes
|
||||||
import de.bixilon.minosoft.config.profile.delegate.SimpleDelegate
|
import de.bixilon.minosoft.config.profile.delegate.SimpleDelegate
|
||||||
import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate
|
import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate
|
||||||
import de.bixilon.minosoft.config.profile.delegate.types.NullableStringDelegate
|
import de.bixilon.minosoft.config.profile.delegate.types.NullableStringDelegate
|
||||||
import de.bixilon.minosoft.config.profile.delegate.types.RedirectDelegate
|
|
||||||
import de.bixilon.minosoft.config.profile.delegate.types.map.MapDelegate
|
import de.bixilon.minosoft.config.profile.delegate.types.map.MapDelegate
|
||||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile
|
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile
|
||||||
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||||
@ -63,8 +65,17 @@ class ErosServer(
|
|||||||
@get:JsonInclude(JsonInclude.Include.NON_EMPTY)
|
@get:JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
override var profiles: MutableMap<ResourceLocation, String> by MapDelegate(profile, profiles)
|
override var profiles: MutableMap<ResourceLocation, String> by MapDelegate(profile, profiles)
|
||||||
|
|
||||||
|
@get:JsonProperty("forcedVersion")
|
||||||
@get:JsonInclude(JsonInclude.Include.NON_NULL)
|
@get:JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
override var forcedVersion: Version? by RedirectDelegate<Version?, String?>(profile, { it?.name }, { Versions[it] })
|
private var _forcedVersion: String? by SimpleDelegate(profile, null)
|
||||||
|
|
||||||
|
@get:JsonIgnore
|
||||||
|
override var forcedVersion: Version? by SimpleDelegate(profile, null)
|
||||||
|
|
||||||
|
init {
|
||||||
|
this::forcedVersion.observe(this) { _forcedVersion = it?.name }
|
||||||
|
this::_forcedVersion.observe(this) { this.forcedVersion = Versions[it] }
|
||||||
|
}
|
||||||
|
|
||||||
@get:JsonInclude(JsonInclude.Include.NON_DEFAULT)
|
@get:JsonInclude(JsonInclude.Include.NON_DEFAULT)
|
||||||
override var faviconHash: String? by NullableStringDelegate(profile, null) { if (it != null) check(it.length == HashTypes.SHA256.length) { "Not a valid sha256 hash!" } }
|
override var faviconHash: String? by NullableStringDelegate(profile, null) { if (it != null) check(it.length == HashTypes.SHA256.length) { "Not a valid sha256 hash!" } }
|
||||||
|
@ -20,7 +20,6 @@ enum class BootTasks {
|
|||||||
ASSETS_PROPERTIES,
|
ASSETS_PROPERTIES,
|
||||||
DEFAULT_REGISTRIES,
|
DEFAULT_REGISTRIES,
|
||||||
LAN_SERVERS,
|
LAN_SERVERS,
|
||||||
FILE_WATCHER,
|
|
||||||
YGGDRASIL,
|
YGGDRASIL,
|
||||||
STARTUP_PROGRESS,
|
STARTUP_PROGRESS,
|
||||||
ASSETS_OVERRIDE,
|
ASSETS_OVERRIDE,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user