mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-16 00:26:07 +09:00
GameBlockLoader registering TileItem and Tile-to-Wall recipe by itself
This commit is contained in:
@@ -8,15 +8,19 @@ import net.torvald.terrarum.App.*
|
|||||||
import net.torvald.terrarum.App.setToGameConfig
|
import net.torvald.terrarum.App.setToGameConfig
|
||||||
import net.torvald.terrarum.audio.AudioCodex
|
import net.torvald.terrarum.audio.AudioCodex
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
|
import net.torvald.terrarum.blockproperties.BlockProp
|
||||||
import net.torvald.terrarum.blockproperties.OreCodex
|
import net.torvald.terrarum.blockproperties.OreCodex
|
||||||
import net.torvald.terrarum.blockproperties.WireCodex
|
import net.torvald.terrarum.blockproperties.WireCodex
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gamecontroller.IME
|
import net.torvald.terrarum.gamecontroller.IME
|
||||||
import net.torvald.terrarum.gameitems.GameItem
|
import net.torvald.terrarum.gameitems.GameItem
|
||||||
import net.torvald.terrarum.gameitems.ItemID
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
|
import net.torvald.terrarum.itemproperties.CraftingCodex
|
||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.itemproperties.MaterialCodex
|
import net.torvald.terrarum.itemproperties.MaterialCodex
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameitems.BlockBase
|
||||||
import net.torvald.terrarum.modulebasegame.worldgenerator.OregenParams
|
import net.torvald.terrarum.modulebasegame.worldgenerator.OregenParams
|
||||||
import net.torvald.terrarum.modulebasegame.worldgenerator.Worldgen
|
import net.torvald.terrarum.modulebasegame.worldgenerator.Worldgen
|
||||||
import net.torvald.terrarum.serialise.Common
|
import net.torvald.terrarum.serialise.Common
|
||||||
@@ -531,9 +535,75 @@ object ModMgr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic operator fun invoke(module: String) {
|
@JvmStatic operator fun invoke(module: String) {
|
||||||
Terrarum.blockCodex.fromModule(module, "blocks/blocks.csv")
|
Terrarum.blockCodex.fromModule(module, "blocks/blocks.csv") { tile ->
|
||||||
|
// register blocks as items
|
||||||
|
ItemCodex[tile.id] = makeNewItemObj(tile, false)
|
||||||
|
|
||||||
|
if (IS_DEVELOPMENT_BUILD) print(tile.id+" ")
|
||||||
|
|
||||||
|
if (BlockCodex[tile.id].isWallable) {
|
||||||
|
ItemCodex["wall@" + tile.id] = makeNewItemObj(tile, true).also {
|
||||||
|
it.tags.add("WALL")
|
||||||
|
}
|
||||||
|
if (IS_DEVELOPMENT_BUILD) print("wall@" + tile.id + " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// crafting recipes: tile -> 2x wall
|
||||||
|
if (tile.isWallable && tile.isSolid && !tile.isActorBlock) {
|
||||||
|
CraftingRecipeCodex.addRecipe(
|
||||||
|
CraftingCodex.CraftingRecipe(
|
||||||
|
"",
|
||||||
|
arrayOf(
|
||||||
|
CraftingCodex.CraftingIngredients(
|
||||||
|
tile.id, CraftingCodex.CraftingItemKeyMode.VERBATIM, 1
|
||||||
|
)),
|
||||||
|
2,
|
||||||
|
"wall@"+tile.id,
|
||||||
|
module
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
Terrarum.wireCodex.fromModule(module, "wires/")
|
Terrarum.wireCodex.fromModule(module, "wires/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun makeNewItemObj(tile: BlockProp, isWall: Boolean) = object : GameItem(
|
||||||
|
if (isWall) "wall@"+tile.id else tile.id
|
||||||
|
) {
|
||||||
|
override var baseMass: Double = tile.density / 100.0
|
||||||
|
override var baseToolSize: Double? = null
|
||||||
|
override var inventoryCategory = if (isWall) Category.WALL else Category.BLOCK
|
||||||
|
override var isDynamic = false
|
||||||
|
override val materialId = tile.material
|
||||||
|
override var equipPosition = EquipPosition.HAND_GRIP
|
||||||
|
// override val itemImage: TextureRegion
|
||||||
|
// get() {
|
||||||
|
// val itemSheetNumber = App.tileMaker.tileIDtoItemSheetNumber(originalID)
|
||||||
|
// val bucket = if (isWall) BlocksDrawer.tileItemWall else BlocksDrawer.tileItemTerrain
|
||||||
|
// return bucket.get(
|
||||||
|
// itemSheetNumber % App.tileMaker.ITEM_ATLAS_TILES_X,
|
||||||
|
// itemSheetNumber / App.tileMaker.ITEM_ATLAS_TILES_X
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
|
||||||
|
init {
|
||||||
|
tags.addAll(tile.tags)
|
||||||
|
originalName =
|
||||||
|
if (isWall && tags.contains("UNLIT")) "${tile.nameKey}>>=BLOCK_UNLIT_TEMPLATE>>=BLOCK_WALL_NAME_TEMPLATE"
|
||||||
|
else if (isWall) "${tile.nameKey}>>=BLOCK_WALL_NAME_TEMPLATE"
|
||||||
|
else if (tags.contains("UNLIT")) "${tile.nameKey}>>=BLOCK_UNLIT_TEMPLATE"
|
||||||
|
else tile.nameKey
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long {
|
||||||
|
return BlockBase.blockStartPrimaryUse(actor, this, dynamicID, delta)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
||||||
|
BlockBase.blockEffectWhenEquipped(actor, delta)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object GameOreLoader {
|
object GameOreLoader {
|
||||||
|
|||||||
@@ -55,15 +55,15 @@ class BlockCodex {
|
|||||||
/**
|
/**
|
||||||
* Later entry (possible from other modules) will replace older ones
|
* Later entry (possible from other modules) will replace older ones
|
||||||
*/
|
*/
|
||||||
fun fromModule(module: String, path: String) {
|
fun fromModule(module: String, path: String, blockRegisterHook: (BlockProp) -> Unit) {
|
||||||
printdbg(this, "Building block properties table")
|
printdbg(this, "Building block properties table")
|
||||||
try {
|
try {
|
||||||
register(module, CSVFetcher.readFromModule(module, path))
|
register(module, CSVFetcher.readFromModule(module, path), blockRegisterHook)
|
||||||
}
|
}
|
||||||
catch (e: IOException) { e.printStackTrace() }
|
catch (e: IOException) { e.printStackTrace() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fromCSV(module: String, csvString: String) {
|
fun fromCSV(module: String, csvString: String, blockRegisterHook: (BlockProp) -> Unit) {
|
||||||
printdbg(this, "Building block properties table for module $module")
|
printdbg(this, "Building block properties table for module $module")
|
||||||
|
|
||||||
val csvParser = org.apache.commons.csv.CSVParser.parse(
|
val csvParser = org.apache.commons.csv.CSVParser.parse(
|
||||||
@@ -73,10 +73,10 @@ class BlockCodex {
|
|||||||
val csvRecordList = csvParser.records
|
val csvRecordList = csvParser.records
|
||||||
csvParser.close()
|
csvParser.close()
|
||||||
|
|
||||||
register(module, csvRecordList)
|
register(module, csvRecordList, blockRegisterHook)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun register(module: String, records: List<CSVRecord>) {
|
private fun register(module: String, records: List<CSVRecord>, blockRegisterHook: (BlockProp) -> Unit) {
|
||||||
records.forEach {
|
records.forEach {
|
||||||
/*if (it.intVal("id") == -1) {
|
/*if (it.intVal("id") == -1) {
|
||||||
setProp(nullProp, it)
|
setProp(nullProp, it)
|
||||||
@@ -107,6 +107,9 @@ class BlockCodex {
|
|||||||
}
|
}
|
||||||
tileToVirtual[tileId] = virtualChunk.sorted().toList()
|
tileToVirtual[tileId] = virtualChunk.sorted().toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
blockProps[tileId]?.let(blockRegisterHook)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,81 +56,9 @@ class EntryPoint : ModuleEntryPoint() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////
|
|
||||||
// load customised item loader //
|
|
||||||
/////////////////////////////////
|
|
||||||
|
|
||||||
printdbg(this, "recording item ID ")
|
|
||||||
|
|
||||||
// blocks.csvs are loaded by ModMgr beforehand
|
|
||||||
// register blocks as items
|
|
||||||
for (tile in BlockCodex.getAll()) {
|
|
||||||
ItemCodex[tile.id] = makeNewItemObj(tile, false)
|
|
||||||
|
|
||||||
if (IS_DEVELOPMENT_BUILD) print(tile.id+" ")
|
|
||||||
|
|
||||||
if (BlockCodex[tile.id].isWallable) {
|
|
||||||
ItemCodex["wall@" + tile.id] = makeNewItemObj(tile, true).also {
|
|
||||||
it.tags.add("WALL")
|
|
||||||
}
|
|
||||||
if (IS_DEVELOPMENT_BUILD) print("wall@" + tile.id + " ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// crafting recipes: tile -> 2x wall
|
|
||||||
BlockCodex.getAll().filter { it.isWallable && it.isSolid && !it.isActorBlock }.forEach { tile ->
|
|
||||||
CraftingRecipeCodex.addRecipe(CraftingCodex.CraftingRecipe(
|
|
||||||
"",
|
|
||||||
arrayOf(CraftingCodex.CraftingIngredients(
|
|
||||||
tile.id, CraftingCodex.CraftingItemKeyMode.VERBATIM, 1
|
|
||||||
)),
|
|
||||||
2,
|
|
||||||
"wall@"+tile.id,
|
|
||||||
moduleName
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
println("\n[Basegame.EntryPoint] Welcome back!")
|
println("\n[Basegame.EntryPoint] Welcome back!")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun makeNewItemObj(tile: BlockProp, isWall: Boolean) = object : GameItem(
|
|
||||||
if (isWall) "wall@"+tile.id else tile.id
|
|
||||||
) {
|
|
||||||
override var baseMass: Double = tile.density / 100.0
|
|
||||||
override var baseToolSize: Double? = null
|
|
||||||
override var inventoryCategory = if (isWall) Category.WALL else Category.BLOCK
|
|
||||||
override var isDynamic = false
|
|
||||||
override val materialId = tile.material
|
|
||||||
override var equipPosition = EquipPosition.HAND_GRIP
|
|
||||||
// override val itemImage: TextureRegion
|
|
||||||
// get() {
|
|
||||||
// val itemSheetNumber = App.tileMaker.tileIDtoItemSheetNumber(originalID)
|
|
||||||
// val bucket = if (isWall) BlocksDrawer.tileItemWall else BlocksDrawer.tileItemTerrain
|
|
||||||
// return bucket.get(
|
|
||||||
// itemSheetNumber % App.tileMaker.ITEM_ATLAS_TILES_X,
|
|
||||||
// itemSheetNumber / App.tileMaker.ITEM_ATLAS_TILES_X
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
|
|
||||||
init {
|
|
||||||
tags.addAll(tile.tags)
|
|
||||||
originalName =
|
|
||||||
if (isWall && tags.contains("UNLIT")) "${tile.nameKey}>>=BLOCK_UNLIT_TEMPLATE>>=BLOCK_WALL_NAME_TEMPLATE"
|
|
||||||
else if (isWall) "${tile.nameKey}>>=BLOCK_WALL_NAME_TEMPLATE"
|
|
||||||
else if (tags.contains("UNLIT")) "${tile.nameKey}>>=BLOCK_UNLIT_TEMPLATE"
|
|
||||||
else tile.nameKey
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long {
|
|
||||||
return BlockBase.blockStartPrimaryUse(actor, this, dynamicID, delta)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
|
||||||
BlockBase.blockEffectWhenEquipped(actor, delta)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
WatchFont.dispose()
|
WatchFont.dispose()
|
||||||
|
|||||||
Reference in New Issue
Block a user