mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 01:54:04 +09:00
loading player from json file
This commit is contained in:
@@ -6,6 +6,7 @@ import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
|
||||
import net.torvald.terrarum.serialise.WriteActor
|
||||
import net.torvald.terrarum.serialise.WriteMeta
|
||||
import net.torvald.terrarum.serialise.WriteWorld
|
||||
@@ -40,10 +41,10 @@ object ExportWorld : ConsoleCommand {
|
||||
if (args.size == 2) {
|
||||
try {
|
||||
val str = WriteWorld(Terrarum.ingame!! as TerrarumIngame).invoke()
|
||||
val writer = java.io.FileWriter(AppLoader.defaultDir + "/Exports/${args[1]}", false)
|
||||
val writer = java.io.FileWriter(AppLoader.defaultDir + "/Exports/${args[1]}.json", false)
|
||||
writer.write(str)
|
||||
writer.close()
|
||||
Echo("Exportworld: exported to ${args[1]}")
|
||||
Echo("Exportworld: exported to ${args[1]}.json")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
Echo("Exportworld: IOException raised.")
|
||||
@@ -56,7 +57,7 @@ object ExportWorld : ConsoleCommand {
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Usage: Exportworld filename.json")
|
||||
Echo("Usage: Exportworld filename-without-extension")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +68,7 @@ object ExportActor : ConsoleCommand {
|
||||
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
|
||||
if (player == null) return
|
||||
|
||||
val str = WriteActor(player)
|
||||
val str = WriteActor(player as IngamePlayer)
|
||||
val writer = java.io.FileWriter(AppLoader.defaultDir + "/Exports/${args[1]}.json", false)
|
||||
writer.write(str)
|
||||
writer.close()
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.serialise.ReadActor
|
||||
import net.torvald.terrarum.serialise.ReadWorld
|
||||
import net.torvald.terrarum.serialise.WriteMeta
|
||||
import java.io.IOException
|
||||
@@ -16,9 +17,9 @@ object ImportWorld : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
try {
|
||||
val reader = java.io.FileReader(AppLoader.defaultDir + "/Exports/${args[1]}")
|
||||
val reader = java.io.FileReader(AppLoader.defaultDir + "/Exports/${args[1]}.json")
|
||||
ReadWorld(Terrarum.ingame!! as TerrarumIngame).invoke(reader)
|
||||
Echo("Importworld: imported a world from ${args[1]}")
|
||||
Echo("Importworld: imported a world from ${args[1]}.json")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
Echo("Importworld: IOException raised.")
|
||||
@@ -31,6 +32,29 @@ object ImportWorld : ConsoleCommand {
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Usage: Importworld filename.json")
|
||||
Echo("Usage: Importworld filename-without-extension")
|
||||
}
|
||||
}
|
||||
|
||||
object ImportActor : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
try {
|
||||
val reader = java.io.FileReader(AppLoader.defaultDir + "/Exports/${args[1]}.json")
|
||||
ReadActor(Terrarum.ingame!! as TerrarumIngame).invoke(reader)
|
||||
Echo("Importactor: imported an actor from ${args[1]}.json")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
Echo("Importactor: IOException raised.")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Usage: Importactor filename-without-extension")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user