From 9d51f419f529e1b6938e34406c4062ea66896e03 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 13 Feb 2020 15:08:59 +0900 Subject: [PATCH] make quickslots work with dynamic items --- .../torvald/terrarum/UIItemInventoryElem.kt | 11 +++ .../terrarum/UIItemInventoryElemSimple.kt | 11 +++ .../gameactors/ActorInventory.kt | 4 ++ .../gameactors/PlayerBuilderSigrid.kt | 2 +- .../modulebasegame/gameactors/Pocketed.kt | 8 +++ .../gameitems/PickaxeGeneric.kt | 5 +- .../modulebasegame/icongen/IconGenMesh.kt | 28 ++++++++ .../modulebasegame/icongen/Rasteriser.kt | 36 ++++++++++ .../modulebasegame/icongen/SwordGen.kt | 27 +++++++ work_files/procedural_sword_gen.gv | 71 +++++++++++++++++++ 10 files changed, 200 insertions(+), 3 deletions(-) create mode 100644 src/net/torvald/terrarum/modulebasegame/icongen/IconGenMesh.kt create mode 100644 src/net/torvald/terrarum/modulebasegame/icongen/Rasteriser.kt create mode 100644 src/net/torvald/terrarum/modulebasegame/icongen/SwordGen.kt create mode 100644 work_files/procedural_sword_gen.gv diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index 4e6815e96..97eb850a6 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.modulebasegame.TerrarumIngame @@ -205,9 +206,19 @@ class UIItemInventoryElem( if (item != ItemCodex[player.inventory.itemEquipped.get(itemEquipSlot)]) { // if this item is unequipped, equip it player.equipItem(item!!) + + // also equip on the quickslot + player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)?.let { + player.inventory.setQuickBar(it, item!!.dynamicID) + } } else { // if not, unequip it player.unequipItem(item!!) + + // also unequip on the quickslot + player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)?.let { + player.inventory.setQuickBar(it, null) + } } } diff --git a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt index dadbf0ae7..d5570524a 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt @@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.modulebasegame.TerrarumIngame @@ -178,9 +179,19 @@ class UIItemInventoryElemSimple( if (item != ItemCodex[player.inventory.itemEquipped.get(itemEquipSlot)]) { // if this item is unequipped, equip it player.equipItem(item!!) + + // also equip on the quickslot + player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)?.let { + player.inventory.setQuickBar(it, item!!.dynamicID) + } } else { // if not, unequip it player.unequipItem(item!!) + + // also unequip on the quickslot + player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)?.let { + player.inventory.setQuickBar(it, null) + } } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt index e5187fedf..0323d7529 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt @@ -202,6 +202,10 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c add(newItem) itemEquipped[newItem.equipPosition] = newItem.dynamicID //invSearchByDynamicID(newItem.dynamicID)!!.item // will test if some sketchy code is written. Test fail: kotlinNullpointerException + actor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)?.let { + setQuickBar(it, newItem.dynamicID) + } + // FIXME now damage meter (vital) is broken } else { diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt index dd129acdf..fce89dcea 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt @@ -84,7 +84,7 @@ object PlayerBuilderSigrid { // item ids are defined in /items/itemid.csv - inventory.add(8448) // copper pick + inventory.add(8448, 16) // copper pick inventory.add(8449) // iron pick inventory.add(8450) // steel pick inventory.add(8466, 9995) // wire piece diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/Pocketed.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/Pocketed.kt index c1cedbf97..cc4e8845d 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/Pocketed.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/Pocketed.kt @@ -28,6 +28,14 @@ interface Pocketed { } inventory.itemEquipped[item.equipPosition] = null + + // remove it from the quickslot + inventory.quickSlot.forEachIndexed { index, itemID -> + if (itemID == item.dynamicID) { + inventory.setQuickBar(index, null) + } + } + item.effectOnUnequip(AppLoader.UPDATE_RATE) } diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt index 50e0d442c..5572ffa61 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt @@ -34,12 +34,13 @@ object PickaxeCore { // linear search filter (check for intersection with tilewise mouse point and tilewise hitbox) // return false if hitting actors - var ret1 = true + // ** below is commented out -- don't make actors obstruct the way of digging ** + /*var ret1 = true Terrarum.ingame!!.actorContainerActive.forEach { if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint)) ret1 = false // return is not allowed here } - if (!ret1) return ret1 + if (!ret1) return ret1*/ // return false if here's no tile if (Block.AIR == (Terrarum.ingame!!.world).getTileFromTerrain(mouseTileX, mouseTileY)) diff --git a/src/net/torvald/terrarum/modulebasegame/icongen/IconGenMesh.kt b/src/net/torvald/terrarum/modulebasegame/icongen/IconGenMesh.kt new file mode 100644 index 000000000..45e99b843 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/icongen/IconGenMesh.kt @@ -0,0 +1,28 @@ +package net.torvald.terrarum.modulebasegame.icongen + +import net.torvald.terrarum.Point2d + +/** + * + * . _ end point + * / \ _ control point 1 LR + * | | _ control point 2 LR + * | | _ ... + * | | _ control point 8 LR + * ===== _ accessory (hilt) + * | _ accessory (grip) + * O _ accessory (pommel) + * + * Created by minjaesong on 2020-02-11. + */ +inline class IconGenMesh(val datapoints: Array) { + + operator fun times(other: PerturbMesh) { + + } + +} + +inline class PerturbMesh(val datapoints: Array) { + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/icongen/Rasteriser.kt b/src/net/torvald/terrarum/modulebasegame/icongen/Rasteriser.kt new file mode 100644 index 000000000..f7508f949 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/icongen/Rasteriser.kt @@ -0,0 +1,36 @@ +package net.torvald.terrarum.modulebasegame.icongen + +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.Pixmap +import com.badlogic.gdx.graphics.Texture + +/** + * Created by minjaesong on 2020-02-11. + */ +object Rasteriser { + + operator fun invoke(size: Int, accessories: IcongenOverlays, colour: Color, + mesh: IconGenMesh): Texture { + + val retPixmap = Pixmap(size, size, Pixmap.Format.RGBA8888) + + + + + + + + + val ret = Texture(retPixmap) + retPixmap.dispose() + return ret + + } + +} + +// dummy class plz del +class IcongenOverlays { + +} + diff --git a/src/net/torvald/terrarum/modulebasegame/icongen/SwordGen.kt b/src/net/torvald/terrarum/modulebasegame/icongen/SwordGen.kt new file mode 100644 index 000000000..e64e20940 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/icongen/SwordGen.kt @@ -0,0 +1,27 @@ +package net.torvald.terrarum.modulebasegame.icongen + +import com.badlogic.gdx.graphics.Color + +/** + * Created by minjaesong on 2020-02-11. + */ +object SwordGen { + + operator fun invoke( + size: Int, accessories: IconGenOverlays, colour: Color, type: SwordGenType, + straightness: Double, roughness: Double) { + + + + } + + //private fun getBaseArmingSwordMesh + +} + +enum class SwordGenType { + ArmingSword, TwoHanded, Mace +} + +// dummy class plz del +class IconGenOverlays {} \ No newline at end of file diff --git a/work_files/procedural_sword_gen.gv b/work_files/procedural_sword_gen.gv new file mode 100644 index 000000000..cbda65efd --- /dev/null +++ b/work_files/procedural_sword_gen.gv @@ -0,0 +1,71 @@ +digraph EnergyFlow { + + graph [compound = true]; + + subgraph cluster_resources { + hilt1; + hilt2; + hilt3; + grip1; + grip2; + grip3; + + } + + subgraph cluster_genicon { + Size; + Accessories; + Colour; + Type; + Straightness; + Roughness; + } + + subgraph cluster_mesh { + "Left Perturb Mesh"; + "Right Perturb Mesh"; + "Curve Mesh"; + } + + subgraph gens { + node [style=filled,shape=rect]; + Curvegen; + Jagg; + "Accessory\nSelector"; + Rasterizer; + "Base Shape"; + "Final Mesh"; + } + + grip1 -> "Accessory\nSelector"; + grip2 -> "Accessory\nSelector"; + grip3 -> "Accessory\nSelector"; + hilt1 -> "Accessory\nSelector"; + hilt2 -> "Accessory\nSelector"; + hilt3 -> "Accessory\nSelector"; + Type -> "Base Shape"; + + + Straightness -> Curvegen -> "Curve Mesh"; + Roughness -> Jagg; + Jagg -> "Left Perturb Mesh"; + Jagg -> "Right Perturb Mesh"; + + + "Accessory\nSelector" -> Accessories; + + Accessories -> Rasterizer; + Size -> Rasterizer; + Colour -> Rasterizer; + "Base Shape" -> Add; + "Curve Mesh" -> Add; + Add -> "Final Mesh"; + "Left Perturb Mesh" -> Mul; + "Right Perturb Mesh" -> Mul; + "Base Shape" -> Mul; + Mul -> "Final Mesh"; + + "Final Mesh" -> Rasterizer; + + +}