From 007633274c28e5958684e40ff65f3ae162c15be9 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Mon, 28 Nov 2022 08:53:04 +0100 Subject: [PATCH] profiles: replace almost all delegates with custom delegates --- .../minosoft/config/profile/ProfileManager.kt | 10 +++--- .../delegate/primitive/BooleanDelegate.kt | 2 +- .../delegate/{ => types}/ColorDelegate.kt | 3 +- .../profile/delegate/types/EnumDelegate.kt | 28 +++++++++++++++ .../delegate/types/LanguageDelegate.kt | 26 ++++++++++++++ .../delegate/types/NullableStringDelegate.kt | 26 ++++++++++++++ .../profile/delegate/types/StringDelegate.kt | 26 ++++++++++++++ .../profile/delegate/types/map/LogDelegate.kt | 24 +++++++++++++ .../profile/delegate/types/map/MapDelegate.kt | 36 +++++++++++++++++++ .../profiles/account/AccountProfile.kt | 12 ++++--- .../profile/profiles/audio/AudioProfile.kt | 4 +-- .../profile/profiles/block/BlockProfile.kt | 4 +-- .../profiles/block/outline/OutlineC.kt | 2 +- .../profiles/connection/ConnectionProfile.kt | 21 ++++++----- .../connection/signature/SignatureC.kt | 13 +++---- .../profile/profiles/connection/skin/SkinC.kt | 19 +++++----- .../profiles/controls/ControlsProfile.kt | 8 ++--- .../controls/interaction/InteractionC.kt | 11 +++--- .../profile/profiles/controls/mouse/MouseC.kt | 9 ++--- .../profile/profiles/entity/EntityProfile.kt | 6 ++-- .../profile/profiles/entity/hitbox/HitboxC.kt | 15 ++++---- .../profile/profiles/eros/ErosProfile.kt | 12 +++---- .../profile/profiles/eros/general/GeneralC.kt | 15 ++++---- .../profile/profiles/eros/server/ServerC.kt | 7 ++-- .../profiles/eros/server/list/ListC.kt | 15 +++++--- .../profiles/eros/server/modify/ModifyC.kt | 9 ++--- .../profile/profiles/eros/text/TextC.kt | 11 +++--- .../profile/profiles/eros/theme/ThemeC.kt | 7 ++-- .../config/profile/profiles/gui/GUIProfile.kt | 15 ++++---- .../config/profile/profiles/gui/chat/ChatC.kt | 21 ++++++----- .../profiles/gui/chat/internal/InternalC.kt | 14 ++++---- .../gui/confirmation/ConfirmationC.kt | 13 +++---- .../config/profile/profiles/gui/hud/HudC.kt | 9 ++--- .../profiles/gui/hud/crosshair/CrosshairC.kt | 10 +++--- .../profiles/gui/hud/hotbar/HotbarC.kt | 7 ++-- .../profiles/gui/hud/hotbar/hunger/HungerC.kt | 9 ++--- .../config/profile/profiles/gui/sign/SignC.kt | 7 ++-- .../profile/profiles/other/OtherProfile.kt | 11 +++--- .../config/profile/profiles/other/log/LogC.kt | 11 +++--- .../profiles/particle/ParticleProfile.kt | 17 ++++----- .../profile/profiles/particle/types/TypesC.kt | 9 ++--- .../profiles/rendering/RenderingProfile.kt | 4 +-- 42 files changed, 372 insertions(+), 166 deletions(-) rename src/main/java/de/bixilon/minosoft/config/profile/delegate/{ => types}/ColorDelegate.kt (89%) create mode 100644 src/main/java/de/bixilon/minosoft/config/profile/delegate/types/EnumDelegate.kt create mode 100644 src/main/java/de/bixilon/minosoft/config/profile/delegate/types/LanguageDelegate.kt create mode 100644 src/main/java/de/bixilon/minosoft/config/profile/delegate/types/NullableStringDelegate.kt create mode 100644 src/main/java/de/bixilon/minosoft/config/profile/delegate/types/StringDelegate.kt create mode 100644 src/main/java/de/bixilon/minosoft/config/profile/delegate/types/map/LogDelegate.kt create mode 100644 src/main/java/de/bixilon/minosoft/config/profile/delegate/types/map/MapDelegate.kt diff --git a/src/main/java/de/bixilon/minosoft/config/profile/ProfileManager.kt b/src/main/java/de/bixilon/minosoft/config/profile/ProfileManager.kt index c201b2cd1..4a9ca96a0 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/ProfileManager.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/ProfileManager.kt @@ -63,7 +63,7 @@ interface ProfileManager { val profiles: AbstractMutableBiMap var selected: T - @Deprecated("Should not be accessed") var currentLoadingPath: String? + @Deprecated("Should not be accessed", level = DeprecationLevel.ERROR) var currentLoadingPath: String? val baseDirectory: File get() = File(RunConfiguration.HOME_DIRECTORY + "config/" + namespace.namespace + "/") @@ -92,7 +92,7 @@ interface ProfileManager { return profile } - @Deprecated("") + @Deprecated("", level = DeprecationLevel.ERROR) fun delegate(value: V, verify: ((V) -> Unit)? = null): ProfileDelegate { return ProfileDelegate(value, this, currentLoadingPath ?: throw IllegalAccessException("Delegate can only be created while loading or creating profiles!"), verify) } @@ -106,17 +106,17 @@ interface ProfileManager { } } - @Deprecated("") + @Deprecated("", level = DeprecationLevel.ERROR) fun mapDelegate(default: MutableMap = mutableMapOf(), verify: ((MapChangeListener.Change) -> Unit)? = null): MapDelegateProfile { return MapDelegateProfile(FXCollections.synchronizedObservableMap(FXCollections.observableMap(default)), profileManager = this, profileName = currentLoadingPath ?: throw IllegalAccessException("Delegate can only be created while loading or creating profiles!"), verify = verify) } - @Deprecated("") + @Deprecated("", level = DeprecationLevel.ERROR) fun listDelegate(default: MutableList = mutableListOf(), verify: ((ListChangeListener.Change) -> Unit)? = null): ListDelegateProfile { return ListDelegateProfile(FXCollections.synchronizedObservableList(FXCollections.observableList(default)), profileManager = this, profileName = currentLoadingPath ?: throw IllegalAccessException("Delegate can only be created while loading or creating profiles!"), verify = verify) } - @Deprecated("") + @Deprecated("", level = DeprecationLevel.ERROR) fun setDelegate(default: MutableSet = mutableSetOf(), verify: ((SetChangeListener.Change) -> Unit)? = null): SetDelegateProfile { return SetDelegateProfile(FXCollections.synchronizedObservableSet(FXCollections.observableSet(default)), profileManager = this, profileName = currentLoadingPath ?: throw IllegalAccessException("Delegate can only be created while loading or creating profiles!"), verify = verify) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/delegate/primitive/BooleanDelegate.kt b/src/main/java/de/bixilon/minosoft/config/profile/delegate/primitive/BooleanDelegate.kt index a454c81ac..e8e698d38 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/delegate/primitive/BooleanDelegate.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/delegate/primitive/BooleanDelegate.kt @@ -19,7 +19,7 @@ import de.bixilon.minosoft.config.profile.profiles.Profile open class BooleanDelegate( override val profile: Profile, default: Boolean, - name: String, + name: String = "", ) : SimpleDelegate(profile, default, name) { override fun validate(value: Boolean) = Unit diff --git a/src/main/java/de/bixilon/minosoft/config/profile/delegate/ColorDelegate.kt b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/ColorDelegate.kt similarity index 89% rename from src/main/java/de/bixilon/minosoft/config/profile/delegate/ColorDelegate.kt rename to src/main/java/de/bixilon/minosoft/config/profile/delegate/types/ColorDelegate.kt index 7bac32bf3..047429f29 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/delegate/ColorDelegate.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/ColorDelegate.kt @@ -11,8 +11,9 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.config.profile.delegate +package de.bixilon.minosoft.config.profile.delegate.types +import de.bixilon.minosoft.config.profile.delegate.SimpleDelegate import de.bixilon.minosoft.config.profile.profiles.Profile import de.bixilon.minosoft.data.text.formatting.color.RGBColor diff --git a/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/EnumDelegate.kt b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/EnumDelegate.kt new file mode 100644 index 000000000..05253d756 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/EnumDelegate.kt @@ -0,0 +1,28 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.config.profile.delegate.types + +import de.bixilon.kutil.enums.ValuesEnum +import de.bixilon.minosoft.config.profile.delegate.SimpleDelegate +import de.bixilon.minosoft.config.profile.profiles.Profile + +open class EnumDelegate>( + override val profile: Profile, + default: T, + values: ValuesEnum, + name: String = "", +) : SimpleDelegate(profile, default, name) { + + override fun validate(value: T) = Unit +} diff --git a/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/LanguageDelegate.kt b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/LanguageDelegate.kt new file mode 100644 index 000000000..0bc72c887 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/LanguageDelegate.kt @@ -0,0 +1,26 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.config.profile.delegate.types + +import de.bixilon.minosoft.config.profile.delegate.SimpleDelegate +import de.bixilon.minosoft.config.profile.profiles.Profile + +open class LanguageDelegate( + override val profile: Profile, + default: String?, + name: String = "", +) : SimpleDelegate(profile, default, name) { + + override fun validate(value: String?) = Unit +} diff --git a/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/NullableStringDelegate.kt b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/NullableStringDelegate.kt new file mode 100644 index 000000000..b20362e9c --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/NullableStringDelegate.kt @@ -0,0 +1,26 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.config.profile.delegate.types + +import de.bixilon.minosoft.config.profile.delegate.SimpleDelegate +import de.bixilon.minosoft.config.profile.profiles.Profile + +open class NullableStringDelegate( + override val profile: Profile, + default: String?, + name: String = "", +) : SimpleDelegate(profile, default, name) { + + override fun validate(value: String?) = Unit +} diff --git a/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/StringDelegate.kt b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/StringDelegate.kt new file mode 100644 index 000000000..d8ec9d526 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/StringDelegate.kt @@ -0,0 +1,26 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.config.profile.delegate.types + +import de.bixilon.minosoft.config.profile.delegate.SimpleDelegate +import de.bixilon.minosoft.config.profile.profiles.Profile + +open class StringDelegate( + override val profile: Profile, + default: String, + name: String = "", +) : SimpleDelegate(profile, default, name) { + + override fun validate(value: String) = Unit +} diff --git a/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/map/LogDelegate.kt b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/map/LogDelegate.kt new file mode 100644 index 000000000..c5bb02b6e --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/map/LogDelegate.kt @@ -0,0 +1,24 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.config.profile.delegate.types.map + +import de.bixilon.minosoft.config.profile.profiles.Profile +import de.bixilon.minosoft.util.logging.LogLevels +import de.bixilon.minosoft.util.logging.LogMessageType + +class LogDelegate( + override val profile: Profile, + default: MutableMap, + name: String = "", +) : MapDelegate(profile, default, name) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/map/MapDelegate.kt b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/map/MapDelegate.kt new file mode 100644 index 000000000..c1ba664bb --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/delegate/types/map/MapDelegate.kt @@ -0,0 +1,36 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.config.profile.delegate.types.map + +import de.bixilon.kutil.observer.map.MapObserver +import de.bixilon.minosoft.config.profile.delegate.AbstractDelegate +import de.bixilon.minosoft.config.profile.profiles.Profile +import de.bixilon.minosoft.util.KUtil.minosoft + +abstract class MapDelegate( + override val profile: Profile, + default: MutableMap, + name: String, +) : MapObserver(default), AbstractDelegate> { + override val name = minosoft(name) + override val description = minosoft("$name.description") + + override fun get() = value + override fun set(value: MutableMap) { + validate(value) + this.value.unsafe = value + } + + override fun validate(value: MutableMap) = Unit +} diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt index 84f6f4d26..362573c37 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt @@ -19,9 +19,11 @@ import com.fasterxml.jackson.annotation.JsonProperty import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.kutil.random.RandomStringUtil.randomString import de.bixilon.minosoft.config.profile.ProfileManager +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.StringDelegate import de.bixilon.minosoft.config.profile.profiles.Profile import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager.backingDelegate -import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager.delegate import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager.mapDelegate import de.bixilon.minosoft.data.accounts.Account @@ -40,20 +42,20 @@ class AccountProfile( override var saved: Boolean = true override var ignoreNextReload: Boolean = false override val version: Int = latestVersion - override var description by delegate(description ?: "") + override var description by StringDelegate(this, description ?: "") /** * The client token. * This 128 length long string is generated randomly while the profile was created * Will be sent to mojang when logging in/refreshing an account */ - var clientToken by delegate(KUtil.RANDOM.randomString(128)) + var clientToken by StringDelegate(this, KUtil.RANDOM.randomString(128)) /** * Before using an account, it always tries to fetch the profile. * If the fetch is successful, we can be sure that the account is working. */ - var alwaysFetchProfile by delegate(true) + var alwaysFetchProfile by BooleanDelegate(this, true) /** * All accounts @@ -66,7 +68,7 @@ class AccountProfile( * The current id of the selected account */ @get:JsonInclude(JsonInclude.Include.NON_NULL) - @get:JsonProperty("selected") private var _selected: String? by delegate(null) + @get:JsonProperty("selected") private var _selected: String? by NullableStringDelegate(this, null) @get:JsonIgnore var selected: Account? by backingDelegate(getter = { entries[_selected] }, setter = { _selected = it?.id }) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/audio/AudioProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/audio/AudioProfile.kt index e7053d272..9617be331 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/audio/AudioProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/audio/AudioProfile.kt @@ -16,8 +16,8 @@ package de.bixilon.minosoft.config.profile.profiles.audio import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.config.profile.ProfileManager import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate import de.bixilon.minosoft.config.profile.profiles.Profile -import de.bixilon.minosoft.config.profile.profiles.audio.AudioProfileManager.delegate import de.bixilon.minosoft.config.profile.profiles.audio.AudioProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.audio.gui.GuiC import de.bixilon.minosoft.config.profile.profiles.audio.types.TypesC @@ -36,7 +36,7 @@ class AudioProfile( override var saved: Boolean = true override var ignoreNextReload: Boolean = false override val version: Int = latestVersion - override var description by delegate(description ?: "") + override var description by StringDelegate(this, description ?: "") /** * Skips the loading od the AudioPlayer diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/block/BlockProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/block/BlockProfile.kt index 570069459..00e24f601 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/block/BlockProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/block/BlockProfile.kt @@ -16,8 +16,8 @@ package de.bixilon.minosoft.config.profile.profiles.block import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.config.profile.ProfileManager import de.bixilon.minosoft.config.profile.delegate.primitive.IntDelegate +import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate import de.bixilon.minosoft.config.profile.profiles.Profile -import de.bixilon.minosoft.config.profile.profiles.block.BlockProfileManager.delegate import de.bixilon.minosoft.config.profile.profiles.block.BlockProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.block.outline.OutlineC import de.bixilon.minosoft.config.profile.profiles.block.rendering.RenderingC @@ -36,7 +36,7 @@ class BlockProfile( override var saved: Boolean = true override var ignoreNextReload: Boolean = false override val version: Int = latestVersion - override var description by delegate(description ?: "") + override var description by StringDelegate(this, description ?: "") /** * The block view distance in chunks. diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/block/outline/OutlineC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/block/outline/OutlineC.kt index 2a9f00c45..a2c94da4e 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/block/outline/OutlineC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/block/outline/OutlineC.kt @@ -13,8 +13,8 @@ package de.bixilon.minosoft.config.profile.profiles.block.outline -import de.bixilon.minosoft.config.profile.delegate.ColorDelegate import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.delegate.types.ColorDelegate import de.bixilon.minosoft.config.profile.profiles.block.BlockProfile import de.bixilon.minosoft.data.text.formatting.color.ChatColors diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/ConnectionProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/ConnectionProfile.kt index db7ccaa09..231d5613f 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/ConnectionProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/ConnectionProfile.kt @@ -15,8 +15,11 @@ package de.bixilon.minosoft.config.profile.profiles.connection import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.config.profile.ProfileManager +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.delegate.types.EnumDelegate +import de.bixilon.minosoft.config.profile.delegate.types.LanguageDelegate +import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate import de.bixilon.minosoft.config.profile.profiles.Profile -import de.bixilon.minosoft.config.profile.profiles.connection.ConnectionProfileManager.delegate import de.bixilon.minosoft.config.profile.profiles.connection.ConnectionProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.connection.signature.SignatureC import de.bixilon.minosoft.config.profile.profiles.connection.skin.SkinC @@ -35,35 +38,35 @@ class ConnectionProfile( override var saved: Boolean = true override var ignoreNextReload: Boolean = false override val version: Int = latestVersion - override var description by delegate(description ?: "") + override var description by StringDelegate(this, description ?: "") /** * Language for language files. * Will be sent to the server * If unset (null), uses eros language */ - var language: String? by delegate(null) + var language: String? by LanguageDelegate(this, null) /** * If false, the server should not list us the ping player list * Will be sent to the server */ - var playerListing by delegate(true) + var playerListing by BooleanDelegate(this, true) /** * Main arm to use */ - var mainArm by delegate(Arms.RIGHT) + var mainArm by EnumDelegate(this, Arms.RIGHT) - val skin = SkinC() - val signature = SignatureC() + val skin = SkinC(this) + val signature = SignatureC(this) - var autoRespawn by delegate(false) + var autoRespawn by BooleanDelegate(this, false) /** * If set, the client will respond with "vanilla" as brand and not "minosoft" */ - var fakeBrand by delegate(false) + var fakeBrand by BooleanDelegate(this, false) override fun toString(): String { return ConnectionProfileManager.getName(this) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/signature/SignatureC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/signature/SignatureC.kt index 91eef2612..cce3c6926 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/signature/SignatureC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/signature/SignatureC.kt @@ -13,27 +13,28 @@ package de.bixilon.minosoft.config.profile.profiles.connection.signature -import de.bixilon.minosoft.config.profile.profiles.connection.ConnectionProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.connection.ConnectionProfile -class SignatureC { +class SignatureC(profile: ConnectionProfile) { /** * Hides all bad signed messages */ - val ignoreBadSignedMessages by delegate(false) + val ignoreBadSignedMessages by BooleanDelegate(profile, false) /** * Does not fetch/load the private key, thus forcing the unsigned mode */ - val disableKeys by delegate(false) + val disableKeys by BooleanDelegate(profile, false) /** * Send commands as message */ - val sendCommandAsMessage by delegate(false) + val sendCommandAsMessage by BooleanDelegate(profile, false) /** * Signs commands */ - val signCommands by delegate(true) + val signCommands by BooleanDelegate(profile, true) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/skin/SkinC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/skin/SkinC.kt index 59e292640..31b5c32e6 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/skin/SkinC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/connection/skin/SkinC.kt @@ -14,51 +14,52 @@ package de.bixilon.minosoft.config.profile.profiles.connection.skin import com.fasterxml.jackson.annotation.JsonIgnore -import de.bixilon.minosoft.config.profile.profiles.connection.ConnectionProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.connection.ConnectionProfile import de.bixilon.minosoft.data.entities.entities.player.SkinParts -class SkinC { +class SkinC(profile: ConnectionProfile) { /** * The cape of use will be hidden * Will be sent to the server */ - var cape by delegate(true) + var cape by BooleanDelegate(profile, true) /** * The jacket of use will be hidden * Will be sent to the server */ - var jacket by delegate(true) + var jacket by BooleanDelegate(profile, true) /** * The left sleeve of use will be hidden * Will be sent to the server */ - var leftSleeve by delegate(true) + var leftSleeve by BooleanDelegate(profile, true) /** * The right sleeve of use will be hidden * Will be sent to the server */ - var rightSleeve by delegate(true) + var rightSleeve by BooleanDelegate(profile, true) /** * The left pants of use will be hidden * Will be sent to the server */ - var leftPants by delegate(true) + var leftPants by BooleanDelegate(profile, true) /** * The right pants of use will be hidden * Will be sent to the server */ - var rightPants by delegate(true) + var rightPants by BooleanDelegate(profile, true) /** * The hat of use will be hidden * Will be sent to the server */ - var hat by delegate(true) + var hat by BooleanDelegate(profile, true) @get:JsonIgnore val skinParts: Array diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/ControlsProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/ControlsProfile.kt index 929b3bf36..0edbce688 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/ControlsProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/ControlsProfile.kt @@ -16,8 +16,8 @@ package de.bixilon.minosoft.config.profile.profiles.controls import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.config.key.KeyBinding import de.bixilon.minosoft.config.profile.ProfileManager +import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate import de.bixilon.minosoft.config.profile.profiles.Profile -import de.bixilon.minosoft.config.profile.profiles.controls.ControlsProfileManager.delegate import de.bixilon.minosoft.config.profile.profiles.controls.ControlsProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.controls.ControlsProfileManager.mapDelegate import de.bixilon.minosoft.config.profile.profiles.controls.interaction.InteractionC @@ -37,13 +37,13 @@ class ControlsProfile( override var saved: Boolean = true override var ignoreNextReload: Boolean = false override val version: Int = latestVersion - override var description by delegate(description ?: "") + override var description by StringDelegate(this, description ?: "") var keyBindings: MutableMap by mapDelegate() private set - val mouse = MouseC() - val interaction = InteractionC() + val mouse = MouseC(this) + val interaction = InteractionC(this) override fun toString(): String { diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/interaction/InteractionC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/interaction/InteractionC.kt index 676b37c3e..3343ddc87 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/interaction/InteractionC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/interaction/InteractionC.kt @@ -13,22 +13,23 @@ package de.bixilon.minosoft.config.profile.profiles.controls.interaction -import de.bixilon.minosoft.config.profile.profiles.controls.ControlsProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.controls.ControlsProfile -class InteractionC { +class InteractionC(profile: ControlsProfile) { /** * Enables or disables right-clicking with a shovel on grass (…) to create grass paths */ - var flattening by delegate(true) + var flattening by BooleanDelegate(profile, true) /** * Enables right-clicking with an axe on any logs to create stripped logs */ - var stripping by delegate(true) + var stripping by BooleanDelegate(profile, true) /** * Enables right-clicking with a hoe on grass (…) to create farmland */ - var tilling by delegate(true) + var tilling by BooleanDelegate(profile, true) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/mouse/MouseC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/mouse/MouseC.kt index b8eac540d..71d5d3d93 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/mouse/MouseC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/controls/mouse/MouseC.kt @@ -13,20 +13,21 @@ package de.bixilon.minosoft.config.profile.profiles.controls.mouse -import de.bixilon.minosoft.config.profile.profiles.controls.ControlsProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.FloatDelegate +import de.bixilon.minosoft.config.profile.profiles.controls.ControlsProfile -class MouseC { +class MouseC(profile: ControlsProfile) { /** * Mouse sensitivity in percent * Controls how fast the mouse rotates the player around * Must be non-negative */ - var sensitivity by delegate(1.0f) { check(it > 0.0f) { "Must be non-negative!" } } + var sensitivity by FloatDelegate(profile, 1.0f, "", arrayOf(0.01f..10.0f)) /** * Controls how fast you scroll (e.g. in the hotbar) * Must be non-negative */ - var scrollSensitivity by delegate(1.0) { check(it > 0.0) { "Must be non-negative!" } } + var scrollSensitivity by FloatDelegate(profile, 1.0f, "", arrayOf(0.01f..10.0f)) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/EntityProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/EntityProfile.kt index d14bcfe0b..957f91da0 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/EntityProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/EntityProfile.kt @@ -15,8 +15,8 @@ package de.bixilon.minosoft.config.profile.profiles.entity import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.config.profile.ProfileManager +import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate import de.bixilon.minosoft.config.profile.profiles.Profile -import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager.delegate import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.entity.hitbox.HitboxC @@ -33,10 +33,10 @@ class EntityProfile( override var saved: Boolean = true override var ignoreNextReload: Boolean = false override val version: Int = latestVersion - override var description by delegate(description ?: "") + override var description by StringDelegate(this, description ?: "") - val hitbox = HitboxC() + val hitbox = HitboxC(this) override fun toString(): String { return EntityProfileManager.getName(this) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/hitbox/HitboxC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/hitbox/HitboxC.kt index 89ba196e4..08d7ac4ad 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/hitbox/HitboxC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/hitbox/HitboxC.kt @@ -13,33 +13,34 @@ package de.bixilon.minosoft.config.profile.profiles.entity.hitbox -import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfile -class HitboxC { +class HitboxC(profile: EntityProfile) { /** * Enables or disables hit-boxes for all entities */ - var enabled by delegate(true) + var enabled by BooleanDelegate(profile, true) /** * Shows your own hit-box when in first person view */ - var showLocal by delegate(false) + var showLocal by BooleanDelegate(profile, false) /** * Shows hit-boxes from invisible entities */ - var showInvisible by delegate(false) + var showInvisible by BooleanDelegate(profile, false) /** * If true: Shows full colored hit-boxes (aka. lazy boxes). * If false: Shows just the outline of the hit-box */ - var lazy by delegate(false) + var lazy by BooleanDelegate(profile, false) /** * Disables the z-buffer when rendering * => Shows the boxes through walls */ - var showThroughWalls by delegate(false) + var showThroughWalls by BooleanDelegate(profile, false) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/ErosProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/ErosProfile.kt index 6b2ee97fc..b682dc724 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/ErosProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/ErosProfile.kt @@ -15,8 +15,8 @@ package de.bixilon.minosoft.config.profile.profiles.eros import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.config.profile.ProfileManager +import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate import de.bixilon.minosoft.config.profile.profiles.Profile -import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.delegate import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.eros.general.GeneralC import de.bixilon.minosoft.config.profile.profiles.eros.server.ServerC @@ -36,13 +36,13 @@ class ErosProfile( override var saved: Boolean = true override var ignoreNextReload: Boolean = false override val version: Int = latestVersion - override var description by delegate(description ?: "") + override var description by StringDelegate(this, description ?: "") - val general = GeneralC() - val theme = ThemeC() - val server = ServerC() - val text = TextC() + val general = GeneralC(this) + val theme = ThemeC(this) + val server = ServerC(this) + val text = TextC(this) override fun toString(): String { return ErosProfileManager.getName(this) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/general/GeneralC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/general/GeneralC.kt index 467151a99..592732a47 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/general/GeneralC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/general/GeneralC.kt @@ -16,21 +16,24 @@ package de.bixilon.minosoft.config.profile.profiles.eros.general import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty import de.bixilon.kutil.locale.LanguageUtil.fullName +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.StringDelegate import de.bixilon.minosoft.config.profile.profiles.account.AccountProfile import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager -import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.delegate +import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.mapDelegate import de.bixilon.minosoft.data.language.LanguageUtil import de.bixilon.minosoft.data.registries.ResourceLocation import java.util.* -class GeneralC { +class GeneralC(profile: ErosProfile) { /** * Language to use for eros. This is also the fallback language for other profiles */ - var language: String by delegate(Locale.getDefault()?.fullName ?: LanguageUtil.FALLBACK_LANGUAGE) + var language: String by StringDelegate(profile, Locale.getDefault()?.fullName ?: LanguageUtil.FALLBACK_LANGUAGE) - @get:JsonProperty("account_profile") private var _accountProfile: String? by delegate(null) + @get:JsonProperty("account_profile") private var _accountProfile: String? by NullableStringDelegate(profile, null) @get:JsonIgnore var accountProfile: AccountProfile get() = AccountProfileManager.profiles[_accountProfile] ?: AccountProfileManager.selected @@ -48,11 +51,11 @@ class GeneralC { /** * Renders the skin overlay (hat) above the head (used for avatars) */ - var renderSkinOverlay by delegate(true) + var renderSkinOverlay by BooleanDelegate(profile, true) /** * Hides eros (all eros windows) once a connection with a server is successfully established. * Will also show it again, once it got disconnected */ - var hideErosOnceConnected by delegate(false) + var hideErosOnceConnected by BooleanDelegate(profile, false) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/ServerC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/ServerC.kt index b54feb644..5150707d8 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/ServerC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/ServerC.kt @@ -14,14 +14,15 @@ package de.bixilon.minosoft.config.profile.profiles.eros.server import com.fasterxml.jackson.annotation.JsonInclude +import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.listDelegate import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.Server import de.bixilon.minosoft.config.profile.profiles.eros.server.list.ListC import de.bixilon.minosoft.config.profile.profiles.eros.server.modify.ModifyC -class ServerC { - val modify = ModifyC() - val list = ListC() +class ServerC(profile: ErosProfile) { + val modify = ModifyC(profile) + val list = ListC(profile) @get:JsonInclude(JsonInclude.Include.NON_EMPTY) var entries: MutableList by listDelegate() diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/list/ListC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/list/ListC.kt index 026854fb2..680c27338 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/list/ListC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/list/ListC.kt @@ -13,21 +13,26 @@ package de.bixilon.minosoft.config.profile.profiles.eros.server.list -import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile -class ListC { +class ListC(profile: ErosProfile) { /** * Hides all servers in the server list that can not be pinged */ - var hideOffline by delegate(false) + var hideOffline by BooleanDelegate(profile, false) /** * Hides all servers in the server list, when the amount of online players exceeds the slots */ - var hideFull by delegate(false) + + /** + * Hides all servers in the server list, when the amount of online players exceeds the slots + */ + var hideFull by BooleanDelegate(profile, false) /** * Hides all servers in the server list when <= 0 players are online */ - var hideEmpty by delegate(false) + var hideEmpty by BooleanDelegate(profile, false) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/modify/ModifyC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/modify/ModifyC.kt index bbb459795..abf7572bf 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/modify/ModifyC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/modify/ModifyC.kt @@ -13,19 +13,20 @@ package de.bixilon.minosoft.config.profile.profiles.eros.server.modify -import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile /** * Configuration for the add or edit server dialog */ -class ModifyC { +class ModifyC(profile: ErosProfile) { /** * Shows releases in the version select dropdown */ - var showReleases by delegate(true) + var showReleases by BooleanDelegate(profile, true) /** * Shows snapshots in the version select dropdown */ - var showSnapshots by delegate(false) + var showSnapshots by BooleanDelegate(profile, false) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/text/TextC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/text/TextC.kt index 39569bc90..5dca56ec6 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/text/TextC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/text/TextC.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2021 Moritz Zwerger + * Copyright (C) 2020-2022 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. * @@ -13,19 +13,20 @@ package de.bixilon.minosoft.config.profile.profiles.eros.text -import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile -class TextC { +class TextC(profile: ErosProfile) { /** * Displays colored text * If disables it displays the css defined language (defaults to white) */ - var colored by delegate(true) + var colored by BooleanDelegate(profile, true) /** * Enables the obfuscated formatting style * If false, the text will just blink */ - var obfuscated by delegate(true) + var obfuscated by BooleanDelegate(profile, true) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/theme/ThemeC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/theme/ThemeC.kt index 168f2701b..45bbfd116 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/theme/ThemeC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/theme/ThemeC.kt @@ -13,13 +13,14 @@ package de.bixilon.minosoft.config.profile.profiles.eros.theme -import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate +import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile -class ThemeC { +class ThemeC(profile: ErosProfile) { /** * Name of the theme css file * Located in minosoft:eros/themes/.css */ - var theme by delegate("default") + var theme by StringDelegate(profile, "default") } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/GUIProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/GUIProfile.kt index ffbf17a01..6f981439d 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/GUIProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/GUIProfile.kt @@ -15,8 +15,9 @@ package de.bixilon.minosoft.config.profile.profiles.gui import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.config.profile.ProfileManager +import de.bixilon.minosoft.config.profile.delegate.primitive.FloatDelegate +import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate import de.bixilon.minosoft.config.profile.profiles.Profile -import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfileManager.delegate import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.gui.chat.ChatC import de.bixilon.minosoft.config.profile.profiles.gui.confirmation.ConfirmationC @@ -36,18 +37,18 @@ class GUIProfile( override var saved: Boolean = true override var ignoreNextReload: Boolean = false override val version: Int = latestVersion - override var description by delegate(description ?: "") + override var description by StringDelegate(this, description ?: "") /** * The scale of the hud * Must be non-negative */ - var scale by delegate(2.0f) { check(it >= 0.0f) { "GUI scale must be non-negative" } } + var scale by FloatDelegate(this, 2.0f, "", arrayOf(1.0f..10.0f)) - val chat = ChatC() - val hud = HudC() - val confirmation = ConfirmationC() - val sign = SignC() + val chat = ChatC(this) + val hud = HudC(this) + val confirmation = ConfirmationC(this) + val sign = SignC(this) override fun toString(): String { return GUIProfileManager.getName(this) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/chat/ChatC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/chat/ChatC.kt index 021eaf041..d62bfe4e2 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/chat/ChatC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/chat/ChatC.kt @@ -13,44 +13,47 @@ package de.bixilon.minosoft.config.profile.profiles.gui.chat -import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.delegate.primitive.IntDelegate +import de.bixilon.minosoft.config.profile.delegate.types.EnumDelegate +import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile import de.bixilon.minosoft.config.profile.profiles.gui.chat.internal.InternalC import de.bixilon.minosoft.protocol.packets.c2s.play.SettingsC2SP -class ChatC { - val internal = InternalC() +class ChatC(profile: GUIProfile) { + val internal = InternalC(profile) /** * Hides the chat */ - var hidden by delegate(false) + var hidden by BooleanDelegate(profile, false) /** * The width of the chat in scaled pixels */ - var width by delegate(320) + var width by IntDelegate(profile, 320, "", arrayOf(100..500)) /** * The height of the chat in scaled pixels */ - var height by delegate(180) + var height by IntDelegate(profile, 180, "", arrayOf(40..500)) /** * ToDo: Unknown purpose * Will be sent to the server */ - var textFiltering by delegate(false) // ToDo: Implement in the client + var textFiltering by BooleanDelegate(profile, false) // ToDo: Implement in the client /** * If false, the chat will appear in white * Will be sent to the server */ - var chatColors by delegate(true) // ToDo: Implement in the client + var chatColors by BooleanDelegate(profile, true) // ToDo: Implement in the client /** * Chat mode * Will be sent to the server */ - var chatMode by delegate(SettingsC2SP.ChatModes.EVERYTHING) + var chatMode by EnumDelegate(profile, SettingsC2SP.ChatModes.EVERYTHING, SettingsC2SP.ChatModes) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/chat/internal/InternalC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/chat/internal/InternalC.kt index 17705c305..b576716cc 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/chat/internal/InternalC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/chat/internal/InternalC.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2021 Moritz Zwerger + * Copyright (C) 2020-2022 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. * @@ -13,22 +13,24 @@ package de.bixilon.minosoft.config.profile.profiles.gui.chat.internal -import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.delegate.primitive.IntDelegate +import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile -class InternalC { +class InternalC(profile: GUIProfile) { /** * Hides the internal chat */ - var hidden by delegate(false) + var hidden by BooleanDelegate(profile, false) /** * The width of the internal chat in scaled pixels */ - var width by delegate(320) + var width by IntDelegate(profile, 320, "", arrayOf(100..500)) /** * The height of the internal chat in scaled pixels */ - var height by delegate(180) + var height by IntDelegate(profile, 180, "", arrayOf(40..500)) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/confirmation/ConfirmationC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/confirmation/ConfirmationC.kt index 509c5b330..ad4c1b2d8 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/confirmation/ConfirmationC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/confirmation/ConfirmationC.kt @@ -13,11 +13,12 @@ package de.bixilon.minosoft.config.profile.profiles.gui.confirmation -import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile -class ConfirmationC { - var copyToClipboard by delegate(true) - var openFile by delegate(true) - var openURL by delegate(true) - var sendMessage by delegate(true) +class ConfirmationC(profile: GUIProfile) { + var copyToClipboard by BooleanDelegate(profile, true) + var openFile by BooleanDelegate(profile, true) + var openURL by BooleanDelegate(profile, true) + var sendMessage by BooleanDelegate(profile, true) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/HudC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/HudC.kt index d7d10a5de..41f191677 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/HudC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/HudC.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2022 Moritz Zwerger + * Copyright (C) 2020-2022 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. * @@ -13,10 +13,11 @@ package de.bixilon.minosoft.config.profile.profiles.gui.hud +import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile import de.bixilon.minosoft.config.profile.profiles.gui.hud.crosshair.CrosshairC import de.bixilon.minosoft.config.profile.profiles.gui.hud.hotbar.HotbarC -class HudC { - val crosshair = CrosshairC() - val hotbar = HotbarC() +class HudC(profile: GUIProfile) { + val crosshair = CrosshairC(profile) + val hotbar = HotbarC(profile) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/crosshair/CrosshairC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/crosshair/CrosshairC.kt index 6daf0786f..6fb06007d 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/crosshair/CrosshairC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/crosshair/CrosshairC.kt @@ -13,17 +13,19 @@ package de.bixilon.minosoft.config.profile.profiles.gui.hud.crosshair -import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.delegate.types.ColorDelegate +import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile import de.bixilon.minosoft.data.text.formatting.color.ChatColors -class CrosshairC { +class CrosshairC(profile: GUIProfile) { /** * Inverts the color of the crosshair according to the background color */ - var complementaryColor by delegate(true) + var complementaryColor by BooleanDelegate(profile, true) /** * The color of the crosshair */ - var color by delegate(ChatColors.WHITE) + var color by ColorDelegate(profile, ChatColors.WHITE, "") } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/hotbar/HotbarC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/hotbar/HotbarC.kt index 05d344c7d..99ebeb6e3 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/hotbar/HotbarC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/hotbar/HotbarC.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2022 Moritz Zwerger + * Copyright (C) 2020-2022 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. * @@ -13,8 +13,9 @@ package de.bixilon.minosoft.config.profile.profiles.gui.hud.hotbar +import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile import de.bixilon.minosoft.config.profile.profiles.gui.hud.hotbar.hunger.HungerC -class HotbarC { - val hunger = HungerC() +class HotbarC(profile: GUIProfile) { + val hunger = HungerC(profile) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/hotbar/hunger/HungerC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/hotbar/hunger/HungerC.kt index 46218c7f4..338f3735e 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/hotbar/hunger/HungerC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/hotbar/hunger/HungerC.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2022 Moritz Zwerger + * Copyright (C) 2020-2022 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. * @@ -13,13 +13,14 @@ package de.bixilon.minosoft.config.profile.profiles.gui.hud.hotbar.hunger -import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile -class HungerC { +class HungerC(profile: GUIProfile) { /** * Minecraft does not show the saturation by default. * Enabling this option will show how much saturation you have * Enabled by default, might break texture packs */ - val saturationBar by delegate(true) + val saturationBar by BooleanDelegate(profile, true) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/sign/SignC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/sign/SignC.kt index 1a67354c8..b637ae9b5 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/sign/SignC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/sign/SignC.kt @@ -13,8 +13,9 @@ package de.bixilon.minosoft.config.profile.profiles.gui.sign -import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile -class SignC { - var limitLength by delegate(true) +class SignC(profile: GUIProfile) { + var limitLength by BooleanDelegate(profile, true) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/other/OtherProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/other/OtherProfile.kt index 7cee2fee1..6d84d64ca 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/other/OtherProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/other/OtherProfile.kt @@ -15,8 +15,9 @@ package de.bixilon.minosoft.config.profile.profiles.other import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.config.profile.ProfileManager +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate import de.bixilon.minosoft.config.profile.profiles.Profile -import de.bixilon.minosoft.config.profile.profiles.other.OtherProfileManager.delegate import de.bixilon.minosoft.config.profile.profiles.other.OtherProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.other.log.LogC @@ -33,19 +34,19 @@ class OtherProfile( override var saved: Boolean = true override var ignoreNextReload: Boolean = false override val version: Int = latestVersion - override var description by delegate(description ?: "") + override var description by StringDelegate(this, description ?: "") /** * Use native network transport if available */ - var nativeNetwork by delegate(true) + var nativeNetwork by BooleanDelegate(this, true) /** * Listens for servers on your LAN network */ - var listenLAN by delegate(true) + var listenLAN by BooleanDelegate(this, true) - val log = LogC() + val log = LogC(this) override fun toString(): String { return OtherProfileManager.getName(this) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/other/log/LogC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/other/log/LogC.kt index d2ca98220..1f588771d 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/other/log/LogC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/other/log/LogC.kt @@ -13,23 +13,24 @@ package de.bixilon.minosoft.config.profile.profiles.other.log -import de.bixilon.minosoft.config.profile.profiles.other.OtherProfileManager.delegate -import de.bixilon.minosoft.config.profile.profiles.other.OtherProfileManager.mapDelegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.delegate.types.map.LogDelegate +import de.bixilon.minosoft.config.profile.profiles.other.OtherProfile import de.bixilon.minosoft.util.logging.LogMessageType -class LogC { +class LogC(profile: OtherProfile) { /** * Hides various messages (e.g. chunk receiving, entity position updates, ...) * Only relevant if packet logging is on VERBOSE */ - var reducedProtocolLog by delegate(true) + var reducedProtocolLog by BooleanDelegate(profile, true) /** * All log message types mapped to its log level * @see de.bixilon.minosoft.util.logging.LogLevels * @see de.bixilon.minosoft.util.logging.LogMessageType */ - var levels by mapDelegate(LogMessageType.DEFAULT_LOG_MAP.toMutableMap()) + var levels by LogDelegate(profile, LogMessageType.DEFAULT_LOG_MAP.toMutableMap()) private set } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/particle/ParticleProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/particle/ParticleProfile.kt index 3deccba82..fd42c6e55 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/particle/ParticleProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/particle/ParticleProfile.kt @@ -15,8 +15,10 @@ package de.bixilon.minosoft.config.profile.profiles.particle import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.config.profile.ProfileManager +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.delegate.primitive.IntDelegate +import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate import de.bixilon.minosoft.config.profile.profiles.Profile -import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager.delegate import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.particle.types.TypesC import de.bixilon.minosoft.gui.rendering.RenderConstants @@ -34,18 +36,18 @@ class ParticleProfile( override var saved: Boolean = true override var ignoreNextReload: Boolean = false override val version: Int = latestVersion - override var description by delegate(description ?: "") + override var description by StringDelegate(this, description ?: "") /** * Skips the loading of the particle render. Requires to reload the renderer! */ - var skipLoading by delegate(false) + var skipLoading by BooleanDelegate(this, false) /** * Enabled or disables particle renderer * Does not skip loading of particles */ - var enabled by delegate(true) + var enabled by BooleanDelegate(this, true) /** * View distance for particles @@ -53,7 +55,7 @@ class ParticleProfile( * * @see de.bixilon.minosoft.config.profile.profiles.block.BlockProfile.viewDistance */ - var viewDistance by delegate(10) { check(it in 0..128) { "Distance must be non-negative and must not exceed 128" } } + var viewDistance by IntDelegate(this, 10, "", arrayOf(0..128)) /** * Limits the number of particles. @@ -61,9 +63,8 @@ class ParticleProfile( * Must not be negative or exceed $RenderConstants.MAXIMUM_PARTICLE_AMOUNT * @see RenderConstants.MAXIMUM_PARTICLE_AMOUNT */ - var maxAmount by delegate(RenderConstants.MAXIMUM_PARTICLE_AMOUNT) { check(it in 0..RenderConstants.MAXIMUM_PARTICLE_AMOUNT) { "Particle amount must be non-negative and may not exceed ${RenderConstants.MAXIMUM_PARTICLE_AMOUNT}" } } - - val types = TypesC() + var maxAmount by IntDelegate(this, RenderConstants.MAXIMUM_PARTICLE_AMOUNT, "", arrayOf(0..RenderConstants.MAXIMUM_PARTICLE_AMOUNT)) + val types = TypesC(this) override fun toString(): String { return ParticleProfileManager.getName(this) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/particle/types/TypesC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/particle/types/TypesC.kt index c6f7bc07b..e9bfc0eaa 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/particle/types/TypesC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/particle/types/TypesC.kt @@ -13,16 +13,17 @@ package de.bixilon.minosoft.config.profile.profiles.particle.types -import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager.delegate +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfile -class TypesC { +class TypesC(profile: ParticleProfile) { /** * Shows particles from explosions */ - var explosions by delegate(true) + var explosions by BooleanDelegate(profile, true) /** * Shows custom particles */ - var packet by delegate(true) + var packet by BooleanDelegate(profile, true) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/RenderingProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/RenderingProfile.kt index 034c44249..d646f0a1d 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/RenderingProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/RenderingProfile.kt @@ -15,8 +15,8 @@ package de.bixilon.minosoft.config.profile.profiles.rendering import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.config.profile.ProfileManager +import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate import de.bixilon.minosoft.config.profile.profiles.Profile -import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfileManager.delegate import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.rendering.advanced.AdvancedC import de.bixilon.minosoft.config.profile.profiles.rendering.animations.AnimationsC @@ -43,7 +43,7 @@ class RenderingProfile( override var saved: Boolean = true override var ignoreNextReload: Boolean = false override val version: Int = latestVersion - override var description by delegate(description ?: "") + override var description by StringDelegate(this, description ?: "") val advanced = AdvancedC(this) val animations = AnimationsC(this)