Android: Convert ARCheat to Kotlin

This commit is contained in:
Charles Lombardo 2023-03-01 13:32:42 -05:00
parent 211be4698f
commit 408b6cb50c
4 changed files with 54 additions and 62 deletions

View File

@ -1,60 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.cheats.model;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
public class ARCheat extends AbstractCheat
{
@Keep
private final long mPointer;
public ARCheat()
{
mPointer = createNew();
}
@Keep
private ARCheat(long pointer)
{
mPointer = pointer;
}
@Override
public native void finalize();
private native long createNew();
public boolean supportsCreator()
{
return false;
}
public boolean supportsNotes()
{
return false;
}
@NonNull
public native String getName();
@NonNull
public native String getCode();
public native boolean getUserDefined();
public native boolean getEnabled();
@Override
protected native int trySetImpl(@NonNull String name, @NonNull String creator,
@NonNull String notes, @NonNull String code);
@Override
protected native void setEnabledImpl(boolean enabled);
@NonNull
public static native ARCheat[] loadCodes(String gameId, int revision);
public static native void saveCodes(String gameId, int revision, ARCheat[] codes);
}

View File

@ -0,0 +1,52 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.cheats.model
import androidx.annotation.Keep
class ARCheat : AbstractCheat {
@Keep
private val pointer: Long
constructor() {
pointer = createNew()
}
@Keep
private constructor(pointer: Long) {
this.pointer = pointer
}
external fun finalize()
private external fun createNew(): Long
override fun supportsCreator(): Boolean = false
override fun supportsNotes(): Boolean = false
external override fun getName(): String
external override fun getCode(): String
external override fun getUserDefined(): Boolean
external override fun getEnabled(): Boolean
external override fun setEnabledImpl(enabled: Boolean)
external override fun setCheatImpl(
name: String,
creator: String,
notes: String,
code: String
): Int
companion object {
@JvmStatic
external fun loadCodes(gameId: String, revision: Int): Array<ARCheat>
@JvmStatic
external fun saveCodes(gameId: String, revision: Int, codes: Array<ARCheat>)
}
}

View File

@ -500,7 +500,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
const jclass ar_cheat_class =
env->FindClass("org/dolphinemu/dolphinemu/features/cheats/model/ARCheat");
s_ar_cheat_class = reinterpret_cast<jclass>(env->NewGlobalRef(ar_cheat_class));
s_ar_cheat_pointer = env->GetFieldID(ar_cheat_class, "mPointer", "J");
s_ar_cheat_pointer = env->GetFieldID(ar_cheat_class, "pointer", "J");
s_ar_cheat_constructor = env->GetMethodID(ar_cheat_class, "<init>", "(J)V");
env->DeleteLocalRef(ar_cheat_class);

View File

@ -81,7 +81,7 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_ARCheat_getEnabled(JNIEnv*
return static_cast<jboolean>(GetPointer(env, obj)->enabled);
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_features_cheats_model_ARCheat_trySetImpl(
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_features_cheats_model_ARCheat_setCheatImpl(
JNIEnv* env, jobject obj, jstring name, jstring creator, jstring notes, jstring code_string)
{
ActionReplay::ARCode* code = GetPointer(env, obj);