mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-15 08:06:06 +09:00
can retrieve item image for dynamic items
This commit is contained in:
@@ -22,6 +22,7 @@ object ItemCodex {
|
|||||||
*/
|
*/
|
||||||
val itemCodex = HashMap<ItemID, GameItem>()
|
val itemCodex = HashMap<ItemID, GameItem>()
|
||||||
val dynamicItemDescription = HashMap<ItemID, GameItem>()
|
val dynamicItemDescription = HashMap<ItemID, GameItem>()
|
||||||
|
val dynamicToStaticTable = HashMap<ItemID, ItemID>()
|
||||||
|
|
||||||
val ITEM_TILES = 0..GameWorld.TILES_SUPPORTED - 1
|
val ITEM_TILES = 0..GameWorld.TILES_SUPPORTED - 1
|
||||||
val ITEM_WALLS = GameWorld.TILES_SUPPORTED..GameWorld.TILES_SUPPORTED * 2 - 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})")
|
printdbg(this, "Registering new dynamic item $dynamicID (from ${item.originalID})")
|
||||||
}
|
}
|
||||||
dynamicItemDescription[dynamicID] = item
|
dynamicItemDescription[dynamicID] = item
|
||||||
|
dynamicToStaticTable[dynamicID] = item.originalID
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -265,6 +267,8 @@ object ItemCodex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun dynamicToStaticID(dynamicID: ItemID) = dynamicToStaticTable[dynamicID]!!
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mainly used by GameItemLoader
|
* Mainly used by GameItemLoader
|
||||||
*/
|
*/
|
||||||
@@ -279,8 +283,12 @@ object ItemCodex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getItemImage(itemOriginalID: Int): TextureRegion {
|
fun getItemImage(itemOriginalID: Int): TextureRegion {
|
||||||
|
// dynamic item
|
||||||
|
if (itemOriginalID in ITEM_DYNAMIC) {
|
||||||
|
return getItemImage(dynamicToStaticID(itemOriginalID))
|
||||||
|
}
|
||||||
// terrain
|
// terrain
|
||||||
if (itemOriginalID in ITEM_TILES) {
|
else if (itemOriginalID in ITEM_TILES) {
|
||||||
return BlocksDrawer.tileItemTerrain.get(
|
return BlocksDrawer.tileItemTerrain.get(
|
||||||
itemOriginalID % 16,
|
itemOriginalID % 16,
|
||||||
itemOriginalID / 16
|
itemOriginalID / 16
|
||||||
|
|||||||
@@ -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 we already have the item, increment the amount
|
||||||
// If not, add item with specified amount
|
// If not, add item with specified amount
|
||||||
val existingItem = getByDynamicID(item.dynamicID)
|
val existingItem = invSearchByDynamicID(item.dynamicID)
|
||||||
|
|
||||||
// if the item already exists
|
// if the item already exists
|
||||||
if (existingItem != null) {
|
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
|
if (existingItem != null) { // if the item already exists
|
||||||
val newCount = existingItem.amount - count
|
val newCount = existingItem.amount - count
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
|||||||
quickSlot[slot] = dynamicID
|
quickSlot[slot] = dynamicID
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getQuickslot(slot: Int): InventoryPair? = getByDynamicID(quickSlot[slot])
|
fun getQuickslot(slot: Int): InventoryPair? = invSearchByDynamicID(quickSlot[slot])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HashMap<GameItem, Amounts>
|
* HashMap<GameItem, Amounts>
|
||||||
@@ -198,7 +198,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
|||||||
|
|
||||||
newItem.stackable = false
|
newItem.stackable = false
|
||||||
add(newItem)
|
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
|
// FIXME now damage meter (vital) is broken
|
||||||
}
|
}
|
||||||
@@ -236,7 +236,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
|||||||
false
|
false
|
||||||
else
|
else
|
||||||
itemList.binarySearch(id, DYNAMIC_ID) >= 0
|
itemList.binarySearch(id, DYNAMIC_ID) >= 0
|
||||||
fun getByDynamicID(id: ItemID?): InventoryPair? {
|
fun invSearchByDynamicID(id: ItemID?): InventoryPair? {
|
||||||
if (itemList.size == 0 || id == null)
|
if (itemList.size == 0 || id == null)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
@@ -246,8 +246,8 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
|||||||
else
|
else
|
||||||
return itemList[index]
|
return itemList[index]
|
||||||
}
|
}
|
||||||
private fun getByStaticID(id: ItemID): InventoryPair? {
|
private fun invSearchByStaticID(id: ItemID?): InventoryPair? {
|
||||||
if (itemList.size == 0)
|
if (itemList.size == 0 || id == null)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
val index = itemList.binarySearch(id, STATIC_ID)
|
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 STATIC_ID = 41324534
|
||||||
@Transient private val DYNAMIC_ID = 181643953
|
@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
|
// code from collections/Collections.kt
|
||||||
var low = 0
|
var low = 0
|
||||||
var high = this.size - 1
|
var high = this.size - 1
|
||||||
@@ -277,7 +277,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
|||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
val mid = (low + high).ushr(1) // safe from overflows
|
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
|
ItemCodex[this[mid].item]!!.originalID
|
||||||
else
|
else
|
||||||
ItemCodex[this[mid].item]!!.dynamicID
|
ItemCodex[this[mid].item]!!.dynamicID
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ object AmmoMeterProxy {
|
|||||||
else {
|
else {
|
||||||
meter.vitalGetterVal = {
|
meter.vitalGetterVal = {
|
||||||
if (currentItem.stackable && currentItem.maxDurability == GameItem.DURABILITY_NA) {
|
if (currentItem.stackable && currentItem.maxDurability == GameItem.DURABILITY_NA) {
|
||||||
actor.inventory.getByDynamicID(currentItem.dynamicID)!!.amount.toFloat()
|
actor.inventory.invSearchByDynamicID(currentItem.dynamicID)!!.amount.toFloat()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
currentItem.durability
|
currentItem.durability
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class UIItemInventoryEquippedView(
|
|||||||
itemGrid[k].equippedSlot = null
|
itemGrid[k].equippedSlot = null
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val itemRecord = inventory.getByDynamicID(item)!!
|
val itemRecord = inventory.invSearchByDynamicID(item)!!
|
||||||
|
|
||||||
itemGrid[k].item = ItemCodex[item]
|
itemGrid[k].item = ItemCodex[item]
|
||||||
itemGrid[k].amount = itemRecord.amount
|
itemGrid[k].amount = itemRecord.amount
|
||||||
|
|||||||
Reference in New Issue
Block a user