mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 00:09:23 +07:00
Console: Normalized addStat subcommand
This commit is contained in:
@ -11,6 +11,7 @@ internal fun String.toCliInput() = this.lowercase().replace(" ","-")
|
|||||||
|
|
||||||
interface ConsoleCommand {
|
interface ConsoleCommand {
|
||||||
fun handle(console: DevConsolePopup, params: List<String>): DevConsoleResponse
|
fun handle(console: DevConsolePopup, params: List<String>): DevConsoleResponse
|
||||||
|
/** Returns the string to *add* to the existing command */
|
||||||
fun autocomplete(params: List<String>): String? = ""
|
fun autocomplete(params: List<String>): String? = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +58,8 @@ interface ConsoleCommandNode : ConsoleCommand {
|
|||||||
}
|
}
|
||||||
return firstSubcommand.removePrefix(firstParam)
|
return firstSubcommand.removePrefix(firstParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConsoleCommandRoot : ConsoleCommandNode {
|
class ConsoleCommandRoot : ConsoleCommandNode {
|
||||||
@ -223,18 +226,17 @@ class ConsoleTileCommands: ConsoleCommandNode {
|
|||||||
|
|
||||||
class ConsoleCivCommands : ConsoleCommandNode {
|
class ConsoleCivCommands : ConsoleCommandNode {
|
||||||
override val subcommands = hashMapOf<String, ConsoleCommand>(
|
override val subcommands = hashMapOf<String, ConsoleCommand>(
|
||||||
"addstat" to ConsoleAction("civ addstat [civ] <stat> <amount>") { console, params ->
|
"addstat" to ConsoleAction("civ addstat <stat> <amount> [civ]") { console, params ->
|
||||||
var statPos = 0
|
val stat = Stat.safeValueOf(params[0].replaceFirstChar(Char::titlecase))
|
||||||
val civ = if (params.size == 2) console.screen.selectedCiv
|
?: throw ConsoleErrorException("Whut? \"${params[0]}\" is not a Stat!")
|
||||||
else {
|
|
||||||
statPos++
|
|
||||||
console.getCivByName(params[0])
|
|
||||||
}
|
|
||||||
val amount = console.getInt(params[statPos+1])
|
|
||||||
val stat = Stat.safeValueOf(params[statPos].replaceFirstChar(Char::titlecase))
|
|
||||||
?: throw ConsoleErrorException("Whut? \"${params[statPos]}\" is not a Stat!")
|
|
||||||
if (stat !in Stat.statsWithCivWideField)
|
if (stat !in Stat.statsWithCivWideField)
|
||||||
throw ConsoleErrorException("$stat is not civ-wide")
|
throw ConsoleErrorException("$stat is not civ-wide")
|
||||||
|
|
||||||
|
val amount = console.getInt(params[1])
|
||||||
|
|
||||||
|
val civ = if (params.size == 2) console.screen.selectedCiv
|
||||||
|
else console.getCivByName(params[2])
|
||||||
|
|
||||||
civ.addStat(stat, amount)
|
civ.addStat(stat, amount)
|
||||||
DevConsoleResponse.OK
|
DevConsoleResponse.OK
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user