new console command 'error' (stderr equivalent of console window)

Former-commit-id: ab54663fd64f9ae9c758f53b3f5800a5894f0db3
Former-commit-id: 7aba1585ffa45195622bb25e1c62cace474420c9
This commit is contained in:
Song Minjae
2016-04-25 12:49:56 +09:00
parent 1dc3e6df3e
commit 519ecec774
19 changed files with 93 additions and 58 deletions

View File

@@ -19,6 +19,6 @@ class Batch : ConsoleCommand {
}
override fun printUsage() {
Echo().execute("batch path/to/batch.txt")
Echo().execute("Usage: batch path/to/batch.txt")
}
}

View File

@@ -11,6 +11,7 @@ object CommandDict {
internal var dict: HashMap<String, ConsoleCommand> = hashMapOf(
Pair("echo", Echo()),
Pair("error", Error()),
Pair("setav", SetAV()),
Pair("qqq", QuitApp()),
Pair("codex", CodexEdictis()),

View File

@@ -25,6 +25,7 @@ object CommandInterpreter {
fun execute(command: String) {
val cmd: Array<CommandInput?> = parse(command)
val echo = Echo()
val error = Error()
for (single_command in cmd) {
var commandObj: ConsoleCommand? = null
@@ -61,7 +62,7 @@ object CommandInterpreter {
catch (e: Exception) {
System.err.print("[CommandInterpreter] ")
e.printStackTrace()
echo.error(Lang["ERROR_GENERIC_TEXT"])
error.execute(Lang["ERROR_GENERIC_TEXT"])
}
}
@@ -103,7 +104,7 @@ object CommandInterpreter {
val sb = StringBuilder()
val formatter = Formatter(sb)
Echo().error(
Error().execute(
formatter.format(Lang["DEV_MESSAGE_CONSOLE_COMMAND_UNKNOWN"], cmdname).toString())
}

View File

@@ -12,19 +12,13 @@ import java.util.Arrays
internal class Echo : ConsoleCommand {
override fun execute(args: Array<String>) {
val argsWoHeader = Array<String>(args.size - 1, {it -> args[it + 1]})
argsWoHeader.forEach(
{ (Terrarum.game.consoleHandler.UI as ConsoleWindow).sendMessage(it) })
argsWoHeader.forEach { execute(it) }
}
fun execute(single_line: String) {
(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() {
}

View File

@@ -0,0 +1,23 @@
package net.torvald.terrarum.console
import net.torvald.imagefont.GameFontBase
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.ui.ConsoleWindow
/**
* Created by minjaesong on 16-04-25.
*/
class Error : ConsoleCommand {
override fun execute(args: Array<String>) {
val argsWoHeader = Array<String>(args.size - 1, {it -> args[it + 1]})
argsWoHeader.forEach { execute(it) }
}
fun execute(single_line: String) {
(Terrarum.game.consoleHandler.UI as ConsoleWindow).sendMessage("${GameFontBase.colToCode["r"]}$single_line")
}
override fun printUsage() {
}
}

View File

@@ -18,6 +18,7 @@ class GetAV : ConsoleCommand {
override fun execute(args: Array<String>) {
val echo = Echo()
val error = Error()
try {
if (args.size == 1) {
@@ -87,11 +88,11 @@ class GetAV : ConsoleCommand {
}
catch (e: NullPointerException) {
if (args.size == 2) {
echo.error(args[1] + ": actor value does not exist.")
error.execute(args[1] + ": actor value does not exist.")
System.err.println("[GetAV] ${args[1]}: actor value does not exist.")
}
else if (args.size == 3) {
echo.error(args[2] + ": actor value does not exist.")
error.execute(args[2] + ": actor value does not exist.")
System.err.println("[GetAV] ${args[2]}: actor value does not exist.")
}
else {
@@ -99,7 +100,7 @@ class GetAV : ConsoleCommand {
}
}
catch (e1: IllegalArgumentException) {
echo.error("${args[1]}: no actor with this ID.")
error.execute("${args[1]}: no actor with this ID.")
System.err.println("[GetAV] ${args[1]}: no actor with this ID.")
}

View File

@@ -22,6 +22,7 @@ class GetFactioning : ConsoleCommand {
override fun execute(args: Array<String>) {
val echo = Echo()
val error = Error()
fun printOutFactioning(id: Int) {
val a = Terrarum.game.getActorByID(id)
@@ -75,7 +76,7 @@ class GetFactioning : ConsoleCommand {
}
}
else {
echo.error("The actor is not factionable.")
error.execute("The actor is not factionable.")
System.err.println("[GetFactioning] The actor is not factionable.")
}
}
@@ -85,7 +86,7 @@ class GetFactioning : ConsoleCommand {
}
else {
if (!args[1].isNum()) {
echo.error("Invalid actor ID input.")
error.execute("Invalid actor ID input.")
System.err.println("[GetFactioning] Invalid actor ID input.")
return
}
@@ -94,7 +95,7 @@ class GetFactioning : ConsoleCommand {
printOutFactioning(actorID)
}
catch (e: IllegalArgumentException) {
echo.error("${args[1]}: no actor with this ID.")
error.execute("${args[1]}: no actor with this ID.")
System.err.println("[GetFactioning] ${args[1]}: no actor with this ID.")
}
}

View File

@@ -54,6 +54,7 @@ internal class SetAV : ConsoleCommand {
}
val echo = Echo()
val error = Error()
// setav <id, or blank for player> <av> <val>
if (args.size != 4 && args.size != 3) {
@@ -64,7 +65,7 @@ internal class SetAV : ConsoleCommand {
// check if av is number
if (args[1].isNum()) {
echo.error("Illegal ActorValue ${args[1]}: ActorValue cannot be a number.")
error.execute("Illegal ActorValue ${args[1]}: ActorValue cannot be a number.")
System.err.println("[SetAV] Illegal ActorValue ${args[1]}: ActorValue cannot be a number.")
return
}
@@ -81,7 +82,7 @@ internal class SetAV : ConsoleCommand {
// check if av is number
if (args[2].isNum()) {
echo.error("Illegal ActorValue ${args[2]}: ActorValue cannot be a number.")
error.execute("Illegal ActorValue ${args[2]}: ActorValue cannot be a number.")
System.err.println("[SetAV] Illegal ActorValue ${args[2]}: ActorValue cannot be a number.")
return
}
@@ -92,7 +93,7 @@ internal class SetAV : ConsoleCommand {
}
catch (e: IllegalArgumentException) {
if (args.size == 4) {
echo.error("${args[1]}: no actor with this ID.")
error.execute("${args[1]}: no actor with this ID.")
System.err.println("[SetAV] ${args[1]}: no actor with this ID.")
}
}

View File

@@ -9,18 +9,7 @@ import net.torvald.terrarum.Terrarum
class SetTime : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
val lowercaseTime = args[1].toLowerCase()
val timeToSet =
if (args[1].length >= 4) {
lowercaseTime.substringBefore('h').toInt() * WorldTime.HOUR_SEC +
lowercaseTime.substringAfter('h').toInt() * WorldTime.MINUTE_SEC
}
else if (args[1].endsWith("h", true)) {
lowercaseTime.substring(0, args[1].length - 1).toInt() * WorldTime.HOUR_SEC
}
else {
lowercaseTime.toInt()
}
val timeToSet = WorldTime.parseTime(args[1])
Terrarum.game.map.worldTime.setTime(timeToSet)

View File

@@ -6,8 +6,14 @@ import net.torvald.terrarum.Terrarum
* Created by minjaesong on 16-03-20.
*/
class SetTimeDelta : ConsoleCommand {
val HARD_LIMIT = 60
override fun execute(args: Array<String>) {
if (args.size == 2) {
if (args[1].toInt() > HARD_LIMIT)
Error().execute("Delta too large -- acceptable delta is 0-60.")
Terrarum.game.map.worldTime.setTimeDelta(args[1].toInt())
if (Terrarum.game.map.worldTime.timeDelta == 0)
Echo().execute("時間よ止まれ!ザ・ワルド!!")