mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 03:54:06 +09:00
WIP collision solver, colour-codes in game fonts
Former-commit-id: 0bb85999176d89956398bbcc24e1b33cacd3e87c Former-commit-id: 0ef0c1ac9b88f8fe42a7439fee69a8d4792be96a
This commit is contained in:
@@ -9,6 +9,8 @@ import org.apache.commons.codec.digest.DigestUtils
|
||||
*/
|
||||
class Authenticator : ConsoleCommand {
|
||||
|
||||
private var a = false
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
val pwd = args[1]
|
||||
@@ -38,9 +40,4 @@ class Authenticator : ConsoleCommand {
|
||||
override fun printUsage() {
|
||||
CommandInterpreter.echoUnknownCmd("auth")
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private var a = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ object CommandInterpreter {
|
||||
}
|
||||
}
|
||||
catch (e: Exception) {
|
||||
println("[CommandInterpreter] :")
|
||||
System.err.print("[CommandInterpreter] ")
|
||||
e.printStackTrace()
|
||||
Echo().execute(Lang.get("ERROR_GENERIC_TEXT"))
|
||||
Echo().error(Lang["ERROR_GENERIC_TEXT"])
|
||||
}
|
||||
|
||||
}
|
||||
@@ -92,8 +92,8 @@ object CommandInterpreter {
|
||||
val sb = StringBuilder()
|
||||
val formatter = Formatter(sb)
|
||||
|
||||
Echo().execute(
|
||||
formatter.format(Lang.get("DEV_MESSAGE_CONSOLE_COMMAND_UNKNOWN"), cmdname).toString())
|
||||
Echo().error(
|
||||
formatter.format(Lang["DEV_MESSAGE_CONSOLE_COMMAND_UNKNOWN"], cmdname).toString())
|
||||
}
|
||||
|
||||
private class CommandInput(o: Array<Any>) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.console
|
||||
|
||||
import net.torvald.imagefont.GameFontBase
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.ui.ConsoleWindow
|
||||
|
||||
@@ -20,6 +21,10 @@ internal class Echo : ConsoleCommand {
|
||||
(Terrarum.game.consoleHandler.UI as ConsoleWindow).sendMessage(single_line)
|
||||
}
|
||||
|
||||
fun error(single_line: String) {
|
||||
(Terrarum.game.consoleHandler.UI as ConsoleWindow).sendMessage("${GameFontBase.colToCode["r"]}$single_line")
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
|
||||
}
|
||||
|
||||
@@ -17,37 +17,73 @@ class GetAV : ConsoleCommand {
|
||||
val av = Terrarum.game.player.actorValue
|
||||
val keyset = av.keySet
|
||||
|
||||
echo.execute("== ActorValue list for player ==")
|
||||
keyset.forEach { elem -> echo.execute("$elem = ${av[elem as String]}") }
|
||||
|
||||
}
|
||||
else if (args.size != 3 && args.size != 2) {
|
||||
printUsage()
|
||||
}
|
||||
else if (args.size == 2) {
|
||||
echo.execute("player." + args[1] + " = "
|
||||
+ Terrarum.game.player.actorValue[args[1]]
|
||||
+ " ("
|
||||
+ Terrarum.game.player.actorValue[args[1]]!!.javaClass.simpleName
|
||||
+ ")")
|
||||
// check if args[1] is number or not
|
||||
if (!args[1].isNum()) { // args[1] is ActorValue name
|
||||
echo.execute("player.${args[1]} = "
|
||||
+ Terrarum.game.player.actorValue[args[1]]
|
||||
+ " ("
|
||||
+ Terrarum.game.player.actorValue[args[1]]!!.javaClass.simpleName
|
||||
+ ")"
|
||||
)
|
||||
}
|
||||
else { // args[1] is actor ID
|
||||
val av = Terrarum.game.getActor(args[1].toInt()).actorValue
|
||||
val keyset = av.keySet
|
||||
|
||||
echo.execute("== ActorValue list for ${args[1].toInt()} ==")
|
||||
if (keyset.size == 0)
|
||||
echo.execute("(nothing)")
|
||||
else
|
||||
keyset.forEach { elem -> echo.execute("$elem = ${av[elem as String]}") }
|
||||
}
|
||||
}
|
||||
else if (args.size == 3) {
|
||||
|
||||
val id = args[1].toInt()
|
||||
val av = args[2]
|
||||
echo.execute("$id.$av = " +
|
||||
Terrarum.game.getActor(id).actorValue[av] +
|
||||
" (" +
|
||||
Terrarum.game.getActor(id).actorValue[av]!!.javaClass.simpleName +
|
||||
")"
|
||||
)
|
||||
}
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
if (args.size == 2) {
|
||||
echo.execute(args[1] + ": actor value does not exist.")
|
||||
echo.error(args[1] + ": actor value does not exist.")
|
||||
}
|
||||
else if (args.size == 3) {
|
||||
echo.execute(args[2] + ": actor value does not exist.")
|
||||
echo.error(args[2] + ": actor value does not exist.")
|
||||
}
|
||||
else {
|
||||
throw NullPointerException()
|
||||
}
|
||||
}
|
||||
catch (e1: IllegalArgumentException) {
|
||||
if (args.size == 3) {
|
||||
echo.error(args[1] + ": no actor with this ID.")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun String.isNum(): Boolean {
|
||||
try {
|
||||
this.toInt()
|
||||
return true
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
val echo = Echo()
|
||||
echo.execute("Get desired actor value of specific target.")
|
||||
|
||||
@@ -19,43 +19,81 @@ internal class SetAV : ConsoleCommand {
|
||||
}
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
val echo = Echo()
|
||||
|
||||
// setav <id or "player"> <av> <val>
|
||||
if (args.size != 4 && args.size != 3) {
|
||||
printUsage()
|
||||
}
|
||||
else if (args.size == 3) {
|
||||
fun parseAVInput(arg: String): Any {
|
||||
val `val`: Any
|
||||
|
||||
try {
|
||||
`val` = Integer(args[2]) // try for integer
|
||||
`val` = Integer(arg) // try for integer
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
|
||||
try {
|
||||
`val` = args[2].toFloat() // try for float
|
||||
`val` = arg.toFloat() // try for float
|
||||
}
|
||||
catch (ee: NumberFormatException) {
|
||||
if (args[2].equals("__true", ignoreCase = true)) {
|
||||
if (arg.equals("__true", ignoreCase = true)) {
|
||||
`val` = true
|
||||
}
|
||||
else if (args[2].equals("__false", ignoreCase = true)) {
|
||||
else if (arg.equals("__false", ignoreCase = true)) {
|
||||
`val` = false
|
||||
}
|
||||
else {
|
||||
`val` = args[2] // string if not number
|
||||
`val` = arg // string if not number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return `val`
|
||||
}
|
||||
|
||||
val echo = Echo()
|
||||
|
||||
// setav <id, or blank for player> <av> <val>
|
||||
if (args.size != 4 && args.size != 3) {
|
||||
printUsage()
|
||||
}
|
||||
else if (args.size == 3) {
|
||||
val `val` = parseAVInput(args[2])
|
||||
|
||||
// check if av is number
|
||||
if (args[1].isNum()) {
|
||||
echo.error("Illegal ActorValue “${args[1]}”: ActorValue cannot be a number.")
|
||||
return
|
||||
}
|
||||
|
||||
Terrarum.game.player.actorValue[args[1]] = `val`
|
||||
echo.execute("Set " + args[1] + " to " + `val`)
|
||||
echo.execute("Set ${args[1]} to $`val`")
|
||||
}
|
||||
else if (args.size == 4) {
|
||||
try {
|
||||
val id = args[1].toInt()
|
||||
val `val` = parseAVInput(args[3])
|
||||
|
||||
// check if av is number
|
||||
if (args[2].isNum()) {
|
||||
echo.error("Illegal ActorValue “${args[2]}”: ActorValue cannot be a number.")
|
||||
return
|
||||
}
|
||||
|
||||
Terrarum.game.getActor(id).actorValue[args[2]] = `val`
|
||||
echo.execute("Set ${args[2]} of $id to $`val`")
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
if (args.size == 4)
|
||||
echo.error(args[1] + ": no actor with this ID.")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun String.isNum(): Boolean {
|
||||
try {
|
||||
this.toInt()
|
||||
return true
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user