can retrieve item image for dynamic items

This commit is contained in:
minjaesong
2019-03-12 01:15:57 +09:00
parent 1ac735805d
commit 58a91ed10b
4 changed files with 20 additions and 12 deletions

View File

@@ -22,6 +22,7 @@ object ItemCodex {
*/
val itemCodex = HashMap<ItemID, GameItem>()
val dynamicItemDescription = HashMap<ItemID, GameItem>()
val dynamicToStaticTable = HashMap<ItemID, ItemID>()
val ITEM_TILES = 0..GameWorld.TILES_SUPPORTED - 1
val ITEM_WALLS = GameWorld.TILES_SUPPORTED..GameWorld.TILES_SUPPORTED * 2 - 1
@@ -242,6 +243,7 @@ object ItemCodex {
printdbg(this, "Registering new dynamic item $dynamicID (from ${item.originalID})")
}
dynamicItemDescription[dynamicID] = item
dynamicToStaticTable[dynamicID] = item.originalID
}
/**
@@ -265,6 +267,8 @@ object ItemCodex {
}
}
fun dynamicToStaticID(dynamicID: ItemID) = dynamicToStaticTable[dynamicID]!!
/**
* Mainly used by GameItemLoader
*/
@@ -279,8 +283,12 @@ object ItemCodex {
}
fun getItemImage(itemOriginalID: Int): TextureRegion {
// dynamic item
if (itemOriginalID in ITEM_DYNAMIC) {
return getItemImage(dynamicToStaticID(itemOriginalID))
}
// terrain
if (itemOriginalID in ITEM_TILES) {
else if (itemOriginalID in ITEM_TILES) {
return BlocksDrawer.tileItemTerrain.get(
itemOriginalID % 16,
itemOriginalID / 16

View File

@@ -77,7 +77,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
// If we already have the item, increment the amount
// If not, add item with specified amount
val existingItem = getByDynamicID(item.dynamicID)
val existingItem = invSearchByDynamicID(item.dynamicID)
// if the item already exists
if (existingItem != null) {
@@ -106,7 +106,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
val existingItem = getByDynamicID(item.dynamicID)
val existingItem = invSearchByDynamicID(item.dynamicID)
if (existingItem != null) { // if the item already exists
val newCount = existingItem.amount - count
@@ -133,7 +133,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
quickSlot[slot] = dynamicID
}
fun getQuickslot(slot: Int): InventoryPair? = getByDynamicID(quickSlot[slot])
fun getQuickslot(slot: Int): InventoryPair? = invSearchByDynamicID(quickSlot[slot])
/**
* HashMap<GameItem, Amounts>
@@ -198,7 +198,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
newItem.stackable = false
add(newItem)
itemEquipped[newItem.equipPosition] = getByDynamicID(newItem.dynamicID)!!.item // will test if some sketchy code is written. Test fail: kotlinNullpointerException
itemEquipped[newItem.equipPosition] = newItem.dynamicID //invSearchByDynamicID(newItem.dynamicID)!!.item // will test if some sketchy code is written. Test fail: kotlinNullpointerException
// FIXME now damage meter (vital) is broken
}
@@ -236,7 +236,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
false
else
itemList.binarySearch(id, DYNAMIC_ID) >= 0
fun getByDynamicID(id: ItemID?): InventoryPair? {
fun invSearchByDynamicID(id: ItemID?): InventoryPair? {
if (itemList.size == 0 || id == null)
return null
@@ -246,8 +246,8 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
else
return itemList[index]
}
private fun getByStaticID(id: ItemID): InventoryPair? {
if (itemList.size == 0)
private fun invSearchByStaticID(id: ItemID?): InventoryPair? {
if (itemList.size == 0 || id == null)
return null
val index = itemList.binarySearch(id, STATIC_ID)
@@ -269,7 +269,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
}
@Transient private val STATIC_ID = 41324534
@Transient private val DYNAMIC_ID = 181643953
private fun ArrayList<InventoryPair>.binarySearch(ID: ItemID, searchBy: Int): Int {
private fun ArrayList<InventoryPair>.binarySearch(ID: ItemID, searchMode: Int): Int {
// code from collections/Collections.kt
var low = 0
var high = this.size - 1
@@ -277,7 +277,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
while (low <= high) {
val mid = (low + high).ushr(1) // safe from overflows
val midVal = if (searchBy == STATIC_ID)
val midVal = if (searchMode == STATIC_ID)
ItemCodex[this[mid].item]!!.originalID
else
ItemCodex[this[mid].item]!!.dynamicID

View File

@@ -19,7 +19,7 @@ object AmmoMeterProxy {
else {
meter.vitalGetterVal = {
if (currentItem.stackable && currentItem.maxDurability == GameItem.DURABILITY_NA) {
actor.inventory.getByDynamicID(currentItem.dynamicID)!!.amount.toFloat()
actor.inventory.invSearchByDynamicID(currentItem.dynamicID)!!.amount.toFloat()
}
else
currentItem.durability

View File

@@ -132,7 +132,7 @@ class UIItemInventoryEquippedView(
itemGrid[k].equippedSlot = null
}
else {
val itemRecord = inventory.getByDynamicID(item)!!
val itemRecord = inventory.invSearchByDynamicID(item)!!
itemGrid[k].item = ItemCodex[item]
itemGrid[k].amount = itemRecord.amount