walls now work

This commit is contained in:
minjaesong
2021-02-25 11:11:47 +09:00
parent 5f16f71b0a
commit 795f0ab853
3 changed files with 18 additions and 15 deletions

View File

@@ -55,9 +55,13 @@ class EntryPoint : ModuleEntryPoint() {
// block items (blocks and walls are the same thing basically)
for (tile in BlockCodex.getAll()) {
ItemCodex[tile.id] = makeNewItemObj(tile, false)
if (IS_DEVELOPMENT_BUILD) print(tile.id+" ")
ItemCodex["wall@"+tile.id] = makeNewItemObj(tile, true)
if (IS_DEVELOPMENT_BUILD) print("wall@"+tile.id+" ")
if (BlockCodex[tile.id].isWallable) {
ItemCodex["wall@" + tile.id] = makeNewItemObj(tile, true)
if (IS_DEVELOPMENT_BUILD) print("wall@" + tile.id + " ")
}
}
@@ -65,7 +69,9 @@ class EntryPoint : ModuleEntryPoint() {
println("[Basegame.EntryPoint] Welcome back!")
}
private fun makeNewItemObj(tile: BlockProp, isWall: Boolean) = object : GameItem(tile.id) {
private fun makeNewItemObj(tile: BlockProp, isWall: Boolean) = object : GameItem(
if (isWall) "wall@"+tile.id else tile.id
) {
override val isUnique: Boolean = false
override var baseMass: Double = tile.density / 1000.0
override var baseToolSize: Double? = null
@@ -80,7 +86,7 @@ class EntryPoint : ModuleEntryPoint() {
}
override fun startPrimaryUse(delta: Float): Boolean {
return BlockBase.blockStartPrimaryUse(this, tile.id, delta)
return BlockBase.blockStartPrimaryUse(this, dynamicID, delta)
}
override fun effectWhenEquipped(delta: Float) {

View File

@@ -45,18 +45,15 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
init {
}
fun add(itemID: ItemID, count: Int = 1) = if (ItemCodex[itemID] == null) throw NullPointerException("Item not found: "+itemID) else add(ItemCodex[itemID]!!, count)
fun add(itemID: ItemID, count: Int = 1) {
if (ItemCodex[itemID] == null)
throw NullPointerException("Item not found: $itemID")
else
add(ItemCodex[itemID]!!, count)
}
fun add(item: GameItem, count: Int = 1) {
println("[ActorInventory] add $item, $count")
// not wall-able walls
if (item.inventoryCategory == GameItem.Category.WALL &&
(!item.dynamicID.startsWith("wall@") || !BlockCodex[item.dynamicID.substring(5)].isWallable)) {
throw IllegalArgumentException("Wall ID ${item.dynamicID} is not wall-able.")
}
println("[ActorInventory] add-by-elem $item, $count")
// other invalid values
if (count == 0)

View File

@@ -78,7 +78,7 @@ object PlayerBuilderSigrid {
CreateTileAtlas.tags.forEach { t, _ ->
inventory.add(t, 9995)
try {
inventory.add("wall@"+t, 9995)
inventory.add("wall@"+t, 9995) // this code will try to add nonexisting wall items, do not get surprised with NPEs
}
catch (e: Throwable) {
System.err.println("[PlayerBuilder] $e")