Android: Convert GeckoCheat to Kotlin

This commit is contained in:
Charles Lombardo 2023-03-01 13:35:14 -05:00
parent 9e090c6bab
commit 37e8cd1789
3 changed files with 73 additions and 79 deletions

View File

@ -1,78 +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;
import androidx.annotation.Nullable;
public class GeckoCheat extends AbstractCheat
{
@Keep
private final long mPointer;
public GeckoCheat()
{
mPointer = createNew();
}
@Keep
private GeckoCheat(long pointer)
{
mPointer = pointer;
}
@Override
public native void finalize();
private native long createNew();
@Override
public boolean equals(@Nullable Object obj)
{
return obj != null && getClass() == obj.getClass() && equalsImpl((GeckoCheat) obj);
}
public boolean supportsCreator()
{
return true;
}
public boolean supportsNotes()
{
return true;
}
@NonNull
public native String getName();
@NonNull
public native String getCreator();
@NonNull
public native String getNotes();
@NonNull
public native String getCode();
public native boolean getUserDefined();
public native boolean getEnabled();
public native boolean equalsImpl(@NonNull GeckoCheat other);
@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 GeckoCheat[] loadCodes(String gameId, int revision);
public static native void saveCodes(String gameId, int revision, GeckoCheat[] codes);
@Nullable
public static native GeckoCheat[] downloadCodes(String gameTdbId);
}

View File

@ -0,0 +1,72 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.cheats.model
import androidx.annotation.Keep
class GeckoCheat : AbstractCheat {
@Keep
private val mPointer: Long
constructor() {
mPointer = createNew()
}
@Keep
private constructor(pointer: Long) {
mPointer = pointer
}
external fun finalize()
private external fun createNew(): Long
override fun equals(other: Any?): Boolean {
return other != null && javaClass == other.javaClass && equalsImpl(other as GeckoCheat)
}
override fun hashCode(): Int {
return mPointer.hashCode()
}
override fun supportsCreator(): Boolean {
return true
}
override fun supportsNotes(): Boolean {
return true
}
external override fun getName(): String
external override fun getCreator(): String
external override fun getNotes(): String
external override fun getCode(): String
external override fun getUserDefined(): Boolean
external override fun getEnabled(): Boolean
private external fun equalsImpl(other: GeckoCheat): Boolean
external override fun setCheatImpl(
name: String,
creator: String,
notes: String,
code: String
): Int
external override fun setEnabledImpl(enabled: Boolean)
companion object {
@JvmStatic
external fun loadCodes(gameId: String, revision: Int): Array<GeckoCheat>
@JvmStatic
external fun saveCodes(gameId: String, revision: Int, codes: Array<GeckoCheat>)
@JvmStatic
external fun downloadCodes(gameTdbId: String): Array<GeckoCheat>?
}
}

View File

@ -99,7 +99,7 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_GeckoCheat_equalsImpl(JNIEn
return *GetPointer(env, obj) == *GetPointer(env, other);
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_features_cheats_model_GeckoCheat_trySetImpl(
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_features_cheats_model_GeckoCheat_setCheatImpl(
JNIEnv* env, jobject obj, jstring name, jstring creator, jstring notes, jstring code_string)
{
Gecko::GeckoCode* code = GetPointer(env, obj);