diff options
author | Charles Lombardo <clombardo169@gmail.com> | 2023-04-18 09:43:33 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2023-06-03 09:05:52 +0200 |
commit | c609847e4956eaafbf2990f0442e78a0a664fac6 (patch) | |
tree | 2ddb106899a57725a482ce0af282ee3fc391f24f /src/android | |
parent | android: Implement gamepad input (diff) | |
download | yuzu-c609847e4956eaafbf2990f0442e78a0a664fac6.tar yuzu-c609847e4956eaafbf2990f0442e78a0a664fac6.tar.gz yuzu-c609847e4956eaafbf2990f0442e78a0a664fac6.tar.bz2 yuzu-c609847e4956eaafbf2990f0442e78a0a664fac6.tar.lz yuzu-c609847e4956eaafbf2990f0442e78a0a664fac6.tar.xz yuzu-c609847e4956eaafbf2990f0442e78a0a664fac6.tar.zst yuzu-c609847e4956eaafbf2990f0442e78a0a664fac6.zip |
Diffstat (limited to '')
24 files changed, 418 insertions, 363 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractBooleanSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractBooleanSetting.kt new file mode 100644 index 000000000..a6e9833ee --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractBooleanSetting.kt @@ -0,0 +1,8 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.yuzu.yuzu_emu.features.settings.model + +interface AbstractBooleanSetting : AbstractSetting { + var boolean: Boolean +} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractFloatSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractFloatSetting.kt new file mode 100644 index 000000000..6fe4bc263 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractFloatSetting.kt @@ -0,0 +1,8 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.yuzu.yuzu_emu.features.settings.model + +interface AbstractFloatSetting : AbstractSetting { + var float: Float +} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractIntSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractIntSetting.kt new file mode 100644 index 000000000..892b7dcfe --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractIntSetting.kt @@ -0,0 +1,8 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.yuzu.yuzu_emu.features.settings.model + +interface AbstractIntSetting : AbstractSetting { + var int: Int +} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractSetting.kt new file mode 100644 index 000000000..0ebf55ab7 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractSetting.kt @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.yuzu.yuzu_emu.features.settings.model + +interface AbstractSetting { + val key: String? + val section: String? + val isRuntimeEditable: Boolean + val valueAsString: String +} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractStringSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractStringSetting.kt new file mode 100644 index 000000000..0d02c5997 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/AbstractStringSetting.kt @@ -0,0 +1,8 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.yuzu.yuzu_emu.features.settings.model + +interface AbstractStringSetting : AbstractSetting { + var string: String +} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/BooleanSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/BooleanSetting.kt index f0f270c76..837e5b89d 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/BooleanSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/BooleanSetting.kt @@ -3,10 +3,33 @@ package org.yuzu.yuzu_emu.features.settings.model -class BooleanSetting( - key: String, - section: String, - var value: Boolean -) : Setting(key, section) { - override val valueAsString get() = if (value) "True" else "False" +enum class BooleanSetting( + override val key: String, + override val section: String, + val defaultValue: Boolean +) : AbstractBooleanSetting { + // No boolean settings currently exist + EMPTY_SETTING("", "", false); + + override var boolean: Boolean = defaultValue + + override val valueAsString: String + get() = boolean.toString() + + override val isRuntimeEditable: Boolean + get() { + for (setting in NOT_RUNTIME_EDITABLE) { + if (setting == this) { + return false + } + } + return true + } + + companion object { + private val NOT_RUNTIME_EDITABLE = emptyList<BooleanSetting>() + + fun from(key: String): BooleanSetting? = + BooleanSetting.values().firstOrNull { it.key == key } + } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/FloatSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/FloatSetting.kt index f78242a47..4c83e9527 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/FloatSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/FloatSetting.kt @@ -3,10 +3,32 @@ package org.yuzu.yuzu_emu.features.settings.model -class FloatSetting( - key: String, - section: String, - var value: Float -) : Setting(key, section) { - override val valueAsString get() = value.toString() +enum class FloatSetting( + override val key: String, + override val section: String, + val defaultValue: Float +) : AbstractFloatSetting { + // No float settings currently exist + EMPTY_SETTING("", "", 0f); + + override var float: Float = defaultValue + + override val valueAsString: String + get() = float.toString() + + override val isRuntimeEditable: Boolean + get() { + for (setting in NOT_RUNTIME_EDITABLE) { + if (setting == this) { + return false + } + } + return true + } + + companion object { + private val NOT_RUNTIME_EDITABLE = emptyList<FloatSetting>() + + fun from(key: String): FloatSetting? = FloatSetting.values().firstOrNull { it.key == key } + } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt index 32d9b8b85..164888016 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt @@ -3,10 +3,121 @@ package org.yuzu.yuzu_emu.features.settings.model -class IntSetting( - key: String, - section: String, - var value: Int -) : Setting(key, section) { - override val valueAsString get() = value.toString() +enum class IntSetting( + override val key: String, + override val section: String, + val defaultValue: Int +) : AbstractIntSetting { + RENDERER_USE_SPEED_LIMIT( + "use_speed_limit", + Settings.SECTION_RENDERER, + 1 + ), + USE_DOCKED_MODE( + "use_docked_mode", + Settings.SECTION_SYSTEM, + 0 + ), + RENDERER_USE_DISK_SHADER_CACHE( + "use_disk_shader_cache", + Settings.SECTION_RENDERER, + 1 + ), + RENDERER_FORCE_MAX_CLOCK( + "force_max_clock", + Settings.SECTION_RENDERER, + 1 + ), + RENDERER_ASYNCHRONOUS_SHADERS( + "use_asynchronous_shaders", + Settings.SECTION_RENDERER, + 0 + ), + RENDERER_DEBUG( + "debug", + Settings.SECTION_RENDERER, + 0 + ), + RENDERER_SPEED_LIMIT( + "speed_limit", + Settings.SECTION_RENDERER, + 100 + ), + CPU_ACCURACY( + "cpu_accuracy", + Settings.SECTION_CPU, + 0 + ), + REGION_INDEX( + "region_index", + Settings.SECTION_SYSTEM, + -1 + ), + LANGUAGE_INDEX( + "language_index", + Settings.SECTION_SYSTEM, + 1 + ), + RENDERER_BACKEND( + "backend", + Settings.SECTION_RENDERER, + 1 + ), + RENDERER_ACCURACY( + "gpu_accuracy", + Settings.SECTION_RENDERER, + 0 + ), + RENDERER_RESOLUTION( + "resolution_setup", + Settings.SECTION_RENDERER, + 2 + ), + RENDERER_SCALING_FILTER( + "scaling_filter", + Settings.SECTION_RENDERER, + 1 + ), + RENDERER_ANTI_ALIASING( + "anti_aliasing", + Settings.SECTION_RENDERER, + 0 + ), + RENDERER_ASPECT_RATIO( + "aspect_ratio", + Settings.SECTION_RENDERER, + 0 + ), + AUDIO_VOLUME( + "volume", + Settings.SECTION_AUDIO, + 100 + ); + + override var int: Int = defaultValue + + override val valueAsString: String + get() = int.toString() + + override val isRuntimeEditable: Boolean + get() { + for (setting in NOT_RUNTIME_EDITABLE) { + if (setting == this) { + return false + } + } + return true + } + + companion object { + private val NOT_RUNTIME_EDITABLE = listOf( + RENDERER_USE_DISK_SHADER_CACHE, + RENDERER_ASYNCHRONOUS_SHADERS, + RENDERER_DEBUG, + RENDERER_BACKEND, + RENDERER_RESOLUTION + ) + + fun from(key: String): IntSetting? = IntSetting.values().firstOrNull { it.key == key } + } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Setting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Setting.kt deleted file mode 100644 index befd40257..000000000 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Setting.kt +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-FileCopyrightText: 2023 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.yuzu.yuzu_emu.features.settings.model - -/** - * Abstraction for a setting item as read from / written to yuzu's configuration ini files. - * These files generally consist of a key/value pair, though the type of value is ambiguous and - * must be inferred at read-time. The type of value determines which child of this class is used - * to represent the Setting. - */ -abstract class Setting( - /** - * @return The identifier used to write this setting to the ini file. - */ - val key: String, - /** - * @return The name of the header under which this Setting should be written in the ini file. - */ - val section: String -) { - - /** - * @return A representation of this Setting's backing value converted to a String (e.g. for serialization). - */ - abstract val valueAsString: String -} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/SettingSection.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/SettingSection.kt index 94f85a12a..474f598a9 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/SettingSection.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/SettingSection.kt @@ -8,15 +8,15 @@ package org.yuzu.yuzu_emu.features.settings.model * internally stored as a HashMap. */ class SettingSection(val name: String) { - val settings = HashMap<String, Setting>() + val settings = HashMap<String, AbstractSetting>() /** * Convenience method; inserts a value directly into the backing HashMap. * * @param setting The Setting to be inserted. */ - fun putSetting(setting: Setting) { - settings[setting.key] = setting + fun putSetting(setting: AbstractSetting) { + settings[setting.key!!] = setting } /** @@ -25,7 +25,7 @@ class SettingSection(val name: String) { * @param key Used to retrieve the Setting. * @return A Setting object (you should probably cast this before using) */ - fun getSetting(key: String): Setting? { + fun getSetting(key: String): AbstractSetting? { return settings[key] } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/StringSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/StringSetting.kt index c78be39d7..3fe43de26 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/StringSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/StringSetting.kt @@ -3,10 +3,32 @@ package org.yuzu.yuzu_emu.features.settings.model -class StringSetting( - key: String, - section: String, - var value: String -) : Setting(key, section) { - override val valueAsString get() = value +enum class StringSetting( + override val key: String, + override val section: String, + defaultValue: String +) : AbstractStringSetting { + // No string settings currently exist + EMPTY_SETTING("", "", ""); + + override var string: String = defaultValue + + override val valueAsString: String + get() = string + + override val isRuntimeEditable: Boolean + get() { + for (setting in NOT_RUNTIME_EDITABLE) { + if (setting == this) { + return false + } + } + return true + } + + companion object { + private val NOT_RUNTIME_EDITABLE = emptyList<StringSetting>() + + fun from(key: String): StringSetting? = StringSetting.values().firstOrNull { it.key == key } + } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/DateTimeSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/DateTimeSetting.kt index 041d59f19..cf60798ff 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/DateTimeSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/DateTimeSetting.kt @@ -3,36 +3,30 @@ package org.yuzu.yuzu_emu.features.settings.model.view -import org.yuzu.yuzu_emu.features.settings.model.Setting +import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting +import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting import org.yuzu.yuzu_emu.features.settings.model.StringSetting class DateTimeSetting( - key: String, - section: String, + val key: String? = null, + setting: AbstractSetting?, titleId: Int, descriptionId: Int, - private val defaultValue: String, - setting: Setting -) : SettingsItem(key, section, setting, titleId, descriptionId) { + private val defaultValue: String? = null +) : SettingsItem(setting, titleId, descriptionId) { override val type = TYPE_DATETIME_SETTING val value: String get() = if (setting != null) { val setting = setting as StringSetting - setting.value + setting.string } else { - defaultValue + defaultValue!! } - fun setSelectedValue(datetime: String): StringSetting? { - return if (setting == null) { - val newSetting = StringSetting(key!!, section!!, datetime) - setting = newSetting - newSetting - } else { - val newSetting = setting as StringSetting - newSetting.value = datetime - null - } + fun setSelectedValue(datetime: String): AbstractStringSetting { + val stringSetting = setting as AbstractStringSetting + stringSetting.string = datetime + return stringSetting } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/HeaderSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/HeaderSetting.kt index 0d98a9eac..abba64e93 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/HeaderSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/HeaderSetting.kt @@ -3,13 +3,12 @@ package org.yuzu.yuzu_emu.features.settings.model.view -import org.yuzu.yuzu_emu.features.settings.model.Setting +import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting class HeaderSetting( - key: String?, - setting: Setting?, + setting: AbstractSetting?, titleId: Int, descriptionId: Int? -) : SettingsItem(key, null, setting, titleId, descriptionId) { +) : SettingsItem(setting, titleId, descriptionId) { override val type = TYPE_HEADER } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt index c7ad60046..599da1380 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt @@ -3,19 +3,17 @@ package org.yuzu.yuzu_emu.features.settings.model.view -import org.yuzu.yuzu_emu.features.settings.model.Setting +import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting /** * ViewModel abstraction for an Item in the RecyclerView powering SettingsFragments. - * Each one corresponds to a [Setting] object, so this class's subclasses + * Each one corresponds to a [AbstractSetting] object, so this class's subclasses * should vaguely correspond to those subclasses. There are a few with multiple analogues * and a few with none (Headers, for example, do not correspond to anything in the ini * file.) */ abstract class SettingsItem( - val key: String?, - val section: String?, - var setting: Setting?, + var setting: AbstractSetting?, val nameId: Int, val descriptionId: Int? ) { diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.kt index d094f891e..ed1742ac6 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.kt @@ -3,27 +3,26 @@ package org.yuzu.yuzu_emu.features.settings.model.view +import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting import org.yuzu.yuzu_emu.features.settings.model.IntSetting -import org.yuzu.yuzu_emu.features.settings.model.Setting class SingleChoiceSetting( - key: String, - section: String, - setting: Setting?, + setting: AbstractIntSetting?, titleId: Int, descriptionId: Int, val choicesId: Int, val valuesId: Int, - private val defaultValue: Int, -) : SettingsItem(key, section, setting, titleId, descriptionId) { + val key: String? = null, + val defaultValue: Int? = null +) : SettingsItem(setting, titleId, descriptionId) { override val type = TYPE_SINGLE_CHOICE val selectedValue: Int get() = if (setting != null) { val setting = setting as IntSetting - setting.value + setting.int } else { - defaultValue + defaultValue!! } /** @@ -31,17 +30,11 @@ class SingleChoiceSetting( * initializes a new one and returns it, so it can be added to the Hashmap. * * @param selection New value of the int. - * @return null if overwritten successfully otherwise; a newly created IntSetting. + * @return the existing setting with the new value applied. */ - fun setSelectedValue(selection: Int): IntSetting? { - return if (setting == null) { - val newSetting = IntSetting(key!!, section!!, selection) - setting = newSetting - newSetting - } else { - val newSetting = setting as IntSetting - newSetting.value = selection - null - } + fun setSelectedValue(selection: Int): AbstractIntSetting { + val intSetting = setting as AbstractIntSetting + intSetting.int = selection + return intSetting } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.kt index 832e9d858..e216d0b69 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.kt @@ -3,31 +3,32 @@ package org.yuzu.yuzu_emu.features.settings.model.view +import org.yuzu.yuzu_emu.features.settings.model.AbstractFloatSetting +import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting +import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting import org.yuzu.yuzu_emu.features.settings.model.FloatSetting import org.yuzu.yuzu_emu.features.settings.model.IntSetting -import org.yuzu.yuzu_emu.features.settings.model.Setting import org.yuzu.yuzu_emu.utils.Log import kotlin.math.roundToInt class SliderSetting( - key: String, - section: String, - setting: Setting?, + setting: AbstractSetting?, titleId: Int, descriptionId: Int, val min: Int, val max: Int, val units: String, - val defaultValue: Int, -) : SettingsItem(key, section, setting, titleId, descriptionId) { + val key: String? = null, + val defaultValue: Int? = null, +) : SettingsItem(setting, titleId, descriptionId) { override val type = TYPE_SLIDER val selectedValue: Int get() { - val setting = setting ?: return defaultValue + val setting = setting ?: return defaultValue!! return when (setting) { - is IntSetting -> setting.value - is FloatSetting -> setting.value.roundToInt() + is IntSetting -> setting.int + is FloatSetting -> setting.float.roundToInt() else -> { Log.error("[SliderSetting] Error casting setting type.") -1 @@ -40,18 +41,12 @@ class SliderSetting( * initializes a new one and returns it, so it can be added to the Hashmap. * * @param selection New value of the int. - * @return null if overwritten successfully otherwise; a newly created IntSetting. + * @return the existing setting with the new value applied. */ - fun setSelectedValue(selection: Int): IntSetting? { - return if (setting == null) { - val newSetting = IntSetting(key!!, section!!, selection) - setting = newSetting - newSetting - } else { - val newSetting = setting as IntSetting - newSetting.value = selection - null - } + fun setSelectedValue(selection: Int): AbstractIntSetting { + val intSetting = setting as AbstractIntSetting + intSetting.int = selection + return intSetting } /** @@ -59,17 +54,11 @@ class SliderSetting( * initializes a new one and returns it, so it can be added to the Hashmap. * * @param selection New value of the float. - * @return null if overwritten successfully otherwise; a newly created FloatSetting. + * @return the existing setting with the new value applied. */ - fun setSelectedValue(selection: Float): FloatSetting? { - return if (setting == null) { - val newSetting = FloatSetting(key!!, section!!, selection) - setting = newSetting - newSetting - } else { - val newSetting = setting as FloatSetting - newSetting.value = selection - null - } + fun setSelectedValue(selection: Float): AbstractFloatSetting { + val floatSetting = setting as AbstractFloatSetting + floatSetting.float = selection + return floatSetting } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/StringSingleChoiceSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/StringSingleChoiceSetting.kt index aa1ab2779..1a8173b3c 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/StringSingleChoiceSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/StringSingleChoiceSetting.kt @@ -3,19 +3,19 @@ package org.yuzu.yuzu_emu.features.settings.model.view -import org.yuzu.yuzu_emu.features.settings.model.Setting +import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting +import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting import org.yuzu.yuzu_emu.features.settings.model.StringSetting class StringSingleChoiceSetting( - key: String, - section: String, - setting: Setting?, + val key: String? = null, + setting: AbstractSetting?, titleId: Int, descriptionId: Int, val choicesId: Array<String>, private val valuesId: Array<String>?, - private val defaultValue: String -) : SettingsItem(key, section, setting, titleId, descriptionId) { + private val defaultValue: String? = null +) : SettingsItem(setting, titleId, descriptionId) { override val type = TYPE_STRING_SINGLE_CHOICE fun getValueAt(index: Int): String? { @@ -28,9 +28,9 @@ class StringSingleChoiceSetting( val selectedValue: String get() = if (setting != null) { val setting = setting as StringSetting - setting.value + setting.string } else { - defaultValue + defaultValue!! } val selectValueIndex: Int get() { @@ -48,17 +48,11 @@ class StringSingleChoiceSetting( * initializes a new one and returns it, so it can be added to the Hashmap. * * @param selection New value of the int. - * @return null if overwritten successfully otherwise; a newly created IntSetting. + * @return the existing setting with the new value applied. */ - fun setSelectedValue(selection: String?): StringSetting? { - return if (setting == null) { - val newSetting = StringSetting(key!!, section!!, selection!!) - setting = newSetting - newSetting - } else { - val newSetting = setting as StringSetting - newSetting.value = selection!! - null - } + fun setSelectedValue(selection: String): AbstractStringSetting { + val stringSetting = setting as AbstractStringSetting + stringSetting.string = selection + return stringSetting } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SubmenuSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SubmenuSetting.kt index cda7a9225..8c1af6396 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SubmenuSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SubmenuSetting.kt @@ -3,16 +3,13 @@ package org.yuzu.yuzu_emu.features.settings.model.view -import org.yuzu.yuzu_emu.features.settings.model.Setting +import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting class SubmenuSetting( - key: String?, - setting: Setting?, + setting: AbstractSetting?, titleId: Int, descriptionId: Int, val menuKey: String -) : SettingsItem( - key, null, setting, titleId, descriptionId -) { +) : SettingsItem(setting, titleId, descriptionId) { override val type = TYPE_SUBMENU } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SwitchSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SwitchSetting.kt index b793012cc..6ed1aa880 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SwitchSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SwitchSetting.kt @@ -3,67 +3,42 @@ package org.yuzu.yuzu_emu.features.settings.model.view -import org.yuzu.yuzu_emu.R -import org.yuzu.yuzu_emu.YuzuApplication +import org.yuzu.yuzu_emu.features.settings.model.AbstractBooleanSetting +import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting +import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting import org.yuzu.yuzu_emu.features.settings.model.IntSetting -import org.yuzu.yuzu_emu.features.settings.model.Setting -import org.yuzu.yuzu_emu.features.settings.ui.SettingsFragmentView +import org.yuzu.yuzu_emu.utils.Log -class SwitchSetting : SettingsItem { +class SwitchSetting( + setting: AbstractSetting, + titleId: Int, + descriptionId: Int, + val key: String? = null, + val defaultValue: Boolean? = null +) : SettingsItem(setting, titleId, descriptionId) { override val type = TYPE_SWITCH - private var defaultValue: Boolean - private var showPerformanceWarning: Boolean - private var fragmentView: SettingsFragmentView? = null - - constructor( - key: String, - section: String, - setting: Setting?, - titleId: Int, - descriptionId: Int, - defaultValue: Boolean - ) : super(key, section, setting, titleId, descriptionId) { - this.defaultValue = defaultValue - showPerformanceWarning = false - } - - constructor( - key: String, - section: String, - titleId: Int, - descriptionId: Int, - defaultValue: Boolean, - setting: Setting, - show_performance_warning: Boolean, - view: SettingsFragmentView - ) : super(key, section, setting, titleId, descriptionId) { - this.defaultValue = defaultValue - fragmentView = view - showPerformanceWarning = show_performance_warning - } - val isChecked: Boolean get() { if (setting == null) { - return defaultValue + return defaultValue!! } // Try integer setting try { - val setting = setting as IntSetting - return setting.value == 1 + val setting = setting as AbstractIntSetting + return setting.int == 1 } catch (_: ClassCastException) { } // Try boolean setting try { - val setting = setting as BooleanSetting - return setting.value + val setting = setting as AbstractBooleanSetting + return setting.boolean } catch (_: ClassCastException) { } - return defaultValue + return defaultValue!! } /** @@ -71,24 +46,20 @@ class SwitchSetting : SettingsItem { * initializes a new one and returns it, so it can be added to the Hashmap. * * @param checked Pretty self explanatory. - * @return null if overwritten successfully; otherwise, a newly created BooleanSetting. + * @return the existing setting with the new value applied. */ - fun setChecked(checked: Boolean): IntSetting? { - // Show a performance warning if the setting has been disabled - if (showPerformanceWarning && !checked) { - fragmentView!!.showToastMessage( - YuzuApplication.appContext.getString(R.string.performance_warning), true - ) + fun setChecked(checked: Boolean): AbstractSetting { + // Try integer setting + try { + val setting = setting as AbstractIntSetting + setting.int = if (checked) 1 else 0 + return setting + } catch (_: ClassCastException) { } - return if (setting == null) { - val newSetting = IntSetting(key!!, section!!, if (checked) 1 else 0) - setting = newSetting - newSetting - } else { - val newSetting = setting as IntSetting - newSetting.value = if (checked) 1 else 0 - null - } + // Try boolean setting + val setting = setting as AbstractBooleanSetting + setting.boolean = checked + return setting } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsAdapter.kt index cdbdc78a0..286823562 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsAdapter.kt @@ -101,9 +101,7 @@ class SettingsAdapter( fun onBooleanClick(item: SwitchSetting, position: Int, checked: Boolean) { val setting = item.setChecked(checked) - if (setting != null) { - fragmentView.putSetting(setting) - } + fragmentView.putSetting(setting) fragmentView.onSettingChanged() } @@ -209,7 +207,7 @@ class SettingsAdapter( .setPositiveButton(android.R.string.ok, this) .setNegativeButton(android.R.string.cancel, defaultCancelListener) .setNeutralButton(R.string.slider_default) { dialog: DialogInterface, which: Int -> - sliderBinding.slider.value = item.defaultValue.toFloat() + sliderBinding.slider.value = item.defaultValue!!.toFloat() onClick(dialog, which) } .show() @@ -230,19 +228,15 @@ class SettingsAdapter( // Get the backing Setting, which may be null (if for example it was missing from the file) val setting = scSetting.setSelectedValue(value) - if (setting != null) { - fragmentView.putSetting(setting) - } + fragmentView.putSetting(setting) closeDialog() } is StringSingleChoiceSetting -> { val scSetting = clickedItem as StringSingleChoiceSetting val value = scSetting.getValueAt(which) if (scSetting.selectedValue != value) fragmentView.onSettingChanged() - val setting = scSetting.setSelectedValue(value) - if (setting != null) { - fragmentView.putSetting(setting) - } + val setting = scSetting.setSelectedValue(value!!) + fragmentView.putSetting(setting) closeDialog() } is SliderSetting -> { @@ -253,14 +247,10 @@ class SettingsAdapter( if (sliderSetting.setting is FloatSetting) { val value = sliderProgress.toFloat() val setting = sliderSetting.setSelectedValue(value) - if (setting != null) { - fragmentView.putSetting(setting) - } + fragmentView.putSetting(setting) } else { val setting = sliderSetting.setSelectedValue(sliderProgress) - if (setting != null) { - fragmentView.putSetting(setting) - } + fragmentView.putSetting(setting) } closeDialog() } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt index a9cfdc21f..687d06f2f 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt @@ -15,8 +15,7 @@ import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.divider.MaterialDividerItemDecoration import org.yuzu.yuzu_emu.databinding.FragmentSettingsBinding -import org.yuzu.yuzu_emu.features.settings.model.Setting -import org.yuzu.yuzu_emu.features.settings.model.Settings +import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem class SettingsFragment : Fragment(), SettingsFragmentView { @@ -91,7 +90,7 @@ class SettingsFragment : Fragment(), SettingsFragmentView { activityView!!.showToastMessage(message!!, is_long) } - override fun putSetting(setting: Setting) { + override fun putSetting(setting: AbstractSetting) { fragmentPresenter.putSetting(setting) } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt index aeb262ce6..af85065d0 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt @@ -6,7 +6,9 @@ package org.yuzu.yuzu_emu.features.settings.ui import android.text.TextUtils import androidx.appcompat.app.AppCompatActivity import org.yuzu.yuzu_emu.R -import org.yuzu.yuzu_emu.features.settings.model.Setting +import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting +import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting +import org.yuzu.yuzu_emu.features.settings.model.IntSetting import org.yuzu.yuzu_emu.features.settings.model.Settings import org.yuzu.yuzu_emu.features.settings.model.view.* import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile @@ -28,8 +30,11 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) loadSettingsList() } - fun putSetting(setting: Setting) { - settings.getSection(setting.section)!!.putSetting(setting) + fun putSetting(setting: AbstractSetting) { + val section = settings.getSection(setting.section!!)!! + if (section.getSetting(setting.key!!) == null) { + section.putSetting(setting) + } } fun loadSettingsList() { @@ -61,7 +66,6 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) add( SubmenuSetting( null, - null, R.string.preferences_general, 0, Settings.SECTION_GENERAL @@ -70,7 +74,6 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) add( SubmenuSetting( null, - null, R.string.preferences_system, 0, Settings.SECTION_SYSTEM @@ -79,7 +82,6 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) add( SubmenuSetting( null, - null, R.string.preferences_graphics, 0, Settings.SECTION_RENDERER @@ -88,7 +90,6 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) add( SubmenuSetting( null, - null, R.string.preferences_audio, 0, Settings.SECTION_AUDIO @@ -99,45 +100,36 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) private fun addGeneralSettings(sl: ArrayList<SettingsItem>) { settingsActivity.setTitle(R.string.preferences_general) - val rendererSection = settings.getSection(Settings.SECTION_RENDERER) - val frameLimitEnable = - rendererSection!!.getSetting(SettingsFile.KEY_RENDERER_USE_SPEED_LIMIT) - val frameLimitValue = rendererSection.getSetting(SettingsFile.KEY_RENDERER_SPEED_LIMIT) - val cpuSection = settings.getSection(Settings.SECTION_CPU) - val cpuAccuracy = cpuSection!!.getSetting(SettingsFile.KEY_CPU_ACCURACY) sl.apply { add( SwitchSetting( - SettingsFile.KEY_RENDERER_USE_SPEED_LIMIT, - Settings.SECTION_RENDERER, - frameLimitEnable, + IntSetting.RENDERER_USE_SPEED_LIMIT, R.string.frame_limit_enable, R.string.frame_limit_enable_description, + IntSetting.RENDERER_USE_SPEED_LIMIT.key, true ) ) add( SliderSetting( - SettingsFile.KEY_RENDERER_SPEED_LIMIT, - Settings.SECTION_RENDERER, - frameLimitValue, + IntSetting.RENDERER_SPEED_LIMIT, R.string.frame_limit_slider, R.string.frame_limit_slider_description, 1, 200, "%", + IntSetting.RENDERER_SPEED_LIMIT.key, 100 ) ) add( SingleChoiceSetting( - SettingsFile.KEY_CPU_ACCURACY, - Settings.SECTION_CPU, - cpuAccuracy, + IntSetting.CPU_ACCURACY, R.string.cpu_accuracy, 0, R.array.cpuAccuracyNames, R.array.cpuAccuracyValues, + IntSetting.CPU_ACCURACY.key, 0 ) ) @@ -146,42 +138,35 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) private fun addSystemSettings(sl: ArrayList<SettingsItem>) { settingsActivity.setTitle(R.string.preferences_system) - val systemSection = settings.getSection(Settings.SECTION_SYSTEM) - val dockedMode = systemSection!!.getSetting(SettingsFile.KEY_USE_DOCKED_MODE) - val region = systemSection.getSetting(SettingsFile.KEY_REGION_INDEX) - val language = systemSection.getSetting(SettingsFile.KEY_LANGUAGE_INDEX) sl.apply { add( SwitchSetting( - SettingsFile.KEY_USE_DOCKED_MODE, - Settings.SECTION_SYSTEM, - dockedMode, + IntSetting.USE_DOCKED_MODE, R.string.use_docked_mode, R.string.use_docked_mode_description, - false, + IntSetting.USE_DOCKED_MODE.key, + false ) ) add( SingleChoiceSetting( - SettingsFile.KEY_REGION_INDEX, - Settings.SECTION_SYSTEM, - region, + IntSetting.REGION_INDEX, R.string.emulated_region, 0, R.array.regionNames, R.array.regionValues, + IntSetting.REGION_INDEX.key, -1 ) ) add( SingleChoiceSetting( - SettingsFile.KEY_LANGUAGE_INDEX, - Settings.SECTION_SYSTEM, - language, + IntSetting.LANGUAGE_INDEX, R.string.emulated_language, 0, R.array.languageNames, R.array.languageValues, + IntSetting.LANGUAGE_INDEX.key, 1 ) ) @@ -190,133 +175,106 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) private fun addGraphicsSettings(sl: ArrayList<SettingsItem>) { settingsActivity.setTitle(R.string.preferences_graphics) - val rendererSection = settings.getSection(Settings.SECTION_RENDERER) - val rendererBackend = rendererSection!!.getSetting(SettingsFile.KEY_RENDERER_BACKEND) - val rendererAccuracy = rendererSection.getSetting(SettingsFile.KEY_RENDERER_ACCURACY) - val rendererResolution = rendererSection.getSetting(SettingsFile.KEY_RENDERER_RESOLUTION) - val rendererScalingFilter = - rendererSection.getSetting(SettingsFile.KEY_RENDERER_SCALING_FILTER) - val rendererAntiAliasing = - rendererSection.getSetting(SettingsFile.KEY_RENDERER_ANTI_ALIASING) - val rendererAspectRatio = - rendererSection.getSetting(SettingsFile.KEY_RENDERER_ASPECT_RATIO) - val rendererUseDiskShaderCache = - rendererSection.getSetting(SettingsFile.KEY_RENDERER_USE_DISK_SHADER_CACHE) - val rendererForceMaxClocks = - rendererSection.getSetting(SettingsFile.KEY_RENDERER_FORCE_MAX_CLOCK) - val rendererAsynchronousShaders = - rendererSection.getSetting(SettingsFile.KEY_RENDERER_ASYNCHRONOUS_SHADERS) - val rendererDebug = rendererSection.getSetting(SettingsFile.KEY_RENDERER_DEBUG) sl.apply { add( SingleChoiceSetting( - SettingsFile.KEY_RENDERER_BACKEND, - Settings.SECTION_RENDERER, - rendererBackend, + IntSetting.RENDERER_BACKEND, R.string.renderer_api, 0, R.array.rendererApiNames, R.array.rendererApiValues, + IntSetting.RENDERER_BACKEND.key, 1 ) ) add( SingleChoiceSetting( - SettingsFile.KEY_RENDERER_ACCURACY, - Settings.SECTION_RENDERER, - rendererAccuracy, + IntSetting.RENDERER_ACCURACY, R.string.renderer_accuracy, 0, R.array.rendererAccuracyNames, R.array.rendererAccuracyValues, + IntSetting.RENDERER_ACCURACY.key, 0 ) ) add( SingleChoiceSetting( - SettingsFile.KEY_RENDERER_RESOLUTION, - Settings.SECTION_RENDERER, - rendererResolution, + IntSetting.RENDERER_RESOLUTION, R.string.renderer_resolution, 0, R.array.rendererResolutionNames, R.array.rendererResolutionValues, + IntSetting.RENDERER_RESOLUTION.key, 2 ) ) add( SingleChoiceSetting( - SettingsFile.KEY_RENDERER_SCALING_FILTER, - Settings.SECTION_RENDERER, - rendererScalingFilter, + IntSetting.RENDERER_SCALING_FILTER, R.string.renderer_scaling_filter, 0, R.array.rendererScalingFilterNames, R.array.rendererScalingFilterValues, + IntSetting.RENDERER_SCALING_FILTER.key, 1 ) ) add( SingleChoiceSetting( - SettingsFile.KEY_RENDERER_ANTI_ALIASING, - Settings.SECTION_RENDERER, - rendererAntiAliasing, + IntSetting.RENDERER_ANTI_ALIASING, R.string.renderer_anti_aliasing, 0, R.array.rendererAntiAliasingNames, R.array.rendererAntiAliasingValues, + IntSetting.RENDERER_ANTI_ALIASING.key, 0 ) ) add( SingleChoiceSetting( - SettingsFile.KEY_RENDERER_ASPECT_RATIO, - Settings.SECTION_RENDERER, - rendererAspectRatio, + IntSetting.RENDERER_ASPECT_RATIO, R.string.renderer_aspect_ratio, 0, R.array.rendererAspectRatioNames, R.array.rendererAspectRatioValues, + IntSetting.RENDERER_ASPECT_RATIO.key, 0 ) ) add( SwitchSetting( - SettingsFile.KEY_RENDERER_USE_DISK_SHADER_CACHE, - Settings.SECTION_RENDERER, - rendererUseDiskShaderCache, + IntSetting.RENDERER_USE_DISK_SHADER_CACHE, R.string.use_disk_shader_cache, R.string.use_disk_shader_cache_description, + IntSetting.RENDERER_USE_DISK_SHADER_CACHE.key, true ) ) add( SwitchSetting( - SettingsFile.KEY_RENDERER_FORCE_MAX_CLOCK, - Settings.SECTION_RENDERER, - rendererForceMaxClocks, + IntSetting.RENDERER_FORCE_MAX_CLOCK, R.string.renderer_force_max_clock, R.string.renderer_force_max_clock_description, + IntSetting.RENDERER_FORCE_MAX_CLOCK.key, true ) ) add( SwitchSetting( - SettingsFile.KEY_RENDERER_ASYNCHRONOUS_SHADERS, - Settings.SECTION_RENDERER, - rendererAsynchronousShaders, + IntSetting.RENDERER_ASYNCHRONOUS_SHADERS, R.string.renderer_asynchronous_shaders, R.string.renderer_asynchronous_shaders_description, + IntSetting.RENDERER_ASYNCHRONOUS_SHADERS.key, false ) ) add( SwitchSetting( - SettingsFile.KEY_RENDERER_DEBUG, - Settings.SECTION_RENDERER, - rendererDebug, + IntSetting.RENDERER_DEBUG, R.string.renderer_debug, R.string.renderer_debug_description, + IntSetting.RENDERER_DEBUG.key, false ) ) @@ -325,18 +283,15 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) private fun addAudioSettings(sl: ArrayList<SettingsItem>) { settingsActivity.setTitle(R.string.preferences_audio) - val audioSection = settings.getSection(Settings.SECTION_AUDIO) - val audioVolume = audioSection!!.getSetting(SettingsFile.KEY_AUDIO_VOLUME) sl.add( SliderSetting( - SettingsFile.KEY_AUDIO_VOLUME, - Settings.SECTION_AUDIO, - audioVolume, + IntSetting.AUDIO_VOLUME, R.string.audio_volume, R.string.audio_volume_description, 0, 100, "%", + IntSetting.AUDIO_VOLUME.key, 100 ) ) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentView.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentView.kt index 9a14c5795..1ebe35eaa 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentView.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentView.kt @@ -3,7 +3,7 @@ package org.yuzu.yuzu_emu.features.settings.ui -import org.yuzu.yuzu_emu.features.settings.model.Setting +import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem /** @@ -49,7 +49,7 @@ interface SettingsFragmentView { * * @param setting The (possibly previously missing) new setting. */ - fun putSetting(setting: Setting) + fun putSetting(setting: AbstractSetting) /** * Have the fragment tell the containing Activity that a setting was modified. diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/utils/SettingsFile.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/utils/SettingsFile.kt index 493d90954..9c6515a54 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/utils/SettingsFile.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/utils/SettingsFile.kt @@ -21,32 +21,7 @@ import java.util.* */ object SettingsFile { const val FILE_NAME_CONFIG = "config" - const val KEY_DESIGN = "design" - - // CPU - const val KEY_CPU_ACCURACY = "cpu_accuracy" - - // System - const val KEY_USE_DOCKED_MODE = "use_docked_mode" - const val KEY_REGION_INDEX = "region_index" - const val KEY_LANGUAGE_INDEX = "language_index" - const val KEY_RENDERER_BACKEND = "backend" - - // Renderer - const val KEY_RENDERER_RESOLUTION = "resolution_setup" - const val KEY_RENDERER_SCALING_FILTER = "scaling_filter" - const val KEY_RENDERER_ANTI_ALIASING = "anti_aliasing" - const val KEY_RENDERER_ASPECT_RATIO = "aspect_ratio" - const val KEY_RENDERER_ACCURACY = "gpu_accuracy" - const val KEY_RENDERER_USE_DISK_SHADER_CACHE = "use_disk_shader_cache" - const val KEY_RENDERER_ASYNCHRONOUS_SHADERS = "use_asynchronous_shaders" - const val KEY_RENDERER_FORCE_MAX_CLOCK = "force_max_clock" - const val KEY_RENDERER_USE_SPEED_LIMIT = "use_speed_limit" - const val KEY_RENDERER_DEBUG = "debug" - const val KEY_RENDERER_SPEED_LIMIT = "speed_limit" - - // Audio - const val KEY_AUDIO_VOLUME = "volume" + private val sectionsMap = BiMap<String?, String?>() /** @@ -75,7 +50,7 @@ object SettingsFile { current = sectionFromLine(line!!, isCustomGame) sections[current.name] = current } else if (current != null) { - val setting = settingFromLine(current, line!!) + val setting = settingFromLine(line!!) if (setting != null) { current.putSetting(setting) } @@ -201,11 +176,10 @@ object SettingsFile { * For a line of text, determines what type of data is being represented, and returns * a Setting object containing this data. * - * @param current The section currently being parsed by the consuming method. * @param line The line of text being parsed. * @return A typed Setting containing the key/value contained in the line. */ - private fun settingFromLine(current: SettingSection, line: String): Setting? { + private fun settingFromLine(line: String): AbstractSetting? { val splitLine = line.split("=".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() if (splitLine.size != 2) { Log.warning("Skipping invalid config line \"$line\"") @@ -217,17 +191,25 @@ object SettingsFile { Log.warning("Skipping null value in config line \"$line\"") return null } - try { - val valueAsInt = value.toInt() - return IntSetting(key, current.name, valueAsInt) - } catch (_: NumberFormatException) { + + val booleanSetting = BooleanSetting.from(key) + if (booleanSetting != null) { + booleanSetting.boolean = value.toBoolean() + return booleanSetting } - try { - val valueAsFloat = value.toFloat() - return FloatSetting(key, current.name, valueAsFloat) - } catch (_: NumberFormatException) { + + val intSetting = IntSetting.from(key) + if (intSetting != null) { + intSetting.int = value.toInt() + return intSetting + } + + val floatSetting = FloatSetting.from(key) + if (floatSetting != null) { + floatSetting.float = value.toFloat() + return floatSetting } - return StringSetting(key, current.name, value) + return StringSetting.from(key) } /** |