From 1ac735805d6fc675af7fe65beea82105387353a3 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 12 Mar 2019 00:47:06 +0900 Subject: [PATCH] not reading material csv issue fixed --- assets/mods/basegame/materialprop.csv | 35 ------------------- assets/mods/basegame/materials/materials.csv | 35 +++++++++++++++++++ src/net/torvald/terrarum/AppLoader.java | 4 +++ src/net/torvald/terrarum/ModMgr.kt | 5 ++- .../torvald/terrarum/UIItemInventoryElem.kt | 26 +++++++++----- .../terrarum/blockproperties/BlockCodex.kt | 6 ++-- .../torvald/terrarum/gameworld/GameWorld.kt | 29 ++++++++++++++- .../terrarum/itemproperties/Material.kt | 22 +++++++++--- .../terrarum/modulebasegame/EntryPoint.kt | 2 +- .../modulebasegame/items/PickaxeGeneric.kt | 6 ++-- .../ui/UIItemInventoryDynamicList.kt | 9 ++++- .../terrarum/serialise/WriteLayerDataZip.kt | 5 +++ 12 files changed, 124 insertions(+), 60 deletions(-) delete mode 100644 assets/mods/basegame/materialprop.csv diff --git a/assets/mods/basegame/materialprop.csv b/assets/mods/basegame/materialprop.csv deleted file mode 100644 index 79279c854..000000000 --- a/assets/mods/basegame/materialprop.csv +++ /dev/null @@ -1,35 +0,0 @@ -"idst";"tens";"impf";"dsty";"fmod";"endurance";"tcond";"comments" -"ROCK"; "15"; "210";"3000"; "1"; "0.42"; "1.0"; -"CUPR"; "210"; "770";"8960"; "2"; "1.00";"401.0";"copper" -"EGLS"; "33";"1000";"2325"; "4"; "0.82"; "1.0";"elven glass/moldavite" -"IRON"; "350";"1085";"7874"; "5"; "1.42"; "1.0"; -"ARGN"; "170"; "595";"10490"; "9"; "0.91"; "1.0";"argentum/silver" -"STAL"; "531";"2520";"7874"; "14"; "1.73"; "1.0";"steel" -"EAUR"; "768"; "0";"8192"; "21"; "1.36"; "1.0";"elven aurichalcum" -"TIAL"; "900"; "0";"4420"; "33"; "2.16"; "1.0";"titanium alloy (Ti6Al4V)" -"ADMT";"2000";"4090";"2700"; "71"; "3.42"; "1.0";"adamant" -"OOZE"; "20"; "0";"1000"; "1"; "N/A"; "0.5";"genetic ooze; data is about human skin" -"BONE"; "130"; "0";"2000"; "1"; "0.23"; "0.55";"data was bovine bone" - -# idst: ID_STRING, ALL CAPS - -# tens: tensile strength (= ultimate stringth) -# not all 'impact' is not tensile stress, but I'm using it anyway because it's easiest to get the value from. -# that, or DF's tensile fracture divided by 1000 (I think Toady and I are both using values posted on Wikipedia, e.g. Silver) - -# impf: Dwarf Fortress impact fracture divided by 1000 (likely not being used) - -# dsty: density (grams per litre) - -# fmod: forcemod -- related to attack points -# Attack points = `4 * forcemod.sqrt()` for each strike - -# endurance: multiplier, using copper as reference; determines durability of tools/weapons/armours/etc. - the base value for endurance differes to tool to tool. When integer is used, resulting value must be ROUNDED. - -# tcond: thermal conductivity - -# Comments: do nothing; do not parse - - -## These values are being used by the phys simulator (blocks) and for attack power calculation (items) diff --git a/assets/mods/basegame/materials/materials.csv b/assets/mods/basegame/materials/materials.csv index e69de29bb..803b63d5a 100644 --- a/assets/mods/basegame/materials/materials.csv +++ b/assets/mods/basegame/materials/materials.csv @@ -0,0 +1,35 @@ +"idst";"tens";"impf";"dsty";"fmod";"endurance";"tcond";"comments" +"ROCK"; "15"; "210";"3000"; "1"; "0.42"; "1.0";"data is that of marble" +"CUPR"; "210"; "770";"8960"; "2"; "1.00";"401.0";"copper" +"EGLS"; "33";"1000";"2325"; "4"; "0.82"; "1.0";"elven glass/moldavite" +"IRON"; "350";"1085";"7874"; "5"; "1.42"; "1.0";"not wrought iron; just natural iron" +"ARGN"; "170"; "595";"10490"; "9"; "0.91"; "1.0";"argentum/silver" +"STAL"; "531";"2520";"7874"; "14"; "1.73"; "1.0";"steel" +"EAUR"; "768"; "0";"8192"; "21"; "1.36"; "1.0";"elven aurichalcum" +"TIAL"; "900"; "0";"4420"; "33"; "2.16"; "1.0";"titanium alloy (Ti6Al4V)" +"ADMT";"2000";"4090";"2700"; "71"; "3.42"; "1.0";"adamant" +"OOZE"; "20"; "0";"1000"; "1"; "N/A"; "0.5";"genetic ooze; data is about human skin" +"BONE"; "130"; "0";"2000"; "1"; "0.23"; "0.55";"data is that of bovine bone" + +# idst: ID_STRING, ALL CAPS +# +# tens: tensile strength (= ultimate stringth) +# not all 'impact' is not tensile stress, but I'm using it anyway because it's easiest to get the value from. +# that, or DF's tensile fracture divided by 1000 (I think Toady and I are both using values posted on Wikipedia, e.g. Silver) +# +# impf: Dwarf Fortress impact fracture divided by 1000 (likely not being used) +# +# dsty: density (grams per litre) +# +# fmod: forcemod -- related to attack points +# Attack points = `4 * forcemod.sqrt()` for each strike +# +# endurance: multiplier, using copper as reference; determines durability of tools/weapons/armours/etc. +# the base value for endurance differes to tool to tool. When integer is used, resulting value must be ROUNDED. +# +# tcond: thermal conductivity +# +# Comments: do nothing; do not parse +# + +## These values are being used by the phys simulator (blocks) and for attack power calculation (items) diff --git a/src/net/torvald/terrarum/AppLoader.java b/src/net/torvald/terrarum/AppLoader.java index 2cfc5e069..ffcae31e4 100644 --- a/src/net/torvald/terrarum/AppLoader.java +++ b/src/net/torvald/terrarum/AppLoader.java @@ -881,6 +881,10 @@ public class AppLoader implements ApplicationListener { } } + public static void printmsg(Object obj, Object message) { + System.out.println("[" + obj.getClass().getSimpleName() + "] " + message.toString()); + } + public static ShaderProgram loadShader(String vert, String frag) { ShaderProgram s = new ShaderProgram(Gdx.files.internal(vert), Gdx.files.internal(frag)); diff --git a/src/net/torvald/terrarum/ModMgr.kt b/src/net/torvald/terrarum/ModMgr.kt index 40c32ad89..fde900102 100644 --- a/src/net/torvald/terrarum/ModMgr.kt +++ b/src/net/torvald/terrarum/ModMgr.kt @@ -2,8 +2,7 @@ package net.torvald.terrarum import com.badlogic.gdx.Gdx import com.badlogic.gdx.files.FileHandle -import net.torvald.terrarum.AppLoader.printdbg -import net.torvald.terrarum.AppLoader.printdbgerr +import net.torvald.terrarum.AppLoader.* import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex @@ -75,7 +74,7 @@ object ModMgr { loadOrder.forEachIndexed { index, it -> val moduleName = it[0] - printdbg(this, "Loading module $moduleName") + printmsg(this, "Loading module $moduleName") try { val modMetadata = Properties() diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index d9bac065c..4716e4d93 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -102,15 +102,25 @@ class UIItemInventoryElem( // this one-liner sets color batch.color = item!!.nameColour mul if (mouseUp) mouseOverTextCol else inactiveTextCol // draw name of the item - Terrarum.fontGame.draw(batch, - // print name and amount in parens - item!!.name + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else "") + - // TEMPORARY print eqipped slot info as well - (if (equippedSlot != null) " ${0xE081.toChar()}\$$equippedSlot" else ""), + if (AppLoader.IS_DEVELOPMENT_BUILD) { + Terrarum.fontGame.draw(batch, + // print static id, dynamic id, and count + "${item!!.originalID}/${item!!.dynamicID}" + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else ""), + posX + textOffsetX, + posY + textOffsetY + ) + } + else { + Terrarum.fontGame.draw(batch, + // print name and amount in parens + item!!.name + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else "") + + // TEMPORARY print eqipped slot info as well + (if (equippedSlot != null) " ${0xE081.toChar()}\$$equippedSlot" else ""), - posX + textOffsetX, - posY + textOffsetY - ) + posX + textOffsetX, + posY + textOffsetY + ) + } // durability metre diff --git a/src/net/torvald/terrarum/blockproperties/BlockCodex.kt b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt index bc50ae7fc..3320a9a47 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockCodex.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt @@ -2,6 +2,7 @@ package net.torvald.terrarum.blockproperties import com.badlogic.gdx.graphics.Color import net.torvald.terrarum.AppLoader +import net.torvald.terrarum.AppLoader.printmsg import net.torvald.terrarum.gameworld.FluidType import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.MapLayer @@ -33,7 +34,7 @@ object BlockCodex { try { val records = CSVFetcher.readFromModule(module, path) - AppLoader.printdbg(this, "Building block properties table") + AppLoader.printmsg(this, "Building block properties table") records.forEach { /*if (intVal(it, "id") == -1) { @@ -136,8 +137,7 @@ object BlockCodex { blockProps[key] = prop - print("${intVal(record, "id")}") - println("\t" + prop.nameKey) + printmsg(this, "${intVal(record, "id")}\t" + prop.nameKey) } } diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index 1658dc4dc..6a980f71b 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -44,11 +44,15 @@ open class GameWorld { val loadTime: Long = System.currentTimeMillis() / 1000L //layers + @TEMzPayload("WALL", TEMzPayload.EIGHT_MSB) val layerWall: MapLayer + @TEMzPayload("TERR", TEMzPayload.EIGHT_MSB) val layerTerrain: MapLayer //val layerWire: MapLayer + @TEMzPayload("WALL", TEMzPayload.FOUR_LSB) val layerWallLowBits: PairedMapLayer + @TEMzPayload("TERR", TEMzPayload.FOUR_LSB) val layerTerrainLowBits: PairedMapLayer //val layerThermal: MapLayerHalfFloat // in Kelvins @@ -59,11 +63,17 @@ open class GameWorld { /** Tilewise spawn point */ var spawnY: Int + @TEMzPayload("WdMG", TEMzPayload.INT48_FLOAT_PAIR) val wallDamages: HashMap + @TEMzPayload("TdMG", TEMzPayload.INT48_FLOAT_PAIR) val terrainDamages: HashMap + @TEMzPayload("FlTP", TEMzPayload.INT48_SHORT_PAIR) val fluidTypes: HashMap + @TEMzPayload("FlFL", TEMzPayload.INT48_FLOAT_PAIR) val fluidFills: HashMap + @TEMzPayload("CtYP", TEMzPayload.INT48_INT_PAIR) val conduitTypes: HashMap // 1 bit = 1 conduit (pipe/wire) type + @TEMzPayload("CfL", TEMzPayload.INT48_FLOAT_PAIR) val conduitFills: Array> val conduitFills0: HashMap // size of liquid packet on the block get() = conduitFills[0] @@ -483,4 +493,21 @@ infix fun Float.fmod(other: Float) = if (this >= 0f) this % other else (this % o inline class FluidType(val value: Int) { infix fun sameAs(other: FluidType) = this.value.absoluteValue == other.value.absoluteValue fun abs() = this.value.absoluteValue -} \ No newline at end of file +} + +/** + * @param payloadName Payload name defined in Map Data Format.txt + * * 4 Letters: regular payload + * * 3 Letters: only valid for arrays with 16 elements, names are auto-generated by appending '0'..'9'+'a'..'f'. E.g.: 'CfL' turns into 'CfL0', 'CfL1' ... 'CfLe', 'CfLf' + * + * @param arg 0 for 8 MSBs of Terrain/Wall layer, 1 for 4 LSBs of Terrain/Wall layer, 2 for Int48-Float pair, 3 for Int48-Short pair, 4 for Int48-Int pair + */ +annotation class TEMzPayload(val payloadName: String, val arg: Int) { + companion object { + const val EIGHT_MSB = 0 + const val FOUR_LSB = 1 + const val INT48_FLOAT_PAIR = 2 + const val INT48_SHORT_PAIR = 3 + const val INT48_INT_PAIR = 4 + } +} diff --git a/src/net/torvald/terrarum/itemproperties/Material.kt b/src/net/torvald/terrarum/itemproperties/Material.kt index 32246f5da..bc20269a5 100644 --- a/src/net/torvald/terrarum/itemproperties/Material.kt +++ b/src/net/torvald/terrarum/itemproperties/Material.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.itemproperties -import net.torvald.terrarum.AppLoader.printdbg +import net.torvald.terrarum.AppLoader.printmsg import net.torvald.terrarum.blockproperties.floatVal import net.torvald.terrarum.blockproperties.intVal import net.torvald.terrarum.utils.CSVFetcher @@ -22,6 +22,8 @@ class Material { //var armourMod: Float // multiplier. Copper as 1.0 var durability: Int = 0 // tools only + + var identifier: String = "Name not set" } object MaterialCodex { @@ -33,17 +35,20 @@ object MaterialCodex { try { val records = CSVFetcher.readFromModule(module, path) - printdbg(this, "Building materials table") + printmsg(this, "Building materials table") records.forEach { val prop = Material() prop.strength = intVal(it, "tens") prop.density = intVal(it, "dsty") - prop.forceMod = intVal(it, "forcemod") + prop.forceMod = intVal(it, "fmod") prop.enduranceMod = floatVal(it, "endurance") prop.thermalConductivity = floatVal(it, "tcond") + prop.identifier = it.get("idst").toUpperCase() - materialProps[it.get("idst").toUpperCase()] = prop + materialProps[prop.identifier] = prop + + printmsg(this, "${prop.identifier}\t${prop.strength}\t${prop.density}\t${prop.forceMod}\t${prop.enduranceMod}") } } catch (e: IOException) { @@ -51,6 +56,13 @@ object MaterialCodex { } } - operator fun get(identifier: String) = materialProps[identifier.toUpperCase()] ?: nullMaterial + operator fun get(identifier: String) = try { + materialProps[identifier.toUpperCase()]!! + } + catch (e: NullPointerException) { + throw NullPointerException("Material with id $identifier does not exist.") + } + + fun getOrDefault(identifier: String) = materialProps[identifier.toUpperCase()] ?: nullMaterial } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt b/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt index ea57b3c54..63ef1defd 100644 --- a/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt +++ b/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt @@ -64,7 +64,7 @@ class EntryPoint : ModuleEntryPoint() { override var stackable = true override var inventoryCategory = if (i in ItemCodex.ITEM_TILES) Category.BLOCK else Category.WALL override var isDynamic = false - override val material = MaterialCodex[blockProp.material] + override val material = MaterialCodex.getOrDefault(blockProp.material) init { equipPosition = EquipPosition.HAND_GRIP diff --git a/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt b/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt index 69b0aeeed..fc5a5a034 100644 --- a/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt +++ b/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt @@ -81,7 +81,7 @@ class PickaxeCopper(override val originalID: ItemID) : GameItem() { override var inventoryCategory = Category.TOOL override val isUnique = false override val isDynamic = true - override var material = MaterialCodex["CUPR"] + override val material = MaterialCodex["CUPR"] override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE override val itemImage: TextureRegion? get() = (AppLoader.resourcePool["basegame.items24"] as TextureRegionPack).get(0,0) @@ -109,7 +109,7 @@ class PickaxeIron(override val originalID: ItemID) : GameItem() { override var inventoryCategory = Category.TOOL override val isUnique = false override val isDynamic = true - override var material = MaterialCodex["IRON"] + override val material = MaterialCodex["IRON"] override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE override val itemImage: TextureRegion? get() = (AppLoader.resourcePool["basegame.items24"] as TextureRegionPack).get(1,0) @@ -137,7 +137,7 @@ class PickaxeSteel(override val originalID: ItemID) : GameItem() { override var inventoryCategory = Category.TOOL override val isUnique = false override val isDynamic = true - override var material = MaterialCodex["STAL"] + override val material = MaterialCodex["STAL"] override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE override val itemImage: TextureRegion? get() = (AppLoader.resourcePool["basegame.items24"] as TextureRegionPack).get(2,0) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt index 743f7b9ff..51486d142 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt @@ -287,7 +287,14 @@ class UIItemInventoryDynamicList( // set tooltip accordingly if (isCompactMode && it.mouseUp && !tooltipSet) { - (Terrarum.ingame as? Ingame)?.setTooltipMessage(it.item?.name) + (Terrarum.ingame as? Ingame)?.setTooltipMessage( + if (AppLoader.IS_DEVELOPMENT_BUILD) { + it.item?.name + "/Mat: ${it.item?.material?.identifier}" + } + else { + it.item?.name + } + ) tooltipSet = true } } diff --git a/src/net/torvald/terrarum/serialise/WriteLayerDataZip.kt b/src/net/torvald/terrarum/serialise/WriteLayerDataZip.kt index 9a3875808..9eec29e66 100644 --- a/src/net/torvald/terrarum/serialise/WriteLayerDataZip.kt +++ b/src/net/torvald/terrarum/serialise/WriteLayerDataZip.kt @@ -1,5 +1,6 @@ package net.torvald.terrarum.serialise +import net.torvald.terrarum.AppLoader.printdbg import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.ByteArray64 import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.ByteArray64GrowableOutputStream @@ -105,6 +106,10 @@ internal object WriteLayerDataZip { // TODO serialised payloads have bit too much zeros, should I be worried? + val savePayloads = world.javaClass.superclass.declaredFields//.filter { it.isAnnotationPresent(TEMzPayload::class.java) } + printdbg(this, "") + savePayloads.forEach { printdbg(this, "${it.name}: ${it.type} @${it.declaredAnnotations.size}") } + wb(PAYLOAD_HEADER); wb("TERR".toByteArray()) wi48(world.width * world.height * 3L / 2) deflater = DeflaterOutputStream(outputStream, Deflater(Deflater.BEST_COMPRESSION, true), false)