mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
completely abolishing GSON; new save format impl wip
This commit is contained in:
@@ -303,7 +303,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
// init map as chosen size
|
||||
val timeNow = System.currentTimeMillis() / 1000
|
||||
gameworld = GameWorldExtension(1, worldParams.width, worldParams.height, timeNow, timeNow, 0) // new game, so the creation time is right now
|
||||
gameworldCount++
|
||||
gameworldIndices.add(gameworld.worldIndex)
|
||||
world = gameworld
|
||||
|
||||
// generate terrain for the map
|
||||
|
||||
@@ -20,7 +20,7 @@ internal object ExportAV : ConsoleCommand {
|
||||
if (player == null) return
|
||||
|
||||
JsonWriter.writeToFile(
|
||||
player.actorValue,
|
||||
player,
|
||||
AppLoader.defaultDir + "/Exports/" + args[1] + ".json")
|
||||
|
||||
Echo("ExportAV: exported to " + args[1] + ".json")
|
||||
|
||||
@@ -1,22 +1,31 @@
|
||||
package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import net.torvald.terrarum.AppLoader
|
||||
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.WriteMeta
|
||||
import net.torvald.terrarum.utils.JsonWriter
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-07-18.
|
||||
*/
|
||||
object ExportLayerData : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
/*try {
|
||||
val outfile = WriteLayerDataZip()
|
||||
WriteWorldInfo()
|
||||
Echo("Layer data exported to ${outfile!!.canonicalPath}")
|
||||
try {
|
||||
val str = WriteMeta(Terrarum.ingame!! as TerrarumIngame).invoke()
|
||||
val writer = java.io.FileWriter(AppLoader.defaultDir + "/Exports/savegame.json", false)
|
||||
writer.write(str)
|
||||
writer.close()
|
||||
Echo("Exportlayer: exported to savegame.json")
|
||||
}
|
||||
catch (e: Exception) {
|
||||
catch (e: IOException) {
|
||||
Echo("Exportlayer: IOException raised.")
|
||||
e.printStackTrace()
|
||||
EchoError("Layer data export failed; see console for error traces.")
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.io.IOException
|
||||
/**
|
||||
* Created by minjaesong on 2016-02-10.
|
||||
*/
|
||||
internal object GsonTest : ConsoleCommand {
|
||||
/*internal object GsonTest : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
|
||||
@@ -51,4 +51,4 @@ internal object GsonTest : ConsoleCommand {
|
||||
|
||||
Echo("Usage: gsontest filename-without-extension")
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -5,7 +5,6 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
import net.torvald.terrarum.serialise.ReadLayerDataZip
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
@@ -13,7 +12,7 @@ import java.io.File
|
||||
*/
|
||||
object ImportLayerData : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size < 2) {
|
||||
/*if (args.size < 2) {
|
||||
ExportLayerData.printUsage()
|
||||
return
|
||||
}
|
||||
@@ -28,7 +27,7 @@ object ImportLayerData : ConsoleCommand {
|
||||
(Terrarum.ingame!!.world).spawnX * TILE_SIZED
|
||||
)
|
||||
|
||||
Echo("Successfully loaded ${args[1]}")
|
||||
Echo("Successfully loaded ${args[1]}")*/
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
|
||||
@@ -2,13 +2,12 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.random.Fudge3
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import com.google.gson.JsonObject
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.ActorValue
|
||||
import java.security.SecureRandom
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-03-25.
|
||||
@@ -27,46 +26,44 @@ object InjectCreatureRaw {
|
||||
operator fun invoke(actorValueRef: ActorValue, module: String, jsonFileName: String) {
|
||||
val jsonObj = JsonFetcher(ModMgr.getPath(module, "creatures/$jsonFileName"))
|
||||
|
||||
jsonObj.keySet().filter { !it.startsWith("_") }.forEach { key ->
|
||||
|
||||
JsonFetcher.forEach(jsonObj) { key, value -> if (!key.startsWith("_")) {
|
||||
val diceRollers = ArrayList<String>()
|
||||
|
||||
jsonObj[key].let {
|
||||
if (it.isJsonPrimitive) {
|
||||
val raw = it.asString
|
||||
val lowraw = raw.toLowerCase()
|
||||
// can the value be cast to Boolean?
|
||||
if (lowraw == "true") actorValueRef[key] = true
|
||||
else if (lowraw == "false") actorValueRef[key] = false
|
||||
else {
|
||||
try {
|
||||
actorValueRef[key] =
|
||||
if (raw.contains('.')) it.asDouble
|
||||
else it.asInt
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
actorValueRef[key] = raw
|
||||
}
|
||||
if (!value.isArray && !value.isObject) {
|
||||
val raw = value.asString()
|
||||
val lowraw = raw.lowercase()
|
||||
// can the value be cast to Boolean?
|
||||
if (lowraw == "true") actorValueRef[key] = true
|
||||
else if (lowraw == "false") actorValueRef[key] = false
|
||||
else {
|
||||
try {
|
||||
actorValueRef[key] =
|
||||
if (raw.contains('.')) value.asDouble()
|
||||
else value.asLong().toInt()
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
actorValueRef[key] = raw
|
||||
}
|
||||
}
|
||||
else if (key.endsWith(JSONMULT) && it.isJsonArray) {
|
||||
diceRollers.add(key)
|
||||
}
|
||||
else {
|
||||
printdbg(this, "Unknown Creature Raw key: $key")
|
||||
}
|
||||
}
|
||||
else if (key.endsWith(JSONMULT) && value.isArray) {
|
||||
diceRollers.add(key)
|
||||
}
|
||||
else {
|
||||
printdbg(this, "Unknown Creature Raw key: $key")
|
||||
}
|
||||
|
||||
diceRollers.forEach { keymult ->
|
||||
val keybase = keymult.substring(0, keymult.length - 4)
|
||||
val baseValue = jsonObj[keybase].asDouble
|
||||
val baseValue = jsonObj[keybase].asDouble()
|
||||
val selected = Fudge3(SecureRandom()).rollForArray()
|
||||
val mult = jsonObj[keymult].asJsonArray.get(selected).asInt
|
||||
val mult = jsonObj[keymult].asIntArray()[selected]
|
||||
val realValue = baseValue * mult / 100.0
|
||||
|
||||
actorValueRef[keybase] = realValue
|
||||
actorValueRef[keybase + BUFF] = 1.0
|
||||
}
|
||||
}
|
||||
} }
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package net.torvald.terrarum.modulebasegame.gameworld
|
||||
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.serialise.ReadLayerDataZip
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2018-07-03.
|
||||
@@ -10,7 +9,7 @@ import net.torvald.terrarum.serialise.ReadLayerDataZip
|
||||
class GameWorldExtension : GameWorld {
|
||||
|
||||
constructor(worldIndex: Int, width: Int, height: Int, creationTIME_T: Long, lastPlayTIME_T: Long, totalPlayTime: Int) : super(worldIndex, width, height, creationTIME_T, lastPlayTIME_T, totalPlayTime)
|
||||
internal constructor(worldIndex: Int, layerData: ReadLayerDataZip.LayerData, creationTIME_T: Long, lastPlayTIME_T: Long, totalPlayTime: Int) : super(worldIndex, layerData, creationTIME_T, lastPlayTIME_T, totalPlayTime)
|
||||
//internal constructor(worldIndex: Int, layerData: ReadLayerDataZip.LayerData, creationTIME_T: Long, lastPlayTIME_T: Long, totalPlayTime: Int) : super(worldIndex, layerData, creationTIME_T, lastPlayTIME_T, totalPlayTime)
|
||||
|
||||
|
||||
val economy = GameEconomy()
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.BuildingMaker
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
@@ -153,7 +154,19 @@ class UIBuildingMakerPenMenu(val parent: BuildingMaker): UICanvas() {
|
||||
|
||||
// draw blocks slot
|
||||
batch.color = blockCellCol
|
||||
val slotConfig = AppLoader.getConfigStringArray("buildingmakerfavs")
|
||||
val slotConfig = arrayOf(
|
||||
Block.GLASS_CRUDE,
|
||||
Block.PLANK_NORMAL,
|
||||
Block.PLANK_BIRCH,
|
||||
Block.STONE_QUARRIED,
|
||||
Block.STONE_BRICKS,
|
||||
|
||||
Block.STONE_TILE_WHITE,
|
||||
Block.TORCH,
|
||||
"wall@" + Block.PLANK_NORMAL,
|
||||
"wall@" + Block.PLANK_BIRCH,
|
||||
"wall@" + Block.GLASS_CRUDE
|
||||
)//AppLoader.getConfigStringArray("buildingmakerfavs")
|
||||
for (i in 0 until PALETTE_SIZE) {
|
||||
val x = blockCellPos[i].x.roundToInt().toFloat()
|
||||
val y = blockCellPos[i].y.roundToInt().toFloat()
|
||||
|
||||
@@ -2,10 +2,10 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.utils.JsonValue
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
|
||||
import net.torvald.terrarum.serialise.ReadWorldInfo
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
import java.util.*
|
||||
@@ -17,7 +17,7 @@ import java.util.*
|
||||
*/
|
||||
class UIItemPlayerInfoCell(
|
||||
parent: UICanvas,
|
||||
val saveInfo: ReadWorldInfo.SaveMetaData,
|
||||
val saveInfo: JsonValue,
|
||||
override val width: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
@@ -50,18 +50,18 @@ class UIItemPlayerInfoCell(
|
||||
init {
|
||||
val cal = Calendar.getInstance()
|
||||
|
||||
cal.timeInMillis = saveInfo.creationTime * 1000
|
||||
cal.timeInMillis = saveInfo.getLong("creation_t") * 1000
|
||||
creationTimeStr = "${cal[Calendar.YEAR]}-" +
|
||||
"${cal[Calendar.MONTH].toString().padStart(2,'0')}-" +
|
||||
"${cal[Calendar.DATE].toString().padStart(2,'0')}"
|
||||
|
||||
cal.timeInMillis = saveInfo.lastPlayTime * 1000
|
||||
cal.timeInMillis = saveInfo.getLong("lastplay_t") * 1000
|
||||
modificationTimeStr = "${cal[Calendar.YEAR]}-" +
|
||||
"${cal[Calendar.MONTH].toString().padStart(2,'0')}-" +
|
||||
"${cal[Calendar.DATE].toString().padStart(2,'0')}"
|
||||
|
||||
|
||||
worldCountStr = Lang["CONTEXT_WORLD_COUNT"] + saveInfo.worldCount
|
||||
worldCountStr = Lang["CONTEXT_WORLD_COUNT"] + saveInfo.get("worlds").asIntArray().size
|
||||
worldCountStrWidth = AppLoader.fontGame.getWidth(worldCountStr)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user