mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-18 22:44:04 +09:00
font update; ui remocon fix; save doc elaboration
UI RemoCon fix: RemoCon will no longer widen to the screen width when being used
This commit is contained in:
34
src/net/torvald/terrarum/serialise/SavegameLedger.kt
Normal file
34
src/net/torvald/terrarum/serialise/SavegameLedger.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package net.torvald.terrarum.serialise
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
import java.io.FileInputStream
|
||||
|
||||
|
||||
|
||||
object SavegameLedger {
|
||||
|
||||
private val SAVE_DIRECTORY = File(Terrarum.defaultSaveDir)
|
||||
|
||||
fun hasSavegameDirectory() = SAVE_DIRECTORY.exists() && SAVE_DIRECTORY.isDirectory
|
||||
|
||||
private fun peekFewBytes(file: File, length: Int): ByteArray {
|
||||
val buffer = ByteArray(length)
|
||||
val `is` = FileInputStream(file)
|
||||
if (`is`.read(buffer) != buffer.size) {
|
||||
throw InternalError()
|
||||
}
|
||||
`is`.close()
|
||||
return buffer
|
||||
}
|
||||
private val MAGIC_TEVD = "TEVd".toByteArray()
|
||||
|
||||
fun getSavefileList(): List<File>? {
|
||||
return if (!hasSavegameDirectory()) null
|
||||
else SAVE_DIRECTORY.listFiles().filter { it.isFile && peekFewBytes(it, 4) contentEquals MAGIC_TEVD }
|
||||
}
|
||||
|
||||
fun getSavefileCount() = getSavefileList()?.count() ?: 0
|
||||
|
||||
}
|
||||
@@ -48,7 +48,7 @@ internal object WriteCSV {
|
||||
Files.copy(tempPathMat, pathMat, StandardCopyOption.REPLACE_EXISTING)
|
||||
Files.deleteIfExists(tempPathMat)
|
||||
|
||||
println("Saved map data '${WriteLayerData.META_FILENAME}' to $saveDirectoryName.")
|
||||
println("Saved map data '${WriteLayerData.LAYERS_FILENAME}' to $saveDirectoryName.")
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.torvald.terrarum.serialise
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.console.EchoError
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
@@ -11,12 +10,14 @@ import java.nio.charset.Charset
|
||||
import java.util.zip.GZIPOutputStream
|
||||
|
||||
/**
|
||||
* TODO this one does not use TerranVirtualDisk
|
||||
*
|
||||
* Created by minjaesong on 2016-03-18.
|
||||
*/
|
||||
// internal for everything: prevent malicious module from messing up the savedata
|
||||
internal object WriteLayerData {
|
||||
|
||||
val META_FILENAME = "worldinfo1"
|
||||
val LAYERS_FILENAME = "worldinfo1"
|
||||
|
||||
val MAGIC = "TEMD".toByteArray(charset = Charset.forName("US-ASCII"))
|
||||
|
||||
@@ -24,7 +25,7 @@ internal object WriteLayerData {
|
||||
|
||||
|
||||
internal operator fun invoke(saveDirectoryName: String): Boolean {
|
||||
val path = "${Terrarum.defaultSaveDir}/$saveDirectoryName/${META_FILENAME}"
|
||||
val path = "${Terrarum.defaultSaveDir}/$saveDirectoryName/${LAYERS_FILENAME}"
|
||||
val tempPath = "${path}_bak"
|
||||
val map = (Terrarum.ingame!!.world)
|
||||
|
||||
@@ -69,7 +70,7 @@ internal object WriteLayerData {
|
||||
outFile.delete()
|
||||
tempFile.copyTo(outFile, overwrite = true)
|
||||
tempFile.delete()
|
||||
println("Saved map data '$META_FILENAME' to $saveDirectoryName.")
|
||||
println("Saved map data '$LAYERS_FILENAME' to $saveDirectoryName.")
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.serialise
|
||||
|
||||
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
|
||||
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
|
||||
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
|
||||
import java.nio.charset.Charset
|
||||
@@ -10,7 +11,7 @@ import java.nio.charset.Charset
|
||||
// internal for everything: prevent malicious module from messing up the savedata
|
||||
internal object WriteMeta {
|
||||
|
||||
val META_FILENAME = "world"
|
||||
val META_FILENAME = "worldinfo0"
|
||||
|
||||
val MAGIC = "TESV".toByteArray(charset = Charset.forName("US-ASCII"))
|
||||
|
||||
@@ -19,6 +20,9 @@ internal object WriteMeta {
|
||||
|
||||
val terraseed: Long = WorldGenerator.SEED
|
||||
val rogueseed: Long = RoguelikeRandomiser.seed
|
||||
val rogueiter: Int = RoguelikeRandomiser.iterations
|
||||
val weatherseed: Long = WeatherMixer.seed
|
||||
val weatheriter: Int = WeatherMixer.iterations
|
||||
|
||||
/**
|
||||
* Write save meta to specified directory. Returns false if something went wrong.
|
||||
|
||||
Reference in New Issue
Block a user