mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
poi read wip
This commit is contained in:
@@ -41,7 +41,7 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
- New Flat ter. : net.torvald.terrarum.modulebasegame.YamlCommandNewFlatTerrain
|
||||
- New Rand. ter.
|
||||
- Export… : net.torvald.terrarum.modulebasegame.YamlCommandToolExportTest
|
||||
- Import…
|
||||
- Import… : net.torvald.terrarum.modulebasegame.YamlCommandToolImportTest
|
||||
- Exit to Title : net.torvald.terrarum.modulebasegame.YamlCommandExit
|
||||
- Edit
|
||||
- Clear Selections : net.torvald.terrarum.modulebasegame.YamlCommandClearSelection
|
||||
@@ -795,4 +795,15 @@ class YamlCommandNewFlatTerrain : YamlInvokable {
|
||||
|
||||
ui.reset()
|
||||
}
|
||||
}
|
||||
|
||||
class YamlCommandToolImportTest : YamlInvokable {
|
||||
override fun invoke(args: Array<Any>) {
|
||||
YamlCommandClearSelection().invoke(args)
|
||||
val ui = (args[0] as BuildingMaker)
|
||||
|
||||
val json = """{"genver":67108864,"id":"test","wlen":8,"w":6,"h":7,"lut":{"0":"basegame:0","1":"basegame:19","2":"basegame:-1"},"layers":[{"name":"test1","dat":["abZy8000000rlLp0S#Gh%Q1%XFDc>fH&5.j6G~zOdGxCG","abZy8000000rlLp0S#Gh38ntBemYv>C=*G~dGxCG"]},{"name":"test2","dat":["abZy8000000rlLp0S#Gh%Q1%XFDc>fH&5.j6G~zOdGxCG","abZy8000000rlLp0S#Gh38ntBemYv>C=*G~dGxCG"]}]}"""
|
||||
|
||||
val poi = Common.jsoner.fromJson(PointOfInterest().javaClass, json)
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.gameworld.BlockLayerI16
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.GameWorld.Companion.TERRAIN
|
||||
import net.torvald.terrarum.gameworld.GameWorld.Companion.WALL
|
||||
import net.torvald.terrarum.linearSearchBy
|
||||
import net.torvald.terrarum.utils.HashArray
|
||||
|
||||
@@ -23,12 +25,11 @@ class PointOfInterest(
|
||||
|
||||
constructor() : this("undefined", 0,0, HashArray())
|
||||
|
||||
@Transient val w = width
|
||||
@Transient val h = height
|
||||
@Transient val layers = ArrayList<POILayer>()
|
||||
@Transient val id = identifier
|
||||
|
||||
@Transient val tileNumberToNameMap: HashArray<ItemID> = tileNumberToNameMap0
|
||||
@Transient var w = width; private set
|
||||
@Transient var h = height; private set
|
||||
@Transient var layers = ArrayList<POILayer>(); private set
|
||||
@Transient var id = identifier; private set
|
||||
@Transient var tileNumberToNameMap: HashArray<ItemID> = tileNumberToNameMap0; private set
|
||||
|
||||
|
||||
override fun write(json: Json) {
|
||||
@@ -52,7 +53,8 @@ class PointOfInterest(
|
||||
|
||||
|
||||
printdbg(this, "unique tiles: ${tileSymbolToItemId.size}")
|
||||
printdbg(this, "lut=$tileSymbolToItemId")
|
||||
printdbg(this, "tileSymbolToItemId=$tileSymbolToItemId")
|
||||
printdbg(this, "itemIDtoTileSym=$itemIDtoTileSym")
|
||||
|
||||
|
||||
|
||||
@@ -69,7 +71,26 @@ class PointOfInterest(
|
||||
}
|
||||
|
||||
override fun read(json: Json, jsonData: JsonValue) {
|
||||
TODO("Not yet implemented")
|
||||
this.id = jsonData["id"].asString()
|
||||
this.w = jsonData["w"].asInt()
|
||||
this.h = jsonData["h"].asInt()
|
||||
this.tileNumberToNameMap = json.readValue(HashArray<ItemID>().javaClass, jsonData["lut"])
|
||||
val wlen = jsonData["wlen"].asInt()
|
||||
|
||||
|
||||
println("read test")
|
||||
println("id: $id, w: $w, h: $h")
|
||||
println("lut: $tileNumberToNameMap")
|
||||
println("==== layers ====")
|
||||
jsonData["layers"].forEachIndexed { index, it ->
|
||||
print("#${index+1}: ")
|
||||
println(it["name"].asString())
|
||||
println("layerdata:")
|
||||
it["dat"].forEachIndexed { index, value ->
|
||||
print(" L${if (index == TERRAIN) "terr" else if (index == WALL) "wall" else "unk$index"}: ")
|
||||
println(value.asString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +134,6 @@ class POILayer(
|
||||
* TileSymbol: condensed version of the Tilenum, of which the higheset number is equal to the number of unique tiles used in the layer
|
||||
*
|
||||
* `tilenumToItemID[-1]` should return `Block.NULL`
|
||||
* `itemIDtoTileSym[Block.NULL]` should return -1, so that it would return 0xFF on any length of the word
|
||||
*/
|
||||
fun getReadyForSerialisation(tilenumToItemID: HashArray<ItemID>, itemIDtoTileSym: Map<ItemID, Long>, byteLength: Int) {
|
||||
dat = blockLayer.map { layer ->
|
||||
@@ -138,7 +158,6 @@ class POILayer(
|
||||
/**
|
||||
* Converts `dat` into `blockLayer` so the Layer can be actually utilised.
|
||||
*
|
||||
* `itemIDtoTileNum[Block.NULL]` should return `-1`
|
||||
* `tileSymbolToItemId[255]` and `tileSymbolToItemId[65535]` should return `Block.NULL`
|
||||
*/
|
||||
fun getReadyToBeUsed(tileSymbolToItemId: HashArray<ItemID>, itemIDtoTileNum: Map<ItemID, Int>, width: Int, height: Int, byteLength: Int) {
|
||||
|
||||
Reference in New Issue
Block a user