mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
fixed a bug where the app would not generate correct config if there is no existing config
This commit is contained in:
@@ -30,9 +30,9 @@ import net.torvald.terrarum.langpack.Lang;
|
||||
import net.torvald.terrarum.modulebasegame.IngameRenderer;
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame;
|
||||
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory;
|
||||
import net.torvald.terrarum.serialise.WriteConfig;
|
||||
import net.torvald.terrarum.tvda.VirtualDisk;
|
||||
import net.torvald.terrarum.utils.JsonFetcher;
|
||||
import net.torvald.terrarum.utils.JsonWriter;
|
||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas;
|
||||
import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack;
|
||||
@@ -995,7 +995,7 @@ public class App implements ApplicationListener {
|
||||
File configFile = new File(configDir);
|
||||
|
||||
if (!configFile.exists() || configFile.length() == 0L) {
|
||||
JsonWriter.INSTANCE.writeToFile(DefaultConfig.INSTANCE.getHashMap(), configDir);
|
||||
WriteConfig.INSTANCE.invoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import net.torvald.terrarum.App
|
||||
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.TerrarumIngame
|
||||
|
||||
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 {
|
||||
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
|
||||
if (player == null) return
|
||||
|
||||
JsonWriter.writeToFile(
|
||||
player,
|
||||
App.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")
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,7 @@ object WriteConfig {
|
||||
override fun write(json: Json, obj: KVHashMap, knownType: Class<*>?) {
|
||||
json.writeObjectStart()
|
||||
obj.hashMap.toSortedMap().forEach { (k, v) ->
|
||||
json.writeValue(k,
|
||||
if (v is Int) v as Int
|
||||
else if (v is Double) v as Double
|
||||
else if (v is IntArray) v as IntArray
|
||||
else if (v is DoubleArray) v as DoubleArray
|
||||
else if (v is Boolean) v as Boolean
|
||||
else v.toString()
|
||||
)
|
||||
json.writeValue(k, v)
|
||||
}
|
||||
json.writeObjectEnd()
|
||||
}
|
||||
@@ -43,8 +36,28 @@ object WriteConfig {
|
||||
|
||||
}
|
||||
|
||||
/*fun getJson(): String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
App.gameConfig.hashMap.toSortedMap().forEach { (k, v) ->
|
||||
sb.append("$k:")
|
||||
|
||||
when (v) {
|
||||
is DoubleArray -> { sb.append("[${v.joinToString(",")}]") }
|
||||
is IntArray -> { sb.append("[${v.joinToString(",")}]") }
|
||||
is Array<*> -> { sb.append("[${v.joinToString(",")}]") }
|
||||
else -> { sb.append("$v") }
|
||||
}
|
||||
|
||||
sb.append("\n")
|
||||
}
|
||||
|
||||
return "{\n$sb}"
|
||||
}*/
|
||||
|
||||
operator fun invoke() {
|
||||
val writer = java.io.FileWriter(App.configDir, false)
|
||||
//writer.write(getJson())
|
||||
writer.write(jsoner.prettyPrint(App.gameConfig))
|
||||
writer.close()
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.torvald.terrarum.tests
|
||||
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.badlogic.gdx.utils.JsonValue
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.terrarum.utils.JsonWriter
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
@@ -68,7 +68,9 @@ fun main() {
|
||||
}
|
||||
}
|
||||
|
||||
JsonWriter.writeToFile(jsonObject, file.absolutePath)
|
||||
val writer = java.io.FileWriter(file, false)
|
||||
writer.write(Json().toJson(jsonObject))
|
||||
writer.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.torvald.terrarum.tests
|
||||
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import net.torvald.terrarum.utils.JsonWriter
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package net.torvald.terrarum.utils
|
||||
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.badlogic.gdx.utils.JsonWriter
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-03-04.
|
||||
*/
|
||||
object JsonWriter {
|
||||
|
||||
private val formattingRegex = Regex("""(?<=[\{,\[])|(?=[\]}])""")
|
||||
|
||||
/**
|
||||
* serialise a class to the file as JSON, using Google GSON.
|
||||
*
|
||||
* @param c: a class
|
||||
* @param path: path to write a file
|
||||
*/
|
||||
@Throws(java.io.IOException::class)
|
||||
fun writeToFile(c: Any, path: String) {
|
||||
val writer = java.io.FileWriter(path, false)
|
||||
writer.write(Json(JsonWriter.OutputType.json).toJson(c).replace(formattingRegex, "\n"))
|
||||
writer.close()
|
||||
}
|
||||
|
||||
/**
|
||||
* serialise JsonObject to the file as JSON, using Google GSON.
|
||||
*
|
||||
* @param jsonObject
|
||||
* @param path: path to write a file
|
||||
*/
|
||||
/*@Throws(java.io.IOException::class)
|
||||
fun writeToFile(jsonObject: Json, path: String) {
|
||||
val writer = java.io.FileWriter(path, false)
|
||||
|
||||
writer.write(jsonObject.)
|
||||
//writer.write(jsonObject.toString().replace(formattingRegex, "\n"))
|
||||
writer.close()
|
||||
}*/
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user