game item to load its own image if needed; common resource pool to assist that

This commit is contained in:
minjaesong
2019-03-10 17:46:48 +09:00
parent d895da9e96
commit 833d8814a7
21 changed files with 197 additions and 66 deletions

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.itemproperties
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.random.HQRNG
import net.torvald.terrarum.ItemValue
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC
@@ -82,6 +83,12 @@ abstract class GameItem : Comparable<GameItem>, Cloneable {
abstract val material: Material
/**
* Don't assign! Create getter -- there's inevitable execution order fuckup on ModMgr,
* where it simultaneously wanted to be called before and after the Mod's EntryPoint if you assign value to it on init block.
*/
@Transient open val itemImage: TextureRegion? = null
/**
* Apparent mass of the item. (basemass * scale^3)
*/
@@ -168,12 +175,12 @@ abstract class GameItem : Comparable<GameItem>, Cloneable {
open fun endSecondaryUse(delta: Float): Boolean = false
/**
* Effects applied immediately only once if thrown from pocket
* Effects applied immediately only once if thrown (discarded) from pocket
*/
open fun effectWhenThrown(delta: Float) { }
/**
* Effects applied (continuously or not) when equipped (drawn)
* Effects applied (continuously or not) when equipped (drawn/pulled out)
*/
open fun effectWhenEquipped(delta: Float) { }
@@ -291,6 +298,8 @@ abstract class GameItem : Comparable<GameItem>, Cloneable {
return ret
}
val NULL_MATERIAL = Material(0,0,0,0,0,0,0,0,1,0.0)
}
}

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.itemproperties
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.AppLoader.printdbg
@@ -10,6 +9,7 @@ import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.CanBeAnItem
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.util.*
/**
@@ -31,7 +31,8 @@ object ItemCodex {
val ITEM_DYNAMIC = 0x10_0000..0x0FFF_FFFF
val ACTORID_MIN = ITEM_DYNAMIC.endInclusive + 1
private val itemImagePlaceholder = TextureRegion(Texture("./assets/item_kari_24.tga"))
private val itemImagePlaceholder: TextureRegion
get() = (AppLoader.resourcePool["basegame.items24"] as TextureRegionPack).get(0,0) // copper pickaxe
//private val ingame = Terrarum.ingame!! as Ingame // WARNING you can't put this here, ExceptionInInitializerError
@@ -294,12 +295,11 @@ object ItemCodex {
)
}
// wire
else if (itemOriginalID in ITEM_WIRES) {
/*else if (itemOriginalID in ITEM_WIRES) {
return BlocksDrawer.tilesWire.get((itemOriginalID % 16) * 16, itemOriginalID / 16)
}
// TODO get it real, using originalID...?
}*/
else
return itemImagePlaceholder
return itemCodex[itemOriginalID]?.itemImage ?: itemImagePlaceholder
}
fun hasItem(itemID: Int): Boolean = dynamicItemDescription.containsKey(itemID)