mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
exportmap cmd reworked
This commit is contained in:
@@ -597,8 +597,8 @@ open class GameWorld(
|
|||||||
layerOres.unsafeSetTile(x, y, tileNameToNumberMap[ore]!!, placement)
|
layerOres.unsafeSetTile(x, y, tileNameToNumberMap[ore]!!, placement)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun terrainIterator(): Iterator<ItemID> {
|
fun terrainIterator(): Iterator<List<ItemID>> {
|
||||||
return object : Iterator<ItemID> {
|
return object : Iterator<List<ItemID>> {
|
||||||
|
|
||||||
private var iteratorCount = 0
|
private var iteratorCount = 0
|
||||||
|
|
||||||
@@ -606,13 +606,13 @@ open class GameWorld(
|
|||||||
return iteratorCount < width * height
|
return iteratorCount < width * height
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun next(): ItemID {
|
override fun next(): List<ItemID> {
|
||||||
val y = iteratorCount / width
|
val y = iteratorCount / width
|
||||||
val x = iteratorCount % width
|
val x = iteratorCount % width
|
||||||
// advance counter
|
// advance counter
|
||||||
iteratorCount += 1
|
iteratorCount += 1
|
||||||
|
|
||||||
return getTileFromTerrain(x, y)
|
return listOf(getTileFromTerrain(x, y), getTileFromWall(x, y), getTileFromOre(x, y).item)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.console
|
package net.torvald.terrarum.modulebasegame.console
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
import net.torvald.gdx.graphics.Cvec
|
import net.torvald.gdx.graphics.Cvec
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
|
import net.torvald.terrarum.BlockCodex
|
||||||
import net.torvald.terrarum.INGAME
|
import net.torvald.terrarum.INGAME
|
||||||
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.console.ConsoleCommand
|
import net.torvald.terrarum.console.ConsoleCommand
|
||||||
import net.torvald.terrarum.console.Echo
|
import net.torvald.terrarum.console.Echo
|
||||||
import net.torvald.terrarum.console.EchoError
|
import net.torvald.terrarum.console.EchoError
|
||||||
import net.torvald.terrarum.utils.RasterWriter
|
import net.torvald.terrarum.utils.RasterWriter
|
||||||
|
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.Companion.WALL_OVERLAY_COLOUR
|
||||||
import net.torvald.terrarum.worlddrawer.toRGBA
|
import net.torvald.terrarum.worlddrawer.toRGBA
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@@ -20,6 +24,14 @@ internal object ExportMap : ConsoleCommand {
|
|||||||
// private var mapDataPointer = 0
|
// private var mapDataPointer = 0
|
||||||
|
|
||||||
|
|
||||||
|
private val oreColourMap = hashMapOf(
|
||||||
|
Block.AIR to Cvec(0),
|
||||||
|
"ores@basegame:1" to Cvec(0x00e9c8ff),
|
||||||
|
"ores@basegame:2" to Cvec(0xff9a5dff.toInt()),
|
||||||
|
"ores@basegame:3" to Cvec(0x383314ff),
|
||||||
|
)
|
||||||
|
|
||||||
|
private val WALL_OVERLAY = Cvec(0.35f, 0.35f, 0.35f, 1f)
|
||||||
|
|
||||||
override fun execute(args: Array<String>) {
|
override fun execute(args: Array<String>) {
|
||||||
val world = (INGAME.world)
|
val world = (INGAME.world)
|
||||||
@@ -31,8 +43,13 @@ internal object ExportMap : ConsoleCommand {
|
|||||||
var mapData = ByteArray(world.width * world.height * 3)
|
var mapData = ByteArray(world.width * world.height * 3)
|
||||||
var mapDataPointer = 0
|
var mapDataPointer = 0
|
||||||
|
|
||||||
for (tile in world.terrainIterator()) {
|
for ((terr, wall, ore) in world.terrainIterator()) {
|
||||||
val colArray = App.tileMaker.terrainTileColourMap.get(tile)!!.toByteArray()
|
val colOre = (oreColourMap.get(ore) ?: throw NullPointerException("nullore $ore")).toByteArray()
|
||||||
|
val colFore = (App.tileMaker.terrainTileColourMap.get(terr) ?: throw NullPointerException("nullterr $terr")).toByteArray()
|
||||||
|
val colWall = (App.tileMaker.terrainTileColourMap.get(wall) ?: throw NullPointerException("nullwall $wall")).cpy().mul(WALL_OVERLAY).toByteArray()
|
||||||
|
|
||||||
|
val colArray = if (ore != Block.AIR) colOre else if (BlockCodex[terr].isSolid) colFore else colWall
|
||||||
|
|
||||||
|
|
||||||
for (i in 0..2) {
|
for (i in 0..2) {
|
||||||
mapData[mapDataPointer + i] = colArray[i]
|
mapData[mapDataPointer + i] = colArray[i]
|
||||||
|
|||||||
Reference in New Issue
Block a user