From 46e68171b984726a0b09f8237901f4233cdc3e93 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Wed, 15 Mar 2023 03:24:50 -0400 Subject: [PATCH] Android: Convert FloatSetting to Kotlin --- .../features/settings/model/FloatSetting.java | 73 ------------------- .../features/settings/model/FloatSetting.kt | 41 +++++++++++ 2 files changed, 41 insertions(+), 73 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java deleted file mode 100644 index 99d15957c4..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java +++ /dev/null @@ -1,73 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.dolphinemu.dolphinemu.features.settings.model; - -import androidx.annotation.NonNull; - -public enum FloatSetting implements AbstractFloatSetting -{ - // These entries have the same names and order as in C++, just for consistency. - - MAIN_EMULATION_SPEED(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "EmulationSpeed", 1.0f), - MAIN_OVERCLOCK(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "Overclock", 1.0f); - - private final String mFile; - private final String mSection; - private final String mKey; - private final float mDefaultValue; - - FloatSetting(String file, String section, String key, float defaultValue) - { - mFile = file; - mSection = section; - mKey = key; - mDefaultValue = defaultValue; - } - - @Override - public boolean isOverridden() - { - return NativeConfig.isOverridden(mFile, mSection, mKey); - } - - @Override - public boolean isRuntimeEditable() - { - return NativeConfig.isSettingSaveable(mFile, mSection, mKey); - } - - @Override - public boolean delete(@NonNull Settings settings) - { - if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey)) - { - throw new UnsupportedOperationException( - "Unsupported setting: " + mFile + ", " + mSection + ", " + mKey); - } - - return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey); - } - - @Override - public float getFloat() - { - return NativeConfig.getFloat(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue); - } - - @Override - public void setFloat(@NonNull Settings settings, float newValue) - { - if (!NativeConfig.isSettingSaveable(mFile, mSection, mKey)) - { - throw new UnsupportedOperationException( - "Unsupported setting: " + mFile + ", " + mSection + ", " + mKey); - } - - NativeConfig.setFloat(settings.getWriteLayer(), mFile, mSection, mKey, newValue); - } - - public void setFloat(int layer, float newValue) - { - NativeConfig.setFloat(layer, mFile, mSection, mKey, newValue); - } -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.kt new file mode 100644 index 0000000000..99b73251e7 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.kt @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.settings.model + +enum class FloatSetting( + private val file: String, + private val section: String, + private val key: String, + private val defaultValue: Float +) : AbstractFloatSetting { + // These entries have the same names and order as in C++, just for consistency. + MAIN_EMULATION_SPEED(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "EmulationSpeed", 1.0f), + MAIN_OVERCLOCK(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "Overclock", 1.0f); + + override val isOverridden: Boolean + get() = NativeConfig.isOverridden(file, section, key) + + override val isRuntimeEditable: Boolean + get() = NativeConfig.isSettingSaveable(file, section, key) + + override fun delete(settings: Settings): Boolean { + if (!NativeConfig.isSettingSaveable(file, section, key)) { + throw UnsupportedOperationException("Unsupported setting: $file, $section, $key") + } + return NativeConfig.deleteKey(settings.writeLayer, file, section, key) + } + + override val float: Float + get() = NativeConfig.getFloat(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue) + + override fun setFloat(settings: Settings, newValue: Float) { + if (!NativeConfig.isSettingSaveable(file, section, key)) { + throw UnsupportedOperationException("Unsupported setting: $file, $section, $key") + } + NativeConfig.setFloat(settings.writeLayer, file, section, key, newValue) + } + + fun setFloat(layer: Int, newValue: Float) { + NativeConfig.setFloat(layer, file, section, key, newValue) + } +}