mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 13:27:45 -07:00
Android: Convert AbstractCheat to Kotlin
This commit is contained in:
parent
37e8cd1789
commit
fbc617c917
@ -1,45 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.cheats.model;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public abstract class AbstractCheat extends ReadOnlyCheat
|
||||
{
|
||||
public boolean supportsCode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public int trySet(@NonNull String name, @NonNull String creator, @NonNull String notes,
|
||||
@NonNull String code)
|
||||
{
|
||||
if (!code.isEmpty() && code.charAt(0) == '$')
|
||||
{
|
||||
int firstLineEnd = code.indexOf('\n');
|
||||
if (firstLineEnd == -1)
|
||||
{
|
||||
name = code.substring(1);
|
||||
code = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
name = code.substring(1, firstLineEnd);
|
||||
code = code.substring(firstLineEnd + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (name.isEmpty())
|
||||
return TRY_SET_FAIL_NO_NAME;
|
||||
|
||||
int result = trySetImpl(name, creator, notes, code);
|
||||
|
||||
if (result == TRY_SET_SUCCESS)
|
||||
onChanged();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected abstract int trySetImpl(@NonNull String name, @NonNull String creator,
|
||||
@NonNull String notes, @NonNull String code);
|
||||
}
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user