new layer 'ores'

This commit is contained in:
minjaesong
2023-10-09 19:38:04 +09:00
parent d9218a2dd6
commit 23c445f014
3 changed files with 49 additions and 14 deletions

View File

@@ -85,6 +85,12 @@ open class GameWorld(
//layers
@Transient lateinit open var layerWall: BlockLayer
@Transient lateinit open var layerTerrain: BlockLayer
val layerOres = HashedOres() // damage to the block follows `terrainDamages`
val wallDamages = HashArray<Float>()
val terrainDamages = HashArray<Float>()
val layerFluids = HashedFluidTypeAndFills();
//val layerThermal: MapLayerHalfFloat // in Kelvins
//val layerFluidPressure: MapLayerHalfFloat // (milibar - 1000)
@@ -102,10 +108,7 @@ open class GameWorld(
}
var portalPoint: Point2i? = null
val wallDamages = HashArray<Float>()
val terrainDamages = HashArray<Float>()
val fluidTypes = HashedFluidType()
val fluidFills = HashArray<Float>()
/**
* Single block can have multiple conduits, different types of conduits are stored separately.
@@ -358,8 +361,7 @@ open class GameWorld(
terrainDamages.remove(blockAddr)
if (BlockCodex[itemID].isSolid) {
fluidFills.remove(blockAddr)
fluidTypes.remove(blockAddr)
layerFluids.remove(blockAddr)
}
// fluid tiles-item should be modified so that they will also place fluid onto their respective map
@@ -669,13 +671,10 @@ open class GameWorld(
if (fill > WorldSimulator.FLUID_MIN_MASS) {
//setTileTerrain(x, y, fluidTypeToBlock(fluidType))
fluidFills[addr] = fill
fluidTypes[addr] = fluidType
layerFluids[addr] = Fill(fluidType, fill)
}
else {
fluidFills.remove(addr)
fluidTypes.remove(addr)
layerFluids.remove(addr)
}
@@ -688,8 +687,8 @@ open class GameWorld(
fun getFluid(x: Int, y: Int): FluidInfo {
val addr = LandUtil.getBlockAddr(this, x, y)
val fill = fluidFills[addr]
val type = fluidTypes[addr]
val type = layerFluids[addr]?.item
val fill = layerFluids[addr]?.amount
return if (type == null) FluidInfo(Fluid.NULL, 0f) else FluidInfo(type, fill!!)
}

View File

@@ -4,6 +4,7 @@ import com.badlogic.gdx.utils.Json
import com.badlogic.gdx.utils.JsonValue
import com.badlogic.gdx.utils.JsonWriter
import net.torvald.random.HQRNG
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.gameworld.BlockLayer
@@ -265,6 +266,28 @@ object Common {
return WeatherMixer.weatherDict[jsonData.asString()]!!
}
})
// Fill
jsoner.setSerializer(Fill::class.java, object : Json.Serializer<Fill> {
override fun write(json: Json, obj: Fill, knownType: Class<*>?) {
json.writeValue("${obj.item};${obj.amount}")
}
override fun read(json: Json, jsonData: JsonValue, type: Class<*>?): Fill {
val csv = jsonData.asString().split(',')
return Fill(csv[0], csv[1].toFloat())
}
})
// OrePlacement
jsoner.setSerializer(OrePlacement::class.java, object : Json.Serializer<OrePlacement> {
override fun write(json: Json, obj: OrePlacement, knownType: Class<*>?) {
json.writeValue("${obj.item};${obj.tilePlacement}")
}
override fun read(json: Json, jsonData: JsonValue, type: Class<*>?): OrePlacement {
val csv = jsonData.asString().split(',')
return OrePlacement(csv[0], csv[1].toInt())
}
})
}

View File

@@ -1,6 +1,8 @@
package net.torvald.terrarum.utils
import com.badlogic.gdx.utils.Json
import com.badlogic.gdx.utils.JsonValue
import net.torvald.terrarum.gameactors.ActorValue
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.BlockAddress
@@ -17,7 +19,6 @@ class HashArray<R>: HashMap<Long, R>() // primitives are working just fine tho
// Oh for the fucks sake fuck you everyone; json shit won't work with generics
class WiringGraphMap: HashMap<ItemID, GameWorld.WiringSimCell>()
class HashedFluidType: HashMap<BlockAddress, ItemID>()
class HashedWirings: HashMap<BlockAddress, GameWorld.WiringNode>()
class HashedWiringGraph: HashMap<BlockAddress, WiringGraphMap>()
class MetaModuleCSVPair: HashMap<String, ZipCodedStr>()
@@ -47,3 +48,15 @@ class PlayerLastStatus() {
@JvmInline value class ZipCodedStr(val doc: String = "") {
override fun toString() = doc
}
@Deprecated(
"Unused and only exists for the savegame compatibility",
ReplaceWith("HashedFluidTypeAndFills")
) class HashedFluidType: HashMap<BlockAddress, ItemID>()
data class Fill(var item: ItemID, var amount: Float)
data class OrePlacement(var item: ItemID, var tilePlacement: Int)
class HashedFluidTypeAndFills: HashMap<BlockAddress, Fill>()
class HashedOres: HashMap<BlockAddress, OrePlacement>()