From 9a819ffec3e5bb992999fce85081003ef374bc34 Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Sat, 29 Apr 2017 23:11:54 +0900 Subject: [PATCH] inventoryItem -> gameItem --- REFERENCING.md | 12 +++++----- .../modules/basegame/items/malicious.groovy | 6 ++--- assets/modules/basegame/items/testpick.groovy | 8 +++---- src/net/torvald/terrarum/AmmoMeterProxy.kt | 8 +++---- src/net/torvald/terrarum/ModMgr.kt | 6 ++--- src/net/torvald/terrarum/StateUITest.kt | 10 ++++----- .../torvald/terrarum/UIItemInventoryElem.kt | 5 ++--- .../terrarum/gameactors/ActorHumanoid.kt | 6 ++--- .../terrarum/gameactors/ActorInventory.kt | 21 +++++++++--------- .../terrarum/gameactors/CanBeAnItem.kt | 4 ++-- .../terrarum/gameactors/DroppedItem.kt | 4 ++-- .../terrarum/gameactors/HumanoidNPC.kt | 17 +++----------- .../torvald/terrarum/gameactors/Pocketed.kt | 22 +++++++++---------- .../terrarum/gamecontroller/GameController.kt | 6 ++--- .../{InventoryItem.kt => GameItem.kt} | 17 +++++++------- .../terrarum/itemproperties/ItemCodex.kt | 12 +++++----- src/net/torvald/terrarum/ui/UIInventory.kt | 20 ++++++++--------- 17 files changed, 84 insertions(+), 100 deletions(-) rename src/net/torvald/terrarum/itemproperties/{InventoryItem.kt => GameItem.kt} (92%) diff --git a/REFERENCING.md b/REFERENCING.md index 3c161b4d3..24fea0c50 100644 --- a/REFERENCING.md +++ b/REFERENCING.md @@ -1,14 +1,14 @@ |Range|Description| |-----|-----------| -|0..4095|Tiles| -|4096..8191|Walls| -|8192..8447|Wires| -|8448..32767|Items (static)| -|32768..0x0FFF_FFFF|Items (dynamic\*)| +|0..4095|Tiles (4096 possible)| +|4096..8191|Walls (4096 possible)| +|8192..8447|Wires (256 possible)| +|8448..32767|Items (static) (24320 possible)| +|32768..0x0FFF_FFFF|Items (dynamic\*) (268M possible)| |0x1000_0000..0x7FFF_FFFF|Actors| |-2147483648..-1 (all negative numbers)|Faction| -* dynamic items can have their own properties that will persist through savegame. +* dynamic items have own properties that will persist through savegame. Actors range in-depth diff --git a/assets/modules/basegame/items/malicious.groovy b/assets/modules/basegame/items/malicious.groovy index 3832ce475..1238334fe 100644 --- a/assets/modules/basegame/items/malicious.groovy +++ b/assets/modules/basegame/items/malicious.groovy @@ -1,4 +1,4 @@ -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.Material import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.Nullable @@ -7,9 +7,9 @@ import org.jetbrains.annotations.Nullable * Created by SKYHi14 on 2017-04-28. */ -static InventoryItem invoke(int id) { +static GameItem invoke(int id) { - return new InventoryItem() { + return new GameItem() { @Override int getDynamicID() { return 0 diff --git a/assets/modules/basegame/items/testpick.groovy b/assets/modules/basegame/items/testpick.groovy index 9c138dad7..3b7dfd29f 100644 --- a/assets/modules/basegame/items/testpick.groovy +++ b/assets/modules/basegame/items/testpick.groovy @@ -9,23 +9,21 @@ import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.ActorWithPhysics import net.torvald.terrarum.itemproperties.Calculate -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.blockproperties.Block // following two are NOT UNUSED! -import net.torvald.terrarum.itemproperties.InventoryItem.EquipPosition -import net.torvald.terrarum.itemproperties.InventoryItem.Category import org.jetbrains.annotations.NotNull import org.newdawn.slick.GameContainer -static InventoryItem invoke(int id) { +static GameItem invoke(int id) { return new TestPick(id) } -class TestPick extends InventoryItem { +class TestPick extends GameItem { int originalID int dynamicID diff --git a/src/net/torvald/terrarum/AmmoMeterProxy.kt b/src/net/torvald/terrarum/AmmoMeterProxy.kt index 0aa20bb5b..ed3283752 100644 --- a/src/net/torvald/terrarum/AmmoMeterProxy.kt +++ b/src/net/torvald/terrarum/AmmoMeterProxy.kt @@ -1,7 +1,7 @@ package net.torvald.terrarum import net.torvald.terrarum.gameactors.ActorHumanoid -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.ui.UIVitalMetre /** @@ -10,7 +10,7 @@ import net.torvald.terrarum.ui.UIVitalMetre object AmmoMeterProxy { operator fun invoke(actor: ActorHumanoid, meter: UIVitalMetre) { - val currentItem = actor.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP] + val currentItem = actor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP] if (currentItem == null) { meter.vitalGetterMax = { null } @@ -18,7 +18,7 @@ object AmmoMeterProxy { } else { meter.vitalGetterVal = { - if (currentItem.stackable && currentItem.maxDurability == InventoryItem.DURABILITY_NA) { + if (currentItem.stackable && currentItem.maxDurability == GameItem.DURABILITY_NA) { actor.inventory.getByDynamicID(currentItem.dynamicID)!!.amount.toFloat() } else @@ -26,7 +26,7 @@ object AmmoMeterProxy { } meter.vitalGetterMax = { - if (currentItem.stackable && currentItem.maxDurability == InventoryItem.DURABILITY_NA) + if (currentItem.stackable && currentItem.maxDurability == GameItem.DURABILITY_NA) 500f else currentItem.maxDurability.toFloat() diff --git a/src/net/torvald/terrarum/ModMgr.kt b/src/net/torvald/terrarum/ModMgr.kt index 3248bd8b2..59171eec4 100644 --- a/src/net/torvald/terrarum/ModMgr.kt +++ b/src/net/torvald/terrarum/ModMgr.kt @@ -1,7 +1,7 @@ package net.torvald.terrarum import net.torvald.CSVFetcher -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.langpack.Lang @@ -103,7 +103,7 @@ object ModMgr { /*val engine = ScriptEngineManager().getEngineByExtension("groovy")!! engine.eval(FileReader(getFile("basegame", "/items/testpick.groovy"))) - val newPick = (engine as Invocable).invokeFunction("invoke", 8449) as InventoryItem + val newPick = (engine as Invocable).invokeFunction("invoke", 8449) as GameItem ItemCodex[8449] = newPick*/ } @@ -157,7 +157,7 @@ object ModMgr { val itemID = it["id"].toInt() groovyEngine.eval(script) - ItemCodex[itemID] = groovyInvocable.invokeFunction("invoke", itemID) as InventoryItem + ItemCodex[itemID] = groovyInvocable.invokeFunction("invoke", itemID) as GameItem } } } diff --git a/src/net/torvald/terrarum/StateUITest.kt b/src/net/torvald/terrarum/StateUITest.kt index 2a8374edb..13816faf0 100644 --- a/src/net/torvald/terrarum/StateUITest.kt +++ b/src/net/torvald/terrarum/StateUITest.kt @@ -2,7 +2,7 @@ package net.torvald.terrarum import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.itemproperties.IVKey -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.blockproperties.Block @@ -46,7 +46,7 @@ class StateUITest : BasicGameState() { // Item properties must be pre-composed using CSV/JSON, and read and made into the item instance // using factory/builder pattern. @see ItemCodex - actor.inventory.add(object : InventoryItem() { + actor.inventory.add(object : GameItem() { init { itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.HAMMER } @@ -56,7 +56,7 @@ class StateUITest : BasicGameState() { override var originalName: String = "Test tool" override var baseMass: Double = 12.0 override var baseToolSize: Double? = 8.0 - override var inventoryCategory: String = InventoryItem.Category.TOOL + override var inventoryCategory: String = GameItem.Category.TOOL override var maxDurability: Int = 143 override var durability: Float = 64f override var stackable = false @@ -65,7 +65,7 @@ class StateUITest : BasicGameState() { }) actor.inventory.getByDynamicID(5656)!!.item.name = "Test tool" - actor.inventory.add(object : InventoryItem() { + actor.inventory.add(object : GameItem() { init { itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.ARTEFACT } @@ -75,7 +75,7 @@ class StateUITest : BasicGameState() { override var originalName: String = "CONTEXT_ITEM_QUEST_NOUN" override var baseMass: Double = 1.4 override var baseToolSize: Double? = null - override var inventoryCategory: String = InventoryItem.Category.MISC + override var inventoryCategory: String = GameItem.Category.MISC override var stackable = false override val isDynamic = false override val material = Material(0,0,0,0,0,0,0,0,0,0.0) diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index 5987d53a7..b4a89ac3e 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -2,8 +2,7 @@ package net.torvald.terrarum import net.torvald.colourutil.CIELabUtil.darkerLab import net.torvald.terrarum.gamecontroller.Key -import net.torvald.terrarum.itemproperties.InventoryItem -import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.ui.UIInventory import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItemTextButton @@ -22,7 +21,7 @@ class UIItemInventoryElem( override var posX: Int, override var posY: Int, override val width: Int, - var item: InventoryItem?, + var item: GameItem?, var amount: Int, var itemImage: Image?, val mouseOverTextCol: Color = Color(0xfff066), diff --git a/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt b/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt index 2b4d45517..6489a3a93 100644 --- a/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt +++ b/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt @@ -4,7 +4,7 @@ import com.jme3.math.FastMath import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.faction.Faction import net.torvald.terrarum.gamecontroller.Key -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.ui.UIInventory @@ -138,7 +138,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null) get() = this == Terrarum.ingame!!.player - private val nullItem = object : InventoryItem() { + private val nullItem = object : GameItem() { override var dynamicID: Int = 0 override val originalID = dynamicID override val isUnique: Boolean = false @@ -480,7 +480,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null) // ONLY FOR HAND_GRIPs!! val quickBarItem = inventory.getQuickBar(actorValue.getAsInt(key)!!)?.item - if (quickBarItem != null && quickBarItem.equipPosition == InventoryItem.EquipPosition.HAND_GRIP) { + if (quickBarItem != null && quickBarItem.equipPosition == GameItem.EquipPosition.HAND_GRIP) { equipItem(quickBarItem) } diff --git a/src/net/torvald/terrarum/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/gameactors/ActorInventory.kt index d5d96a672..e14e7d58e 100644 --- a/src/net/torvald/terrarum/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/gameactors/ActorInventory.kt @@ -2,12 +2,11 @@ package net.torvald.terrarum.gameactors import net.torvald.terrarum.Terrarum import net.torvald.terrarum.blockproperties.BlockCodex -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS import net.torvald.terrarum.itemproperties.ItemID -import net.torvald.terrarum.ui.UIInventory import java.util.* import java.util.concurrent.locks.Lock import java.util.concurrent.locks.ReentrantLock @@ -27,7 +26,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode /** * List of all equipped items (tools, armours, rings, necklaces, etc.) */ - val itemEquipped = Array(InventoryItem.EquipPosition.INDEX_MAX, { null }) + val itemEquipped = Array(GameItem.EquipPosition.INDEX_MAX, { null }) /** * Sorted by referenceID. @@ -39,13 +38,13 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode } fun add(itemID: ItemID, count: Int = 1) = add(ItemCodex[itemID], count) - fun add(item: InventoryItem, count: Int = 1) { + fun add(item: GameItem, count: Int = 1) { println("[ActorInventory] add $item, $count") // not wall-able walls - if (item.inventoryCategory == InventoryItem.Category.WALL && + if (item.inventoryCategory == GameItem.Category.WALL && !BlockCodex[item.dynamicID - ITEM_WALLS.start].isWallable) { throw IllegalArgumentException("Wall ID ${item.dynamicID - ITEM_WALLS.start} is not wall-able.") } @@ -86,7 +85,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode fun remove(itemID: ItemID, count: Int) = remove(ItemCodex[itemID], count) /** Will check existence of the item using its Dynamic ID; careful with command order! * e.g. re-assign after this operation */ - fun remove(item: InventoryItem, count: Int = 1) { + fun remove(item: GameItem, count: Int = 1) { println("[ActorInventory] remove $item, $count") @@ -128,7 +127,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode fun getQuickBar(slot: Int): InventoryPair? = getByDynamicID(quickBar[slot]) /** - * HashMap + * HashMap */ fun forEach(consumer: (InventoryPair) -> Unit) = itemList.forEach(consumer) @@ -169,12 +168,12 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode false - fun consumeItem(actor: Actor, item: InventoryItem) { + fun consumeItem(actor: Actor, item: GameItem) { if (item.stackable && !item.isDynamic) { remove(item, 1) } else { - val newItem: InventoryItem + val newItem: GameItem // unpack newly-made dynamic item (e.g. any weapon, floppy disk) if (item.isDynamic && item.originalID == item.dynamicID) { @@ -219,7 +218,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode - fun contains(item: InventoryItem) = contains(item.dynamicID) + fun contains(item: GameItem) = contains(item.dynamicID) fun contains(id: ItemID) = if (itemList.size == 0) false @@ -288,4 +287,4 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode } } -data class InventoryPair(val item: InventoryItem, var amount: Int) \ No newline at end of file +data class InventoryPair(val item: GameItem, var amount: Int) \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/CanBeAnItem.kt b/src/net/torvald/terrarum/gameactors/CanBeAnItem.kt index c9f4aff30..180b7edf9 100644 --- a/src/net/torvald/terrarum/gameactors/CanBeAnItem.kt +++ b/src/net/torvald/terrarum/gameactors/CanBeAnItem.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.gameactors -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem /** * Created by minjaesong on 16-01-31. @@ -13,6 +13,6 @@ interface CanBeAnItem { fun resumeUpdateAndDraw() - var itemData: InventoryItem + var itemData: GameItem } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/DroppedItem.kt b/src/net/torvald/terrarum/gameactors/DroppedItem.kt index ab9fae50b..c99aa723e 100644 --- a/src/net/torvald/terrarum/gameactors/DroppedItem.kt +++ b/src/net/torvald/terrarum/gameactors/DroppedItem.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.gameactors -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.blockproperties.BlockCodex import org.newdawn.slick.GameContainer @@ -9,7 +9,7 @@ import org.newdawn.slick.Graphics /** * Created by minjaesong on 16-03-15. */ -class DroppedItem(private val item: InventoryItem) : ActorWithPhysics(Actor.RenderOrder.MIDTOP) { +class DroppedItem(private val item: GameItem) : ActorWithPhysics(Actor.RenderOrder.MIDTOP) { init { if (item.dynamicID >= ItemCodex.ACTORID_MIN) diff --git a/src/net/torvald/terrarum/gameactors/HumanoidNPC.kt b/src/net/torvald/terrarum/gameactors/HumanoidNPC.kt index e417fb321..58c13d9b2 100644 --- a/src/net/torvald/terrarum/gameactors/HumanoidNPC.kt +++ b/src/net/torvald/terrarum/gameactors/HumanoidNPC.kt @@ -1,24 +1,13 @@ package net.torvald.terrarum.gameactors import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.gameactors.ActorHumanoid -import net.torvald.terrarum.gameactors.ai.AILuaAPI import net.torvald.terrarum.gameactors.ai.ActorAI import net.torvald.terrarum.gameactors.ai.LuaAIWrapper import net.torvald.terrarum.gamecontroller.mouseX import net.torvald.terrarum.gamecontroller.mouseY -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.Material -import org.luaj.vm2.* -import org.luaj.vm2.compiler.LuaC -import org.luaj.vm2.lib.* -import org.luaj.vm2.lib.jse.JseBaseLib -import org.luaj.vm2.lib.jse.JseMathLib -import org.luaj.vm2.lib.jse.JsePlatform import org.newdawn.slick.GameContainer -import org.newdawn.slick.Input -import java.io.InputStreamReader -import java.io.Reader /** * @param ai AI class. Use LuaAIWrapper for Lua script @@ -42,8 +31,8 @@ open class HumanoidNPC( collisionType = DEFAULT_COLLISION_TYPE } - // we're having InventoryItem data so that this class could be somewhat universal - override var itemData: InventoryItem = object : InventoryItem() { + // we're having GameItem data so that this class could be somewhat universal + override var itemData: GameItem = object : GameItem() { override var dynamicID = referenceID override val originalID = dynamicID override val isUnique = true diff --git a/src/net/torvald/terrarum/gameactors/Pocketed.kt b/src/net/torvald/terrarum/gameactors/Pocketed.kt index 0c9d3fca7..88285024e 100644 --- a/src/net/torvald/terrarum/gameactors/Pocketed.kt +++ b/src/net/torvald/terrarum/gameactors/Pocketed.kt @@ -1,7 +1,7 @@ package net.torvald.terrarum.gameactors import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex /** @@ -14,10 +14,10 @@ interface Pocketed { /** * Equips an item. If the item is not in the inventory, an error will be thrown. */ - fun unequipItem(item: InventoryItem?) { + fun unequipItem(item: GameItem?) { if (item == null) return - if (item.equipPosition == InventoryItem.EquipPosition.NULL) + if (item.equipPosition == GameItem.EquipPosition.NULL) throw Error("Unequipping the item that cannot be equipped in the first place") if (!inventory.contains(item)) { @@ -32,7 +32,7 @@ interface Pocketed { // no need for equipSlot(Int) fun unequipSlot(slot: Int) { - if (slot < 0 || slot > InventoryItem.EquipPosition.INDEX_MAX) + if (slot < 0 || slot > GameItem.EquipPosition.INDEX_MAX) throw IllegalArgumentException("Slot index out of range: $slot") unequipItem(inventory.itemEquipped[slot]) @@ -41,7 +41,7 @@ interface Pocketed { /** * Equips an item. If the item is not in the inventory, adds the item first. */ - fun equipItem(item: InventoryItem) { + fun equipItem(item: GameItem) { if (!inventory.contains(item)) { println("[Pocketed] Item does not exist; adding one before equipped") inventory.add(item) @@ -54,26 +54,26 @@ interface Pocketed { // else do nothing } - fun equipped(item: InventoryItem): Boolean { + fun equipped(item: GameItem): Boolean { return inventory.itemEquipped[item.equipPosition] == item } fun addItem(itemID: Int, count: Int = 1) = inventory.add(ItemCodex[itemID], count) - fun addItem(item: InventoryItem, count: Int = 1) = inventory.add(item, count) + fun addItem(item: GameItem, count: Int = 1) = inventory.add(item, count) fun removeItem(itemID: Int, count: Int = 1) = inventory.remove(ItemCodex[itemID], count) - fun removeItem(item: InventoryItem, count: Int = 1) = inventory.remove(item, count) + fun removeItem(item: GameItem, count: Int = 1) = inventory.remove(item, count) - fun hasItem(item: InventoryItem) = inventory.contains(item.dynamicID) + fun hasItem(item: GameItem) = inventory.contains(item.dynamicID) fun hasItem(id: Int) = inventory.contains(id) - fun consumePrimary(item: InventoryItem) { + fun consumePrimary(item: GameItem) { if (item.primaryUse(Terrarum.appgc, Terrarum.delta)) { inventory.consumeItem(this as Actor, item) // consume on successful } } - fun consumeSecondary(item: InventoryItem) { + fun consumeSecondary(item: GameItem) { if (item.secondaryUse(Terrarum.appgc, Terrarum.delta)) inventory.consumeItem(this as Actor, item) // consume on successful } diff --git a/src/net/torvald/terrarum/gamecontroller/GameController.kt b/src/net/torvald/terrarum/gamecontroller/GameController.kt index a6f9b6f27..7a5401a78 100644 --- a/src/net/torvald/terrarum/gamecontroller/GameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/GameController.kt @@ -3,7 +3,7 @@ package net.torvald.terrarum.gamecontroller import net.torvald.terrarum.worlddrawer.FeaturesDrawer import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.* -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.worlddrawer.WorldCamera import org.newdawn.slick.GameContainer import org.newdawn.slick.Input @@ -65,7 +65,7 @@ object GameController { // Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP) if (ingame.player != null && ingame.canPlayerControl) { if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")) || input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) { - val itemOnGrip = ingame.player!!.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP] + val itemOnGrip = ingame.player!!.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP] if (itemOnGrip != null) { if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) { @@ -130,7 +130,7 @@ object GameController { val ingame = Terrarum.ingame!! // don't separate Player from this! Physics will break, esp. airborne manoeuvre if (ingame.player != null && ingame.canPlayerControl) { - val itemOnGrip = ingame.player!!.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP] + val itemOnGrip = ingame.player!!.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP] if (itemOnGrip != null) { if (button == Terrarum.getConfigInt("mousePrimary")) { diff --git a/src/net/torvald/terrarum/itemproperties/InventoryItem.kt b/src/net/torvald/terrarum/itemproperties/GameItem.kt similarity index 92% rename from src/net/torvald/terrarum/itemproperties/InventoryItem.kt rename to src/net/torvald/terrarum/itemproperties/GameItem.kt index ec316bc65..c2d4b33a1 100644 --- a/src/net/torvald/terrarum/itemproperties/InventoryItem.kt +++ b/src/net/torvald/terrarum/itemproperties/GameItem.kt @@ -5,7 +5,6 @@ import net.torvald.terrarum.ItemValue import net.torvald.terrarum.gameactors.ActorInventory import net.torvald.terrarum.gameactors.Pocketed import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC -import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.langpack.Lang import org.newdawn.slick.Color import org.newdawn.slick.GameContainer @@ -15,7 +14,7 @@ typealias ItemID = Int /** * Created by minjaesong on 16-01-16. */ -abstract class InventoryItem : Comparable, Cloneable { +abstract class GameItem : Comparable, Cloneable { abstract var dynamicID: ItemID /** @@ -110,7 +109,7 @@ abstract class InventoryItem : Comparable, Cloneable { open var scale: Double = 1.0 /** - * Set to zero (InventoryItem.DURABILITY_NA) if durability not applicable + * Set to zero (GameItem.DURABILITY_NA) if durability not applicable */ open var maxDurability: Int = 0 @@ -183,7 +182,7 @@ abstract class InventoryItem : Comparable, Cloneable { override fun equals(other: Any?): Boolean { if (other == null) return false - return dynamicID == (other as InventoryItem).dynamicID + return dynamicID == (other as GameItem).dynamicID } fun unsetCustomName() { @@ -192,7 +191,7 @@ abstract class InventoryItem : Comparable, Cloneable { nameColour = Color.white } - override fun compareTo(other: InventoryItem): Int = (this.dynamicID - other.dynamicID).sign() + override fun compareTo(other: GameItem): Int = (this.dynamicID - other.dynamicID).sign() fun Int.sign(): Int = if (this > 0) 1 else if (this < 0) -1 else 0 @@ -243,17 +242,17 @@ abstract class InventoryItem : Comparable, Cloneable { @JvmStatic val MISC = "misc" } - override public fun clone(): InventoryItem { + override public fun clone(): GameItem { val clonedItem = super.clone() // properly clone ItemValue - (clonedItem as InventoryItem).itemProperties = this.itemProperties.clone() + (clonedItem as GameItem).itemProperties = this.itemProperties.clone() return clonedItem } - fun generateUniqueDynamicID(inventory: ActorInventory): InventoryItem { - dynamicID = InventoryItem.generateUniqueDynamicID(inventory) + fun generateUniqueDynamicID(inventory: ActorInventory): GameItem { + dynamicID = GameItem.generateUniqueDynamicID(inventory) return this } diff --git a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt index 296d71217..843fdca7c 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt @@ -24,7 +24,7 @@ object ItemCodex { * * Will return corresponding Actor if ID >= ACTORID_MIN */ - private val itemCodex = HashMap() + private val itemCodex = HashMap() private val dynamicItemDescription = HashMap() val ITEM_TILES = 0..GameWorld.TILES_SUPPORTED - 1 @@ -42,7 +42,7 @@ object ItemCodex { // blocks.csvs are loaded by ModMgr beforehand // block items (blocks and walls are the same thing basically) for (i in ITEM_TILES + ITEM_WALLS) { - itemCodex[i] = object : InventoryItem() { + itemCodex[i] = object : GameItem() { override val originalID = i override var dynamicID = i override val isUnique: Boolean = false @@ -108,7 +108,7 @@ object ItemCodex { } // test copper pickaxe - /*itemCodex[ITEM_STATIC.first] = object : InventoryItem() { + /*itemCodex[ITEM_STATIC.first] = object : GameItem() { override val originalID = ITEM_STATIC.first override var dynamicID = originalID override val isUnique = false @@ -173,7 +173,7 @@ object ItemCodex { /** * Returns clone of the item in the Codex */ - operator fun get(code: ItemID): InventoryItem { + operator fun get(code: ItemID): GameItem { if (code <= ITEM_STATIC.endInclusive) // generic item return itemCodex[code]!!.clone() // from CSV else if (code <= ITEM_DYNAMIC.endInclusive) { @@ -190,11 +190,11 @@ object ItemCodex { /** * Mainly used by GameItemLoader */ - operator fun set(code: ItemID, item: InventoryItem) { + operator fun set(code: ItemID, item: GameItem) { itemCodex[code] = item } - fun getItemImage(item: InventoryItem): Image { + fun getItemImage(item: GameItem): Image { // terrain if (item.originalID in ITEM_TILES) { return BlocksDrawer.tilesTerrain.getSubImage( diff --git a/src/net/torvald/terrarum/ui/UIInventory.kt b/src/net/torvald/terrarum/ui/UIInventory.kt index f1d72d788..0ef762a31 100644 --- a/src/net/torvald/terrarum/ui/UIInventory.kt +++ b/src/net/torvald/terrarum/ui/UIInventory.kt @@ -5,7 +5,7 @@ import net.torvald.terrarum.Terrarum.joypadLabelNinA import net.torvald.terrarum.Terrarum.joypadLabelNinY import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER -import net.torvald.terrarum.itemproperties.InventoryItem +import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.langpack.Lang import org.newdawn.slick.* @@ -35,15 +35,15 @@ class UIInventory( val defaultTextColour = Color(0xeaeaea) init { - catButtonsToCatIdent.put("GAME_INVENTORY_WEAPONS", InventoryItem.Category.WEAPON) - catButtonsToCatIdent.put("CONTEXT_ITEM_TOOL_PLURAL", InventoryItem.Category.TOOL) - catButtonsToCatIdent.put("CONTEXT_ITEM_ARMOR", InventoryItem.Category.ARMOUR) - catButtonsToCatIdent.put("GAME_INVENTORY_INGREDIENTS", InventoryItem.Category.GENERIC) - catButtonsToCatIdent.put("GAME_INVENTORY_POTIONS", InventoryItem.Category.POTION) - catButtonsToCatIdent.put("CONTEXT_ITEM_MAGIC", InventoryItem.Category.MAGIC) - catButtonsToCatIdent.put("GAME_INVENTORY_BLOCKS", InventoryItem.Category.BLOCK) - catButtonsToCatIdent.put("GAME_INVENTORY_WALLS", InventoryItem.Category.WALL) - catButtonsToCatIdent.put("GAME_GENRE_MISC", InventoryItem.Category.MISC) + catButtonsToCatIdent.put("GAME_INVENTORY_WEAPONS", GameItem.Category.WEAPON) + catButtonsToCatIdent.put("CONTEXT_ITEM_TOOL_PLURAL", GameItem.Category.TOOL) + catButtonsToCatIdent.put("CONTEXT_ITEM_ARMOR", GameItem.Category.ARMOUR) + catButtonsToCatIdent.put("GAME_INVENTORY_INGREDIENTS", GameItem.Category.GENERIC) + catButtonsToCatIdent.put("GAME_INVENTORY_POTIONS", GameItem.Category.POTION) + catButtonsToCatIdent.put("CONTEXT_ITEM_MAGIC", GameItem.Category.MAGIC) + catButtonsToCatIdent.put("GAME_INVENTORY_BLOCKS", GameItem.Category.BLOCK) + catButtonsToCatIdent.put("GAME_INVENTORY_WALLS", GameItem.Category.WALL) + catButtonsToCatIdent.put("GAME_GENRE_MISC", GameItem.Category.MISC) // special filter catButtonsToCatIdent.put("MENU_LABEL_ALL", "__all__")