Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #11614 from t895/kotlin-cheats
Android: Convert Cheats Activity to Kotlin
- Loading branch information
Showing
48 changed files
with
1,511 additions
and
1,917 deletions.
There are no files selected for viewing
60 changes: 0 additions & 60 deletions
60
...ce/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ARCheat.java
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ARCheat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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>) | ||
| } | ||
| } |
45 changes: 0 additions & 45 deletions
45
...roid/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/AbstractCheat.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
...ndroid/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/AbstractCheat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| package org.dolphinemu.dolphinemu.features.cheats.model | ||
|
|
||
| import org.dolphinemu.dolphinemu.features.cheats.model.Cheat.Companion.TRY_SET_FAIL_NO_NAME | ||
| import org.dolphinemu.dolphinemu.features.cheats.model.Cheat.Companion.TRY_SET_SUCCESS | ||
|
|
||
| abstract class AbstractCheat : ReadOnlyCheat() { | ||
| override fun supportsCode(): Boolean { | ||
| return true | ||
| } | ||
|
|
||
| override fun setCheat( | ||
| name: String, | ||
| creator: String, | ||
| notes: String, | ||
| code: String | ||
| ): Int { | ||
| var finalName = name | ||
| var finalCode = code | ||
| if (finalCode.isNotEmpty() && finalCode[0] == '$') { | ||
| val firstLineEnd = finalCode.indexOf('\n') | ||
| if (firstLineEnd == -1) { | ||
| finalName = finalCode.substring(1) | ||
| finalCode = "" | ||
| } else { | ||
| finalName = finalCode.substring(1, firstLineEnd) | ||
| finalCode = finalCode.substring(firstLineEnd + 1) | ||
| } | ||
| } | ||
|
|
||
| if (finalName.isEmpty()) return TRY_SET_FAIL_NO_NAME | ||
|
|
||
| val result = setCheatImpl(finalName, creator, notes, finalCode) | ||
|
|
||
| if (result == TRY_SET_SUCCESS) onChanged() | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| protected abstract fun setCheatImpl( | ||
| name: String, | ||
| creator: String, | ||
| notes: String, | ||
| code: String | ||
| ): Int | ||
| } |
53 changes: 0 additions & 53 deletions
53
Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/Cheat.java
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/Cheat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| package org.dolphinemu.dolphinemu.features.cheats.model | ||
|
|
||
| interface Cheat { | ||
| fun supportsCreator(): Boolean | ||
|
|
||
| fun supportsNotes(): Boolean | ||
|
|
||
| fun supportsCode(): Boolean | ||
|
|
||
| fun getName(): String = "" | ||
|
|
||
| fun getCreator(): String = "" | ||
|
|
||
| fun getNotes(): String = "" | ||
|
|
||
| fun getCode(): String = "" | ||
|
|
||
| fun setCheat( | ||
| name: String, | ||
| creator: String, | ||
| notes: String, | ||
| code: String | ||
| ): Int | ||
|
|
||
| fun getUserDefined(): Boolean | ||
|
|
||
| fun getEnabled(): Boolean | ||
|
|
||
| fun setEnabled(isChecked: Boolean) | ||
|
|
||
| fun setChangedCallback(callback: Runnable?) | ||
|
|
||
| companion object { | ||
| // Result codes greater than 0 represent an error on the corresponding code line (one-indexed) | ||
| const val TRY_SET_FAIL_CODE_MIXED_ENCRYPTION = -3 | ||
| const val TRY_SET_FAIL_NO_CODE_LINES = -2 | ||
| const val TRY_SET_FAIL_NO_NAME = -1 | ||
| const val TRY_SET_SUCCESS = 0 | ||
| } | ||
| } |
Oops, something went wrong.