Android: Convert RiivolutionPatches to Kotlin

This commit is contained in:
Charles Lombardo 2023-03-01 14:38:02 -05:00
parent c5e00b085e
commit ec7b811de3
3 changed files with 81 additions and 87 deletions

View File

@ -1,86 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.riivolution.model;
import androidx.annotation.Keep;
public class RiivolutionPatches
{
private String mGameId;
private int mRevision;
private int mDiscNumber;
private boolean mUnsavedChanges = false;
@Keep
private long mPointer;
public RiivolutionPatches(String gameId, int revision, int discNumber)
{
mGameId = gameId;
mRevision = revision;
mDiscNumber = discNumber;
mPointer = initialize();
}
@Override
public native void finalize();
private static native long initialize();
public native int getDiscCount();
public native String getDiscName(int discIndex);
public native int getSectionCount(int discIndex);
public native String getSectionName(int discIndex, int sectionIndex);
public native int getOptionCount(int discIndex, int sectionIndex);
public native String getOptionName(int discIndex, int sectionIndex, int optionIndex);
public native int getChoiceCount(int discIndex, int sectionIndex, int optionIndex);
public native String getChoiceName(int discIndex, int sectionIndex, int optionIndex,
int choiceIndex);
/**
* @return 0 if no choice is selected, otherwise the index of the selected choice plus one.
*/
public native int getSelectedChoice(int discIndex, int sectionIndex, int optionIndex);
/**
* @param choiceIndex 0 to select no choice, otherwise the choice index plus one.
*/
public void setSelectedChoice(int discIndex, int sectionIndex, int optionIndex, int choiceIndex)
{
mUnsavedChanges = true;
setSelectedChoiceImpl(discIndex, sectionIndex, optionIndex, choiceIndex);
}
/**
* @param choiceIndex 0 to select no choice, otherwise the choice index plus one.
*/
private native void setSelectedChoiceImpl(int discIndex, int sectionIndex, int optionIndex,
int choiceIndex);
public void loadConfig()
{
loadConfigImpl(mGameId, mRevision, mDiscNumber);
}
private native void loadConfigImpl(String gameId, int revision, int discNumber);
public void saveConfig()
{
if (mUnsavedChanges)
{
mUnsavedChanges = false;
saveConfigImpl(mGameId);
}
}
private native void saveConfigImpl(String gameId);
}

View File

@ -0,0 +1,80 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.riivolution.model
import androidx.annotation.Keep
class RiivolutionPatches(
private val gameId: String,
private val revision: Int,
private val discNumber: Int
) {
private var unsavedChanges = false
@Keep
private val pointer: Long = initialize()
external fun finalize()
external fun getDiscCount(): Int
external fun getDiscName(discIndex: Int): String
external fun getSectionCount(discIndex: Int): Int
external fun getSectionName(discIndex: Int, sectionIndex: Int): String
external fun getOptionCount(discIndex: Int, sectionIndex: Int): Int
external fun getOptionName(discIndex: Int, sectionIndex: Int, optionIndex: Int): String
external fun getChoiceCount(discIndex: Int, sectionIndex: Int, optionIndex: Int): Int
external fun getChoiceName(
discIndex: Int,
sectionIndex: Int,
optionIndex: Int,
choiceIndex: Int
): String
/**
* @return 0 if no choice is selected, otherwise the index of the selected choice plus one.
*/
external fun getSelectedChoice(discIndex: Int, sectionIndex: Int, optionIndex: Int): Int
/**
* @param choiceIndex 0 to select no choice, otherwise the choice index plus one.
*/
fun setSelectedChoice(discIndex: Int, sectionIndex: Int, optionIndex: Int, choiceIndex: Int) {
unsavedChanges = true
setSelectedChoiceImpl(discIndex, sectionIndex, optionIndex, choiceIndex)
}
/**
* @param choiceIndex 0 to select no choice, otherwise the choice index plus one.
*/
private external fun setSelectedChoiceImpl(
discIndex: Int, sectionIndex: Int, optionIndex: Int,
choiceIndex: Int
)
fun loadConfig() {
loadConfigImpl(gameId, revision, discNumber)
}
private external fun loadConfigImpl(gameId: String, revision: Int, discNumber: Int)
fun saveConfig() {
if (unsavedChanges) {
unsavedChanges = false
saveConfigImpl(gameId)
}
}
private external fun saveConfigImpl(gameId: String)
companion object {
@JvmStatic
private external fun initialize(): Long
}
}

View File

@ -539,7 +539,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
env->FindClass("org/dolphinemu/dolphinemu/features/riivolution/model/RiivolutionPatches");
s_riivolution_patches_class =
reinterpret_cast<jclass>(env->NewGlobalRef(riivolution_patches_class));
s_riivolution_patches_pointer = env->GetFieldID(riivolution_patches_class, "mPointer", "J");
s_riivolution_patches_pointer = env->GetFieldID(riivolution_patches_class, "pointer", "J");
env->DeleteLocalRef(riivolution_patches_class);
const jclass wii_update_cb_class =