mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-19 15:04:05 +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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user