more canisters

This commit is contained in:
minjaesong
2025-04-29 22:59:26 +09:00
parent 488a214a19
commit 5495e017d5
6 changed files with 93 additions and 2 deletions

View File

@@ -173,10 +173,10 @@ id;classname;tags
65536;net.torvald.terrarum.modulebasegame.gameitems.ItemFileRef;BASEOBJECT
# fluids on storage
# FUTURE QUEST: autogenerate them using CONTAINERS CODEX
# FUTURE QUEST: autogenerate them using CANISTERS CODEX
# with new ItemID scheme:
# basegame_2<fluid@basegame:1
# stands for a wooden bucket (CONTAINERS basegame_2) holding a block of water (fluid@basegame:1)
# stands for a wooden bucket (CANISTERS basegame_2) holding a block of water (fluid@basegame:1)
#
# FLUIDSTORAGE: required tag for buckets/canisters
# OPENSTORAGE: cannot hold gas. Canisters need LIDDEDSTORAGE/SEALEDSTORAGE
1 id classname tags
173 #1048577 net.torvald.terrarum.modulebasegame.gameitems.ItemBucketWooden01 FLUIDSTORAGE,OPENSTORAGE,NOEXTREMETHERM
174 ##1048578 net.torvald.terrarum.modulebasegame.gameitems.ItemBucketWooden02 FLUIDSTORAGE,OPENSTORAGE,NOEXTREMETHERM
175 #1048579 net.torvald.terrarum.modulebasegame.gameitems.ItemBucketWooden03 FLUIDSTORAGE,OPENSTORAGE,NOEXTREMETHERM
176 #
177 #1048832 net.torvald.terrarum.modulebasegame.gameitems.ItemBucketIron00 FLUIDSTORAGE,OPENSTORAGE,FLUIDSTORAGEEMPTY
178 #1048833 net.torvald.terrarum.modulebasegame.gameitems.ItemBucketIron01 FLUIDSTORAGE,OPENSTORAGE
179 #1048834 net.torvald.terrarum.modulebasegame.gameitems.ItemBucketIron02 FLUIDSTORAGE,OPENSTORAGE
180 #1048835 net.torvald.terrarum.modulebasegame.gameitems.ItemBucketIron03 FLUIDSTORAGE,OPENSTORAGE
181 #
182 ## reserved for debug items

View File

@@ -14,6 +14,7 @@ import net.torvald.terrarum.gamecontroller.IME
import net.torvald.terrarum.gameitems.FixtureInteractionBlocked
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.itemproperties.CanistersCodex
import net.torvald.terrarum.itemproperties.CraftingCodex
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.MaterialCodex
@@ -942,6 +943,18 @@ object ModMgr {
watchdogs["$moduleName.${watchdog.javaClass.simpleName}"] = watchdog
}
}
object GameCanistersLoader {
const val canisterPath = "canisters/"
init {
Terrarum.canistersCodex = CanistersCodex()
}
@JvmStatic operator fun invoke(module: String) {
Terrarum.canistersCodex.fromModule(module, canisterPath + "canisters.csv")
}
}
}
private class JarFileLoader(urls: Array<URL>) : URLClassLoader(urls) {

View File

@@ -28,6 +28,7 @@ import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.ActorWithBody.Companion.METER
import net.torvald.terrarum.gameactors.faction.FactionCodex
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.itemproperties.CanistersCodex
import net.torvald.terrarum.itemproperties.CraftingCodex
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.MaterialCodex
@@ -86,6 +87,7 @@ object Terrarum : Disposable {
var oreCodex = OreCodex(); internal set
var audioCodex = AudioCodex(); internal set
var weatherCodex = WeatherCodex(); internal set
var canistersCodex = CanistersCodex(); internal set
//////////////////////////////

View File

@@ -0,0 +1,75 @@
package net.torvald.terrarum.itemproperties
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.blockproperties.intVal
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.utils.CSVFetcher
import org.apache.commons.csv.CSVRecord
import java.io.IOException
/**
* Created by minjaesong on 2025-04-29.
*/
class CanistersCodex {
@Transient val CanisterProps = HashMap<ItemID, CanisterProp>() // itemID is <modulename>_<index>
@Transient private val nullProp = CanisterProp()
operator fun get(canister: ItemID?): CanisterProp {
if (canister == null || canister.substringAfter('_').substringBefore(':').substringBefore('@') == "0") {
return nullProp
}
try {
return CanisterProps[canister]!!
}
catch (e: NullPointerException) {
throw NullPointerException("CanisterProp with id $canister does not exist.")
}
}
fun getOrNull(blockID: ItemID?): CanisterProp? {
return CanisterProps[blockID]
}
/**
* Later entry (possible from other modules) will replace older ones
*/
fun fromModule(module: String, path: String, registerHook: (CanisterProp) -> Unit = {}) {
printdbg(this, "Building fluid properties table")
try {
register(module, CSVFetcher.readFromModule(module, path), registerHook)
}
catch (e: IOException) { e.printStackTrace() }
}
private fun register(module: String, records: List<CSVRecord>, registerHook: (CanisterProp) -> Unit) {
records.forEach {
setProp(module, it.intVal("id"), it)
val tileId = "${module}_${it.intVal("id")}"
CanisterProps[tileId]?.let(registerHook)
}
}
private fun setProp(module: String, key: Int, record: CSVRecord) {
val prop = CanisterProp()
prop.tags = record.get("tags").split(',').map { it.trim().toUpperCase() }.toHashSet()
prop.id = "${module}_$key"
prop.itemID = record.get("itemid")
CanisterProps[prop.id] = prop
printdbg(this, "Setting canister prop ${prop.id}")
}
}
/**
* Created by minjaesong on 2025-04-29.
*/
class CanisterProp {
var id: ItemID = ""
var itemID: ItemID = ""
@Transient var tags = HashSet<String>()
}

View File

@@ -50,6 +50,7 @@ class EntryPoint : ModuleEntryPoint() {
ModMgr.GameLanguageLoader.invoke(moduleName)
ModMgr.GameAudioLoader.invoke(moduleName)
ModMgr.GameWeatherLoader.invoke(moduleName)
ModMgr.GameCanistersLoader.invoke(moduleName)
WeatherCodex.weatherById["titlescreen"] =
WeatherCodex.getById("generic01")?.copy(identifier = "titlescreen", windSpeed = 1f) ?: WeatherMixer.DEFAULT_WEATHER