quickslot works, new event for actor "actorValueChanged"

- "unpacking" fresh new tool would un-register quickslot desig.
- priority issue on "equipped by quickslot change" and "equipped by inventory UI"
This commit is contained in:
Song Minjae
2017-04-28 12:21:27 +09:00
parent 13e817e154
commit 996d578d3e
34 changed files with 215 additions and 61 deletions

View File

@@ -0,0 +1,42 @@
package net.torvald.terrarum.serialise
import java.io.IOException
import java.io.InputStream
/**
* Created by minjaesong on 16-08-24.
*/
// internal for everything: prevent malicious module from messing up the savedata
internal object ReadGameMapData {
internal fun InputStream.readRelative(b: ByteArray, off: Int, len: Int): Int {
if (b == null) {
throw NullPointerException()
} else if (off < 0 || len < 0 || len > b.size) {
throw IndexOutOfBoundsException()
} else if (len == 0) {
return 0
}
var c = read()
if (c == -1) {
return -1
}
b[0] = c.toByte()
var i = 1
try {
while (i < len) {
c = read()
if (c == -1) {
break
}
b[i] = c.toByte()
i++
}
} catch (ee: IOException) {
}
return i
}
}

View File

@@ -0,0 +1,61 @@
package net.torvald.terrarum.serialise
import net.torvald.terrarum.Terrarum
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
/**
* Created by minjaesong on 16-03-18.
*/
// internal for everything: prevent malicious module from messing up the savedata
internal object WriteCSV {
val META_FILENAME_TILE = "worldinfo2"
val META_FILENAME_ITEM = "worldinfo3"
val META_FILENAME_MAT = "worldinfo4"
internal fun write(saveDirectoryName: String): Boolean {
//val tileCSV = CSVFetcher.readCSVasString(BlockCodex.CSV_PATH)
//val itemCSV = CSVFetcher.readCSVasString(ItemCodex.CSV_PATH)
//val matCSV = CSVFetcher.readCSVasString(MaterialCodex.CSV_PATH)
val pathTile = Paths.get("${Terrarum.defaultSaveDir}" +
"/$saveDirectoryName/${META_FILENAME_TILE}")
val pathItem = Paths.get("${Terrarum.defaultSaveDir}" +
"/$saveDirectoryName/${META_FILENAME_ITEM}")
val pathMat = Paths.get("${Terrarum.defaultSaveDir}" +
"/$saveDirectoryName/${META_FILENAME_MAT}")
val tempPathTile = Files.createTempFile(pathTile.toString(), "_temp")
val tempPathItem = Files.createTempFile(pathItem.toString(), "_temp")
val tempPathMat = Files.createTempFile(pathMat.toString(), "_temp")
// TODO gzip
// write CSV to path
//Files.write(tempPathTile, tileCSV.toByteArray(Charsets.UTF_8))
//Files.write(tempPathItem, itemCSV.toByteArray(Charsets.UTF_8))
//Files.write(tempPathMat, matCSV.toByteArray(Charsets.UTF_8))
// replace savemeta with tempfile
try {
Files.copy(tempPathTile, pathTile, StandardCopyOption.REPLACE_EXISTING)
Files.deleteIfExists(tempPathTile)
Files.copy(tempPathItem, pathItem, StandardCopyOption.REPLACE_EXISTING)
Files.deleteIfExists(tempPathItem)
Files.copy(tempPathMat, pathMat, StandardCopyOption.REPLACE_EXISTING)
Files.deleteIfExists(tempPathMat)
println("Saved map data '${WriteGameMapData.META_FILENAME}' to $saveDirectoryName.")
return true
}
catch (e: IOException) {
e.printStackTrace()
}
return false
}
}

View File

@@ -0,0 +1,75 @@
package net.torvald.terrarum.serialise
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.Terrarum
import java.io.IOException
import java.nio.charset.Charset
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
/**
* Created by minjaesong on 16-03-18.
*/
// internal for everything: prevent malicious module from messing up the savedata
internal object WriteGameMapData {
val META_FILENAME = "worldinfo1"
val MAGIC = "TEMD".toByteArray(charset = Charset.forName("US-ASCII"))
val BYTE_NULL: Byte = 0
internal fun write(saveDirectoryName: String): Boolean {
val path = Paths.get("${Terrarum.defaultSaveDir}" +
"/$saveDirectoryName/${WriteMeta.META_FILENAME}")
val tempPath = Files.createTempFile(path.toString(), "_temp")
val map = Terrarum.ingame!!.world
// TODO gzip
// write binary
Files.write(tempPath, MAGIC)
Files.write(tempPath, byteArrayOf(GameWorld.SIZEOF))
Files.write(tempPath, byteArrayOf(GameWorld.LAYERS))
Files.write(tempPath, byteArrayOf(BYTE_NULL))
Files.write(tempPath, byteArrayOf(BYTE_NULL))
Files.write(tempPath, toByteArray(map.width))
Files.write(tempPath, toByteArray(map.height))
Files.write(tempPath, toByteArray(map.spawnX))
Files.write(tempPath, toByteArray(map.spawnY))
map.layerTerrain.forEach(
{ b -> Files.write(tempPath, byteArrayOf(b)) })
map.layerWall.forEach(
{ b -> Files.write(tempPath, byteArrayOf(b)) })
map.layerTerrainLowBits.forEach(
{ b -> Files.write(tempPath, byteArrayOf(b)) })
map.layerWallLowBits.forEach(
{ b -> Files.write(tempPath, byteArrayOf(b)) })
map.layerWire.forEach(
{ b -> Files.write(tempPath, byteArrayOf(b)) })
// replace savemeta with tempfile
try {
Files.copy(tempPath, path, StandardCopyOption.REPLACE_EXISTING)
Files.deleteIfExists(tempPath)
println("Saved map data '$META_FILENAME' to $saveDirectoryName.")
return true
}
catch (e: IOException) {
e.printStackTrace()
}
return false
}
fun toByteArray(int: Int): ByteArray {
return byteArrayOf(
((int ushr 0x18) and 0xFF).toByte(),
((int ushr 0x10) and 0xFF).toByte(),
((int ushr 0x08) and 0xFF).toByte(),
((int ) and 0xFF).toByte()
)
}
}

View File

@@ -0,0 +1,71 @@
package net.torvald.terrarum.serialise
import net.torvald.terrarum.worldgenerator.WorldGenerator
import net.torvald.terrarum.worldgenerator.RoguelikeRandomiser
import java.nio.charset.Charset
/**
* Created by minjaesong on 16-03-15.
*/
// internal for everything: prevent malicious module from messing up the savedata
internal object WriteMeta {
val META_FILENAME = "world"
val MAGIC = "TESV".toByteArray(charset = Charset.forName("US-ASCII"))
val BYTE_NULL: Byte = 0
val terraseed: Long = WorldGenerator.SEED
val rogueseed: Long = RoguelikeRandomiser.seed
/**
* Write save meta to specified directory. Returns false if something went wrong.
* @param saveDirectoryName
* @param savegameName -- Nullable. If the value is not specified, saveDirectoryName will be used instead.
*/
internal fun write(saveDirectoryName: String, savegameName: String?): Boolean {
/*val hashArray: ArrayList<ByteArray> = ArrayList()
val savenameAsByteArray: ByteArray =
(savegameName ?: saveDirectoryName).toByteArray(Charsets.UTF_8)
// define Strings to be hashed
val props = arrayOf(
TilePropCSV()
//, (item, mat, ...)
)
// get and store hash from the list
props.map { hashArray.add(DigestUtils.sha256(it)) }
// open file and delete it
val metaPath = Paths.get("$Terrarum.defaultSaveDir" +
"/$saveDirectoryName/$META_FILENAME")
val metaTempPath = Files.createTempFile(metaPath.toString(), "_temp")
// TODO gzip
// write bytes in tempfile
Files.write(metaTempPath, MAGIC)
Files.write(metaTempPath, savenameAsByteArray)
Files.write(metaTempPath, byteArrayOf(BYTE_NULL))
Files.write(metaTempPath, toByteArray(terraseed))
Files.write(metaTempPath, toByteArray(rogueseed))
for (hash in hashArray)
Files.write(metaTempPath, hash)
// replace savemeta with tempfile
try {
Files.copy(metaTempPath, metaPath, StandardCopyOption.REPLACE_EXISTING)
Files.deleteIfExists(metaTempPath)
println("Saved metadata to $saveDirectoryName.")
return true
}
catch (e: IOException) {
e.printStackTrace()
}*/
return false
}
}