in preparation of new demoworld creation for future version

This commit is contained in:
minjaesong
2023-10-04 17:34:16 +09:00
parent ad0c1d72f3
commit 652dfe39eb
9 changed files with 76 additions and 12 deletions

View File

@@ -0,0 +1,45 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.App
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.gameworld.SimpleGameWorld
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.serialise.WriteSimpleWorld
import java.io.File
import java.io.IOException
/**
* Used to create the titlescreen world
*
* Created by minjaesong on 2023-10-04.
*/
object ExportWorld : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
try {
val ingame = Terrarum.ingame!! as TerrarumIngame
val file = File(App.defaultDir + "/Exports/${args[1]}.json")
val simpleworld = SimpleGameWorld(ingame.world.width, ingame.world.height).also {
it.layerTerrain = ingame.world.layerTerrain
it.layerWall = ingame.world.layerWall
it.tileNumberToNameMap.putAll(ingame.world.tileNumberToNameMap)
}
file.writeText(WriteSimpleWorld(ingame, simpleworld, listOf()))
Echo("Exportworld: exported the world as ${args[1]}.json")
}
catch (e: IOException) {
Echo("Exportworld: IOException raised.")
e.printStackTrace()
}
}
else {
printUsage()
}
}
override fun printUsage() {
Echo("Usage: exportworld filename-without-extension")
}
}

View File

@@ -10,6 +10,8 @@ import java.io.File
import java.io.IOException
/**
* Used to debug the titlescreen world
*
* Created by minjaesong on 2021-08-25.
*/
object ImportWorld : ConsoleCommand {