still wip modularisation, game somehow boots

This commit is contained in:
minjaesong
2018-06-21 17:33:22 +09:00
parent f0a6f8b9c2
commit a6ea2b4e18
266 changed files with 2409 additions and 1122 deletions

View File

@@ -0,0 +1,50 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.debuggerapp.ActorValueTracker
import java.util.*
/**
* Created by minjaesong on 2016-12-29.
*/
internal object AVTracker : ConsoleCommand {
private val jPanelInstances = ArrayList<ActorValueTracker>()
override fun execute(args: Array<String>) {
if (args.size < 2) {
jPanelInstances.add(ActorValueTracker((Terrarum.ingame!! as Ingame).player))
}
else {
try {
val actorID = args[1].toInt()
if (Terrarum.ingame!!.theGameHasActor(actorID)) {
jPanelInstances.add(ActorValueTracker(Terrarum.ingame!!.getActorByID(actorID)))
}
else {
throw IllegalArgumentException()
}
}
catch (e: NumberFormatException) {
EchoError("Illegal actor ID input")
return
}
catch (e1: IllegalArgumentException) {
EchoError("No such actor with specified ID")
return
}
}
}
override fun printUsage() {
Echo("Pops up new window that provides real-time information about the actor's actor value")
}
fun update() {
jPanelInstances.forEach { it.update() }
}
}

View File

@@ -0,0 +1,30 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.debuggerapp.ActorsLister
import net.torvald.terrarum.modulebasegame.Ingame
import java.util.*
/**
* Created by minjaesong on 2016-12-29.
*/
internal object ActorsList : ConsoleCommand {
private val jPanelInstances = ArrayList<ActorsLister>()
override fun execute(args: Array<String>) {
jPanelInstances.add(ActorsLister(
(Terrarum.ingame!! as Ingame).actorContainer,
(Terrarum.ingame!! as Ingame).actorContainerInactive)
)
}
override fun printUsage() {
Echo("Pops up new window that displays the list of actors currently in the game")
}
fun update() {
jPanelInstances.forEach { it.update() }
}
}

View File

@@ -0,0 +1,32 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import java.io.IOException
import java.nio.file.FileSystems
import java.nio.file.Files
/**
* Created by minjaesong on 2016-02-10.
*/
internal object CatStdout : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 1) {
printUsage()
return
}
try {
Files.lines(FileSystems.getDefault().getPath(args[1])).forEach({ Echo(it) })
}
catch (e: IOException) {
Echo("CatStdout: could not read file -- IOException")
}
}
override fun printUsage() {
Echo("usage: cat 'path/to/text/file")
}
}

View File

@@ -0,0 +1,15 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.modulebasegame.Ingame
object CheatWarnTest : ConsoleCommand {
override fun execute(args: Array<String>) {
(Terrarum.ingame as? Ingame)?.uiCheatMotherfuckerNootNoot?.setAsOpen()
}
override fun printUsage() {
}
}

View File

@@ -0,0 +1,49 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.ccO
import net.torvald.terrarum.console.CommandDict
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.langpack.Lang
import java.util.Formatter
/**
* Created by minjaesong on 2016-01-16.
*/
internal object CodexEdictis : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 1) {
printList()
}
else {
try {
val commandObj = CommandDict[args[1].toLowerCase()]
commandObj.printUsage()
}
catch (e: NullPointerException) {
val sb = StringBuilder()
val formatter = Formatter(sb)
Echo("Codex: " + formatter.format(Lang["DEV_MESSAGE_CONSOLE_COMMAND_UNKNOWN"], args[1]).toString())
}
}
}
override fun printUsage() {
Echo("Usage: codex (command)")
Echo("shows how to use 'command'")
Echo("leave blank to get list of available commands")
}
private fun printList() {
Echo(Lang["DEV_MESSAGE_CONSOLE_AVAILABLE_COMMANDS"])
CommandDict.dict.forEach { name, cmd ->
Echo("$ccO" + name)
cmd.printUsage()
}
}
}

View File

@@ -0,0 +1,40 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.utils.JsonWriter
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
import java.io.IOException
/**
* Created by minjaesong on 2016-02-10.
*/
internal object ExportAV : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
try {
JsonWriter.writeToFile(
(Terrarum.ingame!! as Ingame).player.actorValue,
Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
Echo("ExportAV: exported to " + args[1] + ".json")
}
catch (e: IOException) {
Echo("ExportAV: IOException raised.")
e.printStackTrace()
}
}
else {
printUsage()
}
}
override fun printUsage() {
Echo("Export ActorValue as JSON format.")
Echo("Usage: exportav (id) filename-without-extension")
Echo("blank ID for player")
}
}

View File

@@ -0,0 +1,27 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.serialise.WriteLayerData
/**
* Created by minjaesong on 2017-07-18.
*/
object ExportLayerData : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size < 2) {
printUsage()
return
}
val saveDirectoryName = args[1]
WriteLayerData(saveDirectoryName)
Echo("Layer data exported to $saveDirectoryName/${WriteLayerData.META_FILENAME}")
}
override fun printUsage() {
Echo("Usage: exportlayer savename")
}
}

View File

@@ -0,0 +1,119 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.colourutil.Col4096
import net.torvald.terrarum.utils.RasterWriter
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame
import java.io.*
import java.util.HashMap
/**
* Created by minjaesong on 2016-01-17.
*/
internal object ExportMap : ConsoleCommand {
//private var mapData: ByteArray? = null
// private var mapDataPointer = 0
private val colorTable = HashMap<Int, Col4096>()
init {
colorTable.put(Block.AIR, Col4096(0xCEF))
colorTable.put(Block.STONE, Col4096(0x888))
colorTable.put(Block.DIRT, Col4096(0x753))
colorTable.put(Block.GRASS, Col4096(0x472))
colorTable.put(Block.ORE_COPPER, Col4096(0x6A8))
colorTable.put(Block.ORE_IRON, Col4096(0xC75))
colorTable.put(Block.ORE_GOLD, Col4096(0xA87))
colorTable.put(Block.ORE_ILMENITE, Col4096(0x8AB))
colorTable.put(Block.ORE_AURICHALCUM, Col4096(0xD92))
colorTable.put(Block.ORE_SILVER, Col4096(0xDDD))
colorTable.put(Block.RAW_DIAMOND, Col4096(0x2BF))
colorTable.put(Block.RAW_RUBY, Col4096(0xB10))
colorTable.put(Block.RAW_EMERALD, Col4096(0x0B1))
colorTable.put(Block.RAW_SAPPHIRE, Col4096(0x01B))
colorTable.put(Block.RAW_TOPAZ, Col4096(0xC70))
colorTable.put(Block.RAW_AMETHYST, Col4096(0x70C))
colorTable.put(Block.WATER, Col4096(0x038))
colorTable.put(Block.LAVA, Col4096(0xF50))
colorTable.put(Block.SAND, Col4096(0xDDB))
colorTable.put(Block.SAND_WHITE, Col4096(0xFFD))
colorTable.put(Block.SAND_RED, Col4096(0xA32))
colorTable.put(Block.SAND_DESERT, Col4096(0xEDB))
colorTable.put(Block.SAND_BLACK, Col4096(0x444))
colorTable.put(Block.SAND_GREEN, Col4096(0x9A6))
colorTable.put(Block.GRAVEL, Col4096(0x664))
colorTable.put(Block.GRAVEL_GREY, Col4096(0x999))
colorTable.put(Block.ICE_NATURAL, Col4096(0x9AB))
colorTable.put(Block.ICE_MAGICAL, Col4096(0x7AC))
colorTable.put(Block.ICE_FRAGILE, Col4096(0x6AF))
colorTable.put(Block.SNOW, Col4096(0xCDE))
}
override fun execute(args: Array<String>) {
val world = (Terrarum.ingame!! as Ingame).world
if (args.size == 2) {
var mapData = ByteArray(world.width * world.height * 3)
var mapDataPointer = 0
for (tile in world.terrainIterator()) {
val colArray = (colorTable as Map<Int, Col4096>)
.getOrElse(tile, { Col4096(0xFFF) }).toByteArray()
for (i in 0..2) {
mapData[mapDataPointer + i] = colArray[i]
}
mapDataPointer += 3
}
val dir = Terrarum.defaultDir + "/Exports/"
val dirAsFile = File(dir)
if (!dirAsFile.exists()) {
dirAsFile.mkdir()
}
try {
RasterWriter.writePNG_RGB(
world.width, world.height, mapData, dir + args[1] + ".png")
Echo("ExportMap: exported to " + args[1] + ".png")
}
catch (e: IOException) {
EchoError("ExportMap: IOException raised.")
e.printStackTrace()
}
// mapData = null
// mapDataPointer = 0
// Free up some memory
System.gc()
}
else {
printUsage()
}
}
override fun printUsage() {
Echo("Usage: export <name>")
Echo("Exports current map into echo image.")
Echo("The image can be found at %appdata%/terrarum/Exports")
}
}

View File

@@ -0,0 +1,18 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
/**
* Created by minjaesong on 2016-01-18.
*/
internal object ForceGC : ConsoleCommand {
override fun execute(args: Array<String>) {
System.gc()
Echo("Invoked System.gc")
}
override fun printUsage() {
Echo("Invoke garbage collection of JVM.")
}
}

View File

@@ -0,0 +1,120 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.*
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame
/**
* Created by minjaesong on 2016-01-19.
*/
internal object GetAV : ConsoleCommand {
override fun execute(args: Array<String>) {
try {
val ingame = Terrarum.ingame!! as Ingame
if (args.size == 1 && ingame.player != null) {
// print all actorvalue of player
val av = ingame.player.actorValue
val keyset = av.keySet
Echo("$ccW== ActorValue list for ${ccY}player $ccW==")
println("[GetAV] == ActorValue list for 'player' ==")
keyset.forEach { elem ->
Echo("$ccM$elem $ccW= $ccG${av[elem as String]}")
println("[GetAV] $elem = ${av[elem]}")
}
}
else if (args.size != 3 && args.size != 2) {
printUsage()
}
else if (args.size == 2) {
// check if args[1] is number or not
if (!args[1].isNum()) { // args[1] is ActorValue name
Echo("${ccW}player.$ccM${args[1]} $ccW= " +
ccG +
ingame.player.actorValue[args[1]] +
" $ccO" +
ingame.player.actorValue[args[1]]!!.javaClass.simpleName
)
println("[GetAV] player.${args[1]} = " +
ingame.player.actorValue[args[1]] +
" " +
ingame.player.actorValue[args[1]]!!.javaClass.simpleName
)
}
else {
// args[1] is actor ID
val actor = ingame.getActorByID(args[1].toInt())
val av = actor.actorValue
val keyset = av.keySet
Echo("$ccW== ActorValue list for $ccY$actor $ccW==")
println("[GetAV] == ActorValue list for '$actor' ==")
if (keyset.isEmpty()) {
Echo("$ccK(nothing)")
println("[GetAV] (nothing)")
}
else {
keyset.forEach { elem ->
Echo("$ccM$elem $ccW= $ccG${av[elem as String]}")
println("[GetAV] $elem = ${av[elem]}")
}
}
}
}
else if (args.size == 3) {
val id = args[1].toInt()
val av = args[2]
Echo("$ccW$id.$ccM$av $ccW= $ccG" +
ingame.getActorByID(id).actorValue[av] +
" $ccO" +
ingame.getActorByID(id).actorValue[av]!!.javaClass.simpleName
)
println("$id.$av = " +
ingame.getActorByID(id).actorValue[av] +
" " +
ingame.getActorByID(id).actorValue[av]!!.javaClass.simpleName
)
}
}
catch (e: NullPointerException) {
if (args.size == 2) {
EchoError(args[1] + ": actor value does not exist.")
System.err.println("[GetAV] ${args[1]}: actor value does not exist.")
}
else if (args.size == 3) {
EchoError(args[2] + ": actor value does not exist.")
System.err.println("[GetAV] ${args[2]}: actor value does not exist.")
}
else {
throw NullPointerException()
}
}
catch (e1: IllegalArgumentException) {
EchoError("${args[1]}: no actor with this ID.")
System.err.println("[GetAV] ${args[1]}: no actor with this ID.")
}
}
fun String.isNum(): Boolean {
try {
this.toInt()
return true
}
catch (e: NumberFormatException) {
return false
}
}
override fun printUsage() {
Echo("${ccW}Get desired ActorValue of specific target.")
Echo("${ccW}Usage: ${ccY}getav $ccG(id) <av>")
Echo("${ccW}blank ID for player")
}
}

View File

@@ -0,0 +1,120 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.gameactors.Factionable
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.Player
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
/**
* Created by minjaesong on 2016-02-17.
*/
internal object GetFactioning : ConsoleCommand {
val ccW = GameFontBase.toColorCode(0xFFFF)
val ccY = GameFontBase.toColorCode(0xFE8F)
val ccM = GameFontBase.toColorCode(0xEAFF)
val ccG = GameFontBase.toColorCode(0x8F8F)
val ccK = GameFontBase.toColorCode(0x888F)
private val PRINT_INDENTATION = "$ccK --> $ccW"
override fun execute(args: Array<String>) {
val error = Error()
fun printOutFactioning(id: Int) {
val a = Terrarum.ingame!!.getActorByID(id)
if (a is Factionable) {
Echo("$ccW== Faction assignment for $ccY${if (id == Player.PLAYER_REF_ID) "player" else id.toString()} $ccW==")
println("[GetFactioning] == Faction assignment for '${if (id == Player.PLAYER_REF_ID) "player" else id.toString()}' ==")
// get all factioning data of player
val factionSet = a.faction
if (factionSet.isEmpty()) {
Echo("The actor has empty faction set.")
println("[GetFactioning] The actor has empty faction set.")
return
}
val count = factionSet.size
Echo("$ccG${count.toString()} $ccW${Lang.pluralise(" faction", count)} assigned.")
println("[GetFactioning] ${count.toString()} ${Lang.pluralise(" faction", count)} assigned.")
for (faction in factionSet) {
Echo("${ccW}faction $ccM${faction.factionName}")
println("[GetFactioning] faction '${faction.factionName}'")
Echo("$ccY Amicable")
println("[GetFactioning] Amicable")
faction.factionAmicable.forEach { s ->
Echo(PRINT_INDENTATION + s)
println("[GetFactioning] --> $s")
}
Echo("$ccY Explicit neutral")
println("[GetFactioning] Explicit neutral")
faction.factionNeutral.forEach { s ->
Echo(PRINT_INDENTATION + s)
println("[GetFactioning] --> $s")
}
Echo("$ccY Hostile")
println("[GetFactioning] Hostile")
faction.factionHostile.forEach { s ->
Echo(PRINT_INDENTATION + s)
println("[GetFactioning] --> $s")
}
Echo("$ccY Fearful")
println("[GetFactioning] Fearful")
faction.factionFearful.forEach { s ->
Echo(PRINT_INDENTATION + s)
println("[GetFactioning] --> $s")
}
}
}
else {
EchoError("The actor is not factionable.")
System.err.println("[GetFactioning] The actor is not factionable.")
}
}
if (args.size == 1) {
printOutFactioning(Player.PLAYER_REF_ID)
}
else {
if (!args[1].isNum()) {
EchoError("Invalid actor ID input.")
System.err.println("[GetFactioning] Invalid actor ID input.")
return
}
try {
val actorID = args[1].toInt()
printOutFactioning(actorID)
}
catch (e: IllegalArgumentException) {
EchoError("${args[1]}: no actor with this ID.")
System.err.println("[GetFactioning] ${args[1]}: no actor with this ID.")
}
}
}
fun String.isNum(): Boolean {
try {
this.toInt()
return true
}
catch (e: NumberFormatException) {
return false
}
}
override fun printUsage() {
}
}

View File

@@ -0,0 +1,25 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.langpack.Lang
/**
* Created by minjaesong on 2016-01-22.
*/
internal object GetLocale : ConsoleCommand {
override fun execute(args: Array<String>) {
Echo(
"Locale: "
+ Lang["MENU_LANGUAGE_THIS"]
+ " ("
+ Lang["MENU_LANGUAGE_THIS_EN"]
+ ")")
}
override fun printUsage() {
Echo("Usage: getlocale")
Echo("Get name of locale currently using.")
}
}

View File

@@ -0,0 +1,21 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
/**
* Created by minjaesong on 2016-03-20.
*/
internal object GetTime : ConsoleCommand {
override fun execute(args: Array<String>) {
val worldTime = (Terrarum.ingame!! as Ingame).world.time
Echo(worldTime.getFormattedTime())
}
override fun printUsage() {
Echo("Print current world time in convenient form")
}
}

View File

@@ -0,0 +1,49 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import com.google.gson.Gson
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
import java.io.BufferedWriter
import java.io.FileWriter
import java.io.IOException
/**
* Created by minjaesong on 2016-02-10.
*/
internal object GsonTest : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
val avelem = Gson().toJsonTree((Terrarum.ingame!! as Ingame).player)
val jsonString = avelem.toString()
val bufferedWriter: BufferedWriter
val writer: FileWriter
try {
writer = FileWriter(Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
bufferedWriter = BufferedWriter(writer)
bufferedWriter.write(jsonString)
bufferedWriter.close()
Echo("GsonTest: exported to " + args[1] + ".json")
}
catch (e: IOException) {
Echo("GsonTest: IOException raised.")
e.printStackTrace()
}
}
else {
printUsage()
}
}
override fun printUsage() {
Echo("Usage: gsontest filename-without-extension")
}
}

View File

@@ -0,0 +1,27 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.langpack.Lang
/**
* Created by minjaesong on 2016-03-22.
*/
internal object Help : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 1) {
for (i in 1..6) Echo(Lang["HELP_OTF_MAIN_$i"])
}
else if (args[1].toLowerCase() == "slow") {
for (i in 1..4) Echo(Lang["HELP_OTF_SLOW_$i"])
}
else {
for (i in 1..6) Echo(Lang["HELP_OTF_MAIN_$i"])
}
}
override fun printUsage() {
Echo("Prints some utility functions assigned to function row of the keyboard.")
}
}

View File

@@ -0,0 +1,35 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.serialise.ReadLayerData
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import java.io.FileInputStream
/**
* Created by minjaesong on 2017-07-18.
*/
object ImportLayerData : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size < 2) {
ExportLayerData.printUsage()
return
}
//val fis = GZIPInputStream(FileInputStream(args[1])) // this gzip is kaput
val fis = FileInputStream(args[1])
(Terrarum.ingame!! as Ingame).world = ReadLayerData(fis)
(Terrarum.ingame!! as Ingame).player.setPosition(
(Terrarum.ingame!! as Ingame).world.spawnY * FeaturesDrawer.TILE_SIZE.toDouble(),
(Terrarum.ingame!! as Ingame).world.spawnX * FeaturesDrawer.TILE_SIZE.toDouble()
)
fis.close()
Echo("Successfully loaded ${args[1]}")
}
override fun printUsage() {
Echo("Usage: importlayer path/to/layer.data")
}
}

View File

@@ -0,0 +1,79 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.gameactors.Player
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame
/**
* Created by minjaesong on 2016-12-12.
*/
internal object Inventory : ConsoleCommand {
private var target: Pocketed? = (Terrarum.ingame!! as Ingame).player
override fun execute(args: Array<String>) {
if (args.size == 1) {
printUsage()
}
else {
when (args[1]) {
"list" -> listInventory()
"add" -> if (args.size > 3) addItem(args[2].toInt(), args[3].toInt())
else addItem(args[2].toInt())
"target" -> setTarget(args[2].toInt())
"equip" -> equipItem(args[2].toInt())
else -> printUsage()
}
}
}
private fun listInventory() {
if (target != null) {
if (target!!.inventory.getTotalUniqueCount() == 0) {
Echo("(inventory empty)")
}
else {
target!!.inventory.forEach { val (item, amount) = it
if (amount == 0) {
EchoError("Unexpected zero-amounted item: ID ${item.dynamicID}")
}
Echo("ID $item${if (amount > 1) " ($amount)" else ""}")
}
}
}
}
private fun setTarget(actorRefId: Int = Player.PLAYER_REF_ID) {
val actor = Terrarum.ingame!!.getActorByID(actorRefId)
if (actor !is Pocketed) {
EchoError("Cannot edit inventory of incompatible actor: $actor")
}
else {
target = actor
}
}
private fun addItem(refId: Int, amount: Int = 1) {
if (target != null) {
target!!.addItem(ItemCodex[refId], amount)
}
}
private fun equipItem(refId: Int) {
if (target != null) {
val item = ItemCodex[refId]
target!!.equipItem(item)
}
}
override fun printUsage() {
Echo("Usage: inventory command arguments")
Echo("Available commands:")
Echo("list | assign slot | add itemid [amount] | target [actorid] | equip itemid")
}
}

View File

@@ -0,0 +1,23 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.swingapp.IMStringReader
/**
* Created by minjaesong on 2017-02-05.
*/
internal object JavaIMTest : ConsoleCommand {
override fun execute(args: Array<String>) {
IMStringReader(
{ Echo("[JavaIMTest -> IMStringReader] $it") }, // send input to Echo
"JavaIMTest"
)
}
override fun printUsage() {
Echo("Tests Swing input window to get non-English text input")
}
}

View File

@@ -0,0 +1,34 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.langpack.Lang
/**
* Created by minjaesong on 2017-01-31.
*/
internal object KillActor : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
try {
val actorid = args[1].toInt()
Terrarum.ingame!!.removeActor(actorid)
}
catch (e: NumberFormatException) {
EchoError("Wrong number input.")
}
catch (e1: RuntimeException) {
EchoError(e1.message ?: Lang["ERROR_GENERIC_TEXT"])
}
}
else {
printUsage()
}
}
override fun printUsage() {
Echo("Usage: kill actorid")
}
}

View File

@@ -0,0 +1,21 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.langpack.Lang
/**
* Created by minjaesong on 2016-07-11.
*/
internal object LangTest : ConsoleCommand {
override fun printUsage() {
Echo("Prints out string in the current lang pack by STRING_ID provided")
}
override fun execute(args: Array<String>) {
if (args.size < 2)
printUsage()
else
Echo(Lang[args[1].toUpperCase()])
}
}

View File

@@ -0,0 +1,20 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.random.HQRNG
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
object MoneyDisp : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
Echo("¤${0x3000.toChar()}${args[1]}")
}
else {
Echo("¤${0x3000.toChar()}${HQRNG().nextInt(100000)}")
}
}
override fun printUsage() {
Echo("Usage: money [amount] — Prints given or random amount of money")
}
}

View File

@@ -0,0 +1,46 @@
package net.torvald.terrarum.modulebasegame.console
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.audio.Music
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
/**
* Created by minjaesong on 2016-08-02.
*/
internal object MusicTest : ConsoleCommand {
var music: Music? = null
/**
* Args 0: command given
* Args 1: first argument
*
* e.g. in ```setav mass 74```, zeroth args will be ```setav```.
*/
override fun execute(args: Array<String>) {
if (args.size < 2) {
printUsage()
return
}
if (args[1] == "stop") {
music!!.stop()
return
}
val type = args[1].substringAfter('.').toUpperCase()
/*AudioLoader.getStreamingAudio(
type,
File("./assets/sounds/test/${args[1]}").absoluteFile.toURI().toURL()
).playAsMusic(1f, 1f, false)*/
music = Gdx.audio.newMusic(Gdx.files.internal("./assets/sounds/test/${args[1]}"))
music!!.play()
}
override fun printUsage() {
Echo("Usage: musictest filename/in/res/sounds/test")
Echo("musictest stop to stop playback")
}
}

View File

@@ -0,0 +1,18 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
/**
* Created by minjaesong on 2016-07-04.
*/
internal object PrintRandomTips : ConsoleCommand {
override fun execute(args: Array<String>) {
Echo("Nope.")
//Echo(Lang["GAME_TIPS_${Random().nextInt(Lang.TIPS_COUNT) + 1}"])
}
override fun printUsage() {
Echo("Prints random tips for game.")
}
}

View File

@@ -0,0 +1,23 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.*
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
/**
* Created by minjaesong on 2016-06-16.
*/
internal object Seed : ConsoleCommand {
override fun execute(args: Array<String>) {
Echo("Map$ccW: $ccG${(Terrarum.ingame!! as Ingame).world.generatorSeed}")
println("[seed] Map$ccW: $ccG${(Terrarum.ingame!! as Ingame).world.generatorSeed}")
// TODO display randomiser seed
}
override fun printUsage() {
Echo("prints out the generator seed of the current game.")
}
}

View File

@@ -0,0 +1,106 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.*
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame
/**
* Created by minjaesong on 2016-01-15.
*/
internal object SetAV : ConsoleCommand {
override fun printUsage() {
Echo("${ccW}Set actor value of specific target to desired value.")
Echo("${ccW}Usage: ${ccY}setav ${ccG}(id) <av> <val>")
Echo("${ccW}blank ID for player. Data type will be inferred automatically.")
Echo("${ccR}Contaminated (e.g. double -> string) ActorValue will crash the game,")
Echo("${ccR}so make sure it will not happen before you issue the command!")
Echo("${ccW}Use ${ccG}__true ${ccW}and ${ccG}__false ${ccW}for boolean value.")
}
override fun execute(args: Array<String>) {
fun parseAVInput(arg: String): Any {
var inputval: Any
try {
inputval = Integer(arg) // try for integer
}
catch (e: NumberFormatException) {
try {
inputval = arg.toDouble() // try for double
}
catch (ee: NumberFormatException) {
if (arg.equals("__true", ignoreCase = true)) {
inputval = true
}
else if (arg.equals("__false", ignoreCase = true)) {
inputval = false
}
else {
inputval = arg // string if not number
}
}
}
return inputval
}
// setav <id, or blank for player> <av> <val>
if (args.size != 4 && args.size != 3) {
printUsage()
}
else if (args.size == 3) {
val newValue = parseAVInput(args[2])
// check if av is number
if (args[1].isNum()) {
EchoError("Illegal ActorValue ${args[1]}: ActorValue cannot be a number.")
System.err.println("[SetAV] Illegal ActorValue ${args[1]}: ActorValue cannot be a number.")
return
}
(Terrarum.ingame!! as Ingame).player.actorValue[args[1]] = newValue
Echo("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$newValue")
println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.")
}
else if (args.size == 4) {
try {
val id = args[1].toInt()
val newValue = parseAVInput(args[3])
val actor = Terrarum.ingame!!.getActorByID(id)
// check if av is number
if (args[2].isNum()) {
EchoError("Illegal ActorValue ${args[2]}: ActorValue cannot be a number.")
System.err.println("[SetAV] Illegal ActorValue ${args[2]}: ActorValue cannot be a number.")
return
}
actor.actorValue[args[2]] = newValue
Echo("${ccW}Set $ccM${args[2]} ${ccW}for $ccY$id ${ccW}to $ccG$newValue")
println("[SetAV] set ActorValue '${args[2]}' for $actor to '$newValue'.")
}
catch (e: IllegalArgumentException) {
if (args.size == 4) {
EchoError("${args[1]}: no actor with this ID.")
System.err.println("[SetAV] ${args[1]}: no actor with this ID.")
}
}
}
}
fun String.isNum(): Boolean {
try {
this.toInt()
return true
}
catch (e: NumberFormatException) {
return false
}
}
}

View File

@@ -0,0 +1,32 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.modulebasegame.Ingame
/**
* Created by minjaesong on 2016-01-23.
*/
internal object SetBulletin : ConsoleCommand {
override fun execute(args: Array<String>) {
val testMsg = arrayOf(
Lang["ERROR_SAVE_CORRUPTED"],
Lang["MENU_LABEL_CONTINUE_QUESTION"]
)
send(testMsg)
}
override fun printUsage() {
}
/**
* Actually send notifinator
* @param message real message
*/
fun send(message: Array<String>) {
(Terrarum.ingame!! as Ingame).sendNotification(message)
println("sent notifinator")
}
}

View File

@@ -0,0 +1,39 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
/**
* Created by minjaesong on 2017-01-20.
*/
internal object SetScale : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2 || args.size == 3) {
try {
val targetID = if (args.size == 3) args[1].toInt() else (Terrarum.ingame!! as Ingame).player.referenceID
val scale = args[if (args.size == 3) 2 else 1].toDouble()
val target = Terrarum.ingame!!.getActorByID(targetID!!)
if (target !is ActorWithPhysics) {
EchoError("Target is not ActorWithPhysics")
}
else {
target.scale = scale
}
}
catch (e: NumberFormatException) {
EchoError("Wrong number input")
}
}
else printUsage()
}
override fun printUsage() {
Echo("Usage: setscale scale | setscale actorID scale")
}
}

View File

@@ -0,0 +1,37 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
/**
* Created by minjaesong on 2016-03-20.
*/
internal object SetTime : ConsoleCommand {
override fun execute(args: Array<String>) {
val world = (Terrarum.ingame!! as Ingame).world
if (args.size == 2) {
val timeToSet = WorldTime.parseTime(args[1])
world.time.setTimeOfToday(timeToSet)
Echo("Set time to ${world.time.todaySeconds} " +
"(${world.time.hours}h${formatMin(world.time.minutes)})")
}
else {
printUsage()
}
}
private fun formatMin(min: Int): String {
return if (min < 10) "0${min.toString()}" else min.toString()
}
override fun printUsage() {
Echo("usage: settime <39201-in sec or 13h32-in hour>")
}
}

View File

@@ -0,0 +1,34 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
/**
* Created by minjaesong on 2016-03-20.
*/
internal object SetTimeDelta : ConsoleCommand {
val HARD_LIMIT = 60
override fun execute(args: Array<String>) {
val world = (Terrarum.ingame!! as Ingame).world
if (args.size == 2) {
world.time.timeDelta = args[1].toInt()
if (world.time.timeDelta == 0)
Echo("時間よ止まれ!ザ・ワルド!!")
else
Echo("Set time delta to ${world.time.timeDelta}")
}
else {
printUsage()
}
}
override fun printUsage() {
Echo("usage: settimedelta <int>")
}
}

View File

@@ -0,0 +1,52 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.modulebasegame.gameactors.PhysTestBall
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
import org.dyn4j.geometry.Vector2
/**
* Created by minjaesong on 2016-03-05.
*/
internal object SpawnPhysTestBall : ConsoleCommand {
@Throws(Exception::class)
override fun execute(args: Array<String>) {
val world = (Terrarum.ingame!! as Ingame).world
val mouseX = Terrarum.mouseX
val mouseY = Terrarum.mouseY
if (args.size >= 3) {
val elasticity = args[1].toDouble()
val xvel = args[2].toDouble()
val yvel = if (args.size >= 4) args[3].toDouble() else 0.0
val ball = PhysTestBall(world)
ball.setPosition(mouseX, mouseY)
ball.elasticity = elasticity
ball.applyForce(Vector2(xvel, yvel))
Terrarum.ingame!!.addNewActor(ball)
}
else if (args.size == 2) {
val elasticity = args[1].toDouble()
val ball = PhysTestBall(world)
ball.setPosition(mouseX, mouseY)
ball.elasticity = elasticity
Terrarum.ingame!!.addNewActor(ball)
}
else {
printUsage()
}
}
override fun printUsage() {
Echo("usage: spawnball elasticity [x velocity] [y velocity]")
}
}

View File

@@ -0,0 +1,26 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.PhysTestLuarLander
/**
* Created by minjaesong on 2018-01-18.
*/
internal object SpawnPhysTestLunarLander : ConsoleCommand {
override fun execute(args: Array<String>) {
val mouseX = Terrarum.mouseX
val mouseY = Terrarum.mouseY
val lander = PhysTestLuarLander((Terrarum.ingame!! as Ingame).world)
lander.setPosition(mouseX, mouseY)
Terrarum.ingame!!.addNewActor(lander)
}
override fun printUsage() {
Echo("control it with arrow keys")
}
}

View File

@@ -0,0 +1,26 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.gameactors.DecodeTapestry
import java.io.File
/**
* Created by minjaesong on 2017-01-14.
*/
internal object SpawnTapestry : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size < 2) {
printUsage()
return
}
val tapestry = DecodeTapestry(File(args[1]))
Terrarum.ingame!!.addNewActor(tapestry)
}
override fun printUsage() {
Echo("Usage: spawntapestry <tapestry_file>")
}
}

View File

@@ -0,0 +1,23 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
/**
* Created by minjaesong on 2016-12-17.
*/
internal object SpawnTikiTorch : ConsoleCommand {
override fun execute(args: Array<String>) {
val torch = FixtureTikiTorch((Terrarum.ingame!! as Ingame).world)
torch.setPosition(Terrarum.mouseX, Terrarum.mouseY)
Terrarum.ingame!!.addNewActor(torch)
}
override fun printUsage() {
Echo("Usage: spawntorch")
}
}

View File

@@ -0,0 +1,115 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
/**
* Created by minjaesong on 2016-01-24.
*/
internal object Teleport : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 3) {
val x: Int
val y: Int
try {
x = args[1].toInt() * FeaturesDrawer.TILE_SIZE + FeaturesDrawer.TILE_SIZE / 2
y = args[2].toInt() * FeaturesDrawer.TILE_SIZE + FeaturesDrawer.TILE_SIZE / 2
}
catch (e: NumberFormatException) {
EchoError("Teleport: wrong number input.")
return
}
(Terrarum.ingame!! as Ingame).player.setPosition(x.toDouble(), y.toDouble())
}
else if (args.size == 4) {
if (args[2].toLowerCase() != "to") {
EchoError("missing 'to' on teleport command")
return
}
val fromActor: ActorWithPhysics
val targetActor: ActorWithPhysics
try {
val fromActorID = args[1].toInt()
val targetActorID = if (args[3].toLowerCase() == "player")
(Terrarum.ingame!! as Ingame).player.referenceID!!
else
args[3].toInt()
// if from == target, ignore the action
if (fromActorID == targetActorID) return
if (Terrarum.ingame!!.getActorByID(fromActorID) !is ActorWithPhysics ||
Terrarum.ingame!!.getActorByID(targetActorID) !is ActorWithPhysics) {
throw IllegalArgumentException()
}
else {
fromActor = Terrarum.ingame!!.getActorByID(fromActorID) as ActorWithPhysics
targetActor = Terrarum.ingame!!.getActorByID(targetActorID) as ActorWithPhysics
}
}
catch (e: NumberFormatException) {
EchoError("Teleport: illegal number input")
return
}
catch (e1: IllegalArgumentException) {
EchoError("Teleport: operation not possible on specified actor(s)")
return
}
fromActor.setPosition(
targetActor.feetPosVector.x,
targetActor.feetPosVector.y
)
}
else if (args.size == 5) {
if (args[2].toLowerCase() != "to") {
EchoError("missing 'to' on teleport command")
return
}
val actor: ActorWithPhysics
val x: Int
val y: Int
try {
x = args[3].toInt() * FeaturesDrawer.TILE_SIZE + FeaturesDrawer.TILE_SIZE / 2
y = args[4].toInt() * FeaturesDrawer.TILE_SIZE + FeaturesDrawer.TILE_SIZE / 2
val actorID = args[1].toInt()
if (Terrarum.ingame!!.getActorByID(actorID) !is ActorWithPhysics) {
throw IllegalArgumentException()
}
else {
actor = Terrarum.ingame!!.getActorByID(actorID) as ActorWithPhysics
}
}
catch (e: NumberFormatException) {
EchoError("Teleport: illegal number input")
return
}
catch (e1: IllegalArgumentException) {
EchoError("Teleport: operation not possible on specified actor")
return
}
actor.setPosition(x.toDouble(), y.toDouble())
}
else {
printUsage()
}
}
override fun printUsage() {
Echo("Usage: teleport x-tile y-tile")
Echo(" teleport actorid to x-tile y-tile")
Echo(" teleport actorid to actorid")
Echo(" teleport actorid to player")
}
}

View File

@@ -0,0 +1,22 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
/**
* Created by minjaesong on 2016-01-19.
*/
internal object ToggleNoClip : ConsoleCommand {
override fun execute(args: Array<String>) {
val status = (Terrarum.ingame!! as Ingame).player.isNoClip()
(Terrarum.ingame!! as Ingame).player.setNoClip(!status)
Echo("Set no-clip status to " + (!status).toString())
}
override fun printUsage() {
Echo("toggle no-clip status of player")
}
}

View File

@@ -0,0 +1,44 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
/**
* Created by minjaesong on 2016-01-25.
*/
internal object Zoom : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
var zoom: Float
try {
zoom = args[1].toFloat()
}
catch (e: NumberFormatException) {
Echo("Wrong number input.")
return
}
if (zoom < Terrarum.ingame!!.ZOOM_MINIMUM) {
zoom = Terrarum.ingame!!.ZOOM_MINIMUM
}
else if (zoom > Terrarum.ingame!!.ZOOM_MAXIMUM) {
zoom = Terrarum.ingame!!.ZOOM_MAXIMUM
}
Terrarum.ingame!!.screenZoom = zoom
System.gc()
Echo("Set screen zoom to " + zoom.toString())
}
else {
printUsage()
}
}
override fun printUsage() {
Echo("Usage: zoom [zoom]")
}
}