From 037e84d6e2f08e63f9c06e98ab8fdcf2b6bae70b Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Tue, 11 Apr 2017 23:07:29 +0900 Subject: [PATCH] setting up the inventory using builder (during init) requires ingame.player to be nullable, lateinit won't work --- src/net/torvald/terrarum/StateInGame.kt | 26 +++++++------ .../torvald/terrarum/UIItemInventoryElem.kt | 6 +-- src/net/torvald/terrarum/console/ExportAV.kt | 2 +- src/net/torvald/terrarum/console/GetAV.kt | 12 +++--- src/net/torvald/terrarum/console/Inventory.kt | 38 +++++++++++-------- src/net/torvald/terrarum/console/SetAV.kt | 2 +- src/net/torvald/terrarum/console/SetScale.kt | 2 +- src/net/torvald/terrarum/console/Teleport.kt | 4 +- .../torvald/terrarum/console/ToggleNoClip.kt | 4 +- .../terrarum/debuggerapp/ActorValueTracker.kt | 6 +-- .../terrarum/gameactors/ActorInventory.kt | 10 ++--- .../gameactors/PlayerBuilderSigrid.kt | 2 +- .../terrarum/gamecontroller/GameController.kt | 18 +++++---- .../terrarum/gameitem/InventoryItem.kt | 4 ++ .../torvald/terrarum/mapdrawer/MapCamera.kt | 4 +- .../torvald/terrarum/tilestats/TileStats.kt | 4 +- .../terrarum/ui/BasicDebugInfoWindow.kt | 36 +++++++++--------- src/net/torvald/terrarum/ui/UIInventory.kt | 18 +++++++-- src/net/torvald/terrarum/ui/UIPieMenu.kt | 10 ++--- src/net/torvald/terrarum/ui/UIQuickBar.kt | 4 +- .../torvald/terrarum/weather/WeatherMixer.kt | 23 ++++++----- 21 files changed, 132 insertions(+), 103 deletions(-) diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt index cd6dfa389..45456b6f2 100644 --- a/src/net/torvald/terrarum/StateInGame.kt +++ b/src/net/torvald/terrarum/StateInGame.kt @@ -71,9 +71,10 @@ class StateInGame : BasicGameState() { lateinit var debugWindow: UIHandler lateinit var notifier: UIHandler - private lateinit var playableActorDelegate: PlayableActorDelegate // player is necessity in this engine, even if the player is just a camera - internal val player: ActorHumanoid // currently POSSESSED actor :) - get() = playableActorDelegate.actor + + private var playableActorDelegate: PlayableActorDelegate? = null // DO NOT LATEINIT! + internal val player: ActorHumanoid? // currently POSSESSED actor :) + get() = playableActorDelegate?.actor var screenZoom = 1.0f val ZOOM_MAX = 2.0f @@ -141,9 +142,9 @@ class StateInGame : BasicGameState() { // add new player and put it to actorContainer - //playableActorDelegate = PlayableActorDelegate(PlayerBuilderSigrid()) - playableActorDelegate = PlayableActorDelegate(PlayerBuilderTestSubject1()) - addNewActor(player) + playableActorDelegate = PlayableActorDelegate(PlayerBuilderSigrid()) + //playableActorDelegate = PlayableActorDelegate(PlayerBuilderTestSubject1()) + addNewActor(player!!) // test actor @@ -342,10 +343,10 @@ class StateInGame : BasicGameState() { } // take care of old delegate - playableActorDelegate.actor.collisionType = HumanoidNPC.DEFAULT_COLLISION_TYPE + playableActorDelegate!!.actor.collisionType = HumanoidNPC.DEFAULT_COLLISION_TYPE // accept new delegate playableActorDelegate = PlayableActorDelegate(getActorByID(refid) as ActorHumanoid) - playableActorDelegate.actor.collisionType = ActorWithSprite.COLLISION_KINEMATIC + playableActorDelegate!!.actor.collisionType = ActorWithSprite.COLLISION_KINEMATIC WorldSimulator(player, UPDATE_DELTA) } @@ -392,7 +393,7 @@ class StateInGame : BasicGameState() { ///////////////// actorsRenderMiddle.forEach { it.drawBody(worldG) } actorsRenderMidTop.forEach { it.drawBody(worldG) } - player.drawBody(worldG) + player?.drawBody(worldG) actorsRenderFront.forEach { it.drawBody(worldG) } // --> Change of blend mode <-- introduced by ActorVisible // @@ -419,7 +420,7 @@ class StateInGame : BasicGameState() { ////////////////////// actorsRenderMiddle.forEach { it.drawGlow(worldG) } actorsRenderMidTop.forEach { it.drawGlow(worldG) } - player.drawGlow(worldG) + player?.drawGlow(worldG) actorsRenderFront.forEach { it.drawGlow(worldG) } // --> blendLightenOnly() <-- introduced by ActorVisible // @@ -521,7 +522,7 @@ class StateInGame : BasicGameState() { GameController.keyPressed(key, c) if (canPlayerMove) { - player.keyPressed(key, c) + player?.keyPressed(key, c) } if (Terrarum.getConfigIntArray("keyquickselalt").contains(key) @@ -747,7 +748,8 @@ class StateInGame : BasicGameState() { * This is how remove function of [java.util.ArrayList] is defined. */ fun removeActor(actor: Actor) { - if (actor.referenceID == player.referenceID) throw RuntimeException("Attempted to remove player.") + if (actor.referenceID == player?.referenceID || actor.referenceID == 0x51621D) // do not delete this magic + throw RuntimeException("Attempted to remove player.") val indexToDelete = actorContainer.binarySearch(actor.referenceID) if (indexToDelete >= 0) { actorContainer.removeAt(indexToDelete) diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index d3b6ba4ff..e0d50409f 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -138,11 +138,11 @@ class UIItemInventoryElem( val itemEquipSlot = item!!.equipPosition val player = Terrarum.ingame!!.player - if (item != player.inventory.itemEquipped[itemEquipSlot]) { // if this item is unequipped, equip it - player.equipItem(item!!) + if (item != player?.inventory?.itemEquipped?.get(itemEquipSlot)) { // if this item is unequipped, equip it + player?.equipItem(item!!) } else { // if not, unequip it - player.unequipItem(item!!) + player?.unequipItem(item!!) } } diff --git a/src/net/torvald/terrarum/console/ExportAV.kt b/src/net/torvald/terrarum/console/ExportAV.kt index 5c909a919..351afb6fb 100644 --- a/src/net/torvald/terrarum/console/ExportAV.kt +++ b/src/net/torvald/terrarum/console/ExportAV.kt @@ -13,7 +13,7 @@ internal object ExportAV : ConsoleCommand { if (args.size == 2) { try { JsonWriter.writeToFile( - Terrarum.ingame!!.player.actorValue, + Terrarum.ingame!!.player!!.actorValue, Terrarum.defaultDir + "/Exports/" + args[1] + ".json") Echo("ExportAV: exported to " + args[1] + ".json") diff --git a/src/net/torvald/terrarum/console/GetAV.kt b/src/net/torvald/terrarum/console/GetAV.kt index cef3f0725..146066f6d 100644 --- a/src/net/torvald/terrarum/console/GetAV.kt +++ b/src/net/torvald/terrarum/console/GetAV.kt @@ -17,9 +17,9 @@ internal object GetAV : ConsoleCommand { override fun execute(args: Array) { try { - if (args.size == 1) { + if (args.size == 1 && Terrarum.ingame!!.player != null) { // print all actorvalue of player - val av = Terrarum.ingame!!.player.actorValue + val av = Terrarum.ingame!!.player!!.actorValue val keyset = av.keySet Echo("$ccW== ActorValue list for ${ccY}player $ccW==") @@ -37,14 +37,14 @@ internal object GetAV : ConsoleCommand { if (!args[1].isNum()) { // args[1] is ActorValue name Echo("${ccW}player.$ccM${args[1]} $ccW= " + ccG + - Terrarum.ingame!!.player.actorValue[args[1]] + + Terrarum.ingame!!.player!!.actorValue[args[1]] + " $ccO" + - Terrarum.ingame!!.player.actorValue[args[1]]!!.javaClass.simpleName + Terrarum.ingame!!.player!!.actorValue[args[1]]!!.javaClass.simpleName ) println("[GetAV] player.${args[1]} = " + - Terrarum.ingame!!.player.actorValue[args[1]] + + Terrarum.ingame!!.player!!.actorValue[args[1]] + " " + - Terrarum.ingame!!.player.actorValue[args[1]]!!.javaClass.simpleName + Terrarum.ingame!!.player!!.actorValue[args[1]]!!.javaClass.simpleName ) } else { diff --git a/src/net/torvald/terrarum/console/Inventory.kt b/src/net/torvald/terrarum/console/Inventory.kt index 638e3ca86..41c043c43 100644 --- a/src/net/torvald/terrarum/console/Inventory.kt +++ b/src/net/torvald/terrarum/console/Inventory.kt @@ -11,7 +11,7 @@ import net.torvald.terrarum.itemproperties.ItemCodex */ internal object Inventory : ConsoleCommand { - private var target: Pocketed = Terrarum.ingame!!.player + private var target: Pocketed? = Terrarum.ingame!!.player override fun execute(args: Array) { if (args.size == 1) { @@ -30,15 +30,17 @@ internal object Inventory : ConsoleCommand { } private fun listInventory() { - if (target.inventory.getTotalUniqueCount() == 0) { - Echo("(inventory empty)") - } - else { - target.inventory.forEach { - if (it.amount == 0) { - EchoError("Unexpected zero-amounted item: ID ${it.item.id}") + if (target != null) { + if (target!!.inventory.getTotalUniqueCount() == 0) { + Echo("(inventory empty)") + } + else { + target!!.inventory.forEach { + if (it.amount == 0) { + EchoError("Unexpected zero-amounted item: ID ${it.item.id}") + } + Echo("ID ${it.item.id}${if (it.amount > 1) " ($it.second)" else ""}") } - Echo("ID ${it.item.id}${if (it.amount > 1) " ($it.second)" else ""}") } } } @@ -54,18 +56,22 @@ internal object Inventory : ConsoleCommand { } private fun addItem(refId: Int, amount: Int = 1) { - target.inventory.add(ItemCodex[refId], amount) + if (target != null) { + target!!.inventory.add(ItemCodex[refId], amount) + } } private fun equipItem(refId: Int) { - val item = ItemCodex[refId] + if (target != null) { + val item = ItemCodex[refId] - // if the item does not exist, add it first - if (!target.inventory.hasItem(item)) { - target.inventory.add(item) + // if the item does not exist, add it first + if (!target!!.inventory.hasItem(item)) { + target!!.inventory.add(item) + } + + target!!.inventory.itemEquipped[item.equipPosition] = item } - - target.inventory.itemEquipped[item.equipPosition] = item } override fun printUsage() { diff --git a/src/net/torvald/terrarum/console/SetAV.kt b/src/net/torvald/terrarum/console/SetAV.kt index 02c14e490..28461e4f1 100644 --- a/src/net/torvald/terrarum/console/SetAV.kt +++ b/src/net/torvald/terrarum/console/SetAV.kt @@ -66,7 +66,7 @@ internal object SetAV : ConsoleCommand { return } - Terrarum.ingame!!.player.actorValue[args[1]] = newValue + Terrarum.ingame!!.player!!.actorValue[args[1]] = newValue Echo("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$newValue") println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.") } diff --git a/src/net/torvald/terrarum/console/SetScale.kt b/src/net/torvald/terrarum/console/SetScale.kt index 5811930e8..a45854a44 100644 --- a/src/net/torvald/terrarum/console/SetScale.kt +++ b/src/net/torvald/terrarum/console/SetScale.kt @@ -10,7 +10,7 @@ object SetScale : ConsoleCommand { override fun execute(args: Array) { if (args.size == 2 || args.size == 3) { try { - val targetID = if (args.size == 3) args[1].toInt() else Terrarum.ingame!!.player.referenceID + val targetID = if (args.size == 3) args[1].toInt() else Terrarum.ingame!!.player!!.referenceID val scale = args[if (args.size == 3) 2 else 1].toDouble() val target = Terrarum.ingame!!.getActorByID(targetID) diff --git a/src/net/torvald/terrarum/console/Teleport.kt b/src/net/torvald/terrarum/console/Teleport.kt index 0f36f64db..01bd3f64e 100644 --- a/src/net/torvald/terrarum/console/Teleport.kt +++ b/src/net/torvald/terrarum/console/Teleport.kt @@ -24,7 +24,7 @@ internal object Teleport : ConsoleCommand { return } - Terrarum.ingame!!.player.setPosition(x.toDouble(), y.toDouble()) + Terrarum.ingame!!.player!!.setPosition(x.toDouble(), y.toDouble()) } else if (args.size == 4) { if (args[2].toLowerCase() != "to") { @@ -36,7 +36,7 @@ internal object Teleport : ConsoleCommand { try { val fromActorID = args[1].toInt() val targetActorID = if (args[3].toLowerCase() == "player") - Terrarum.ingame!!.player.referenceID + Terrarum.ingame!!.player!!.referenceID else args[3].toInt() diff --git a/src/net/torvald/terrarum/console/ToggleNoClip.kt b/src/net/torvald/terrarum/console/ToggleNoClip.kt index ca110ab05..1327e01f9 100644 --- a/src/net/torvald/terrarum/console/ToggleNoClip.kt +++ b/src/net/torvald/terrarum/console/ToggleNoClip.kt @@ -8,9 +8,9 @@ import net.torvald.terrarum.Terrarum */ internal object ToggleNoClip : ConsoleCommand { override fun execute(args: Array) { - val status = Terrarum.ingame!!.player.isNoClip() + val status = Terrarum.ingame!!.player!!.isNoClip() - Terrarum.ingame!!.player.setNoClip(!status) + Terrarum.ingame!!.player!!.setNoClip(!status) Echo("Set no-clip status to " + (!status).toString()) } diff --git a/src/net/torvald/terrarum/debuggerapp/ActorValueTracker.kt b/src/net/torvald/terrarum/debuggerapp/ActorValueTracker.kt index 6281077ab..4ca286e36 100644 --- a/src/net/torvald/terrarum/debuggerapp/ActorValueTracker.kt +++ b/src/net/torvald/terrarum/debuggerapp/ActorValueTracker.kt @@ -19,7 +19,7 @@ import javax.swing.* */ class ActorValueTracker constructor() : JFrame() { - constructor(actor: Actor) : this() { + constructor(actor: Actor?) : this() { setTrackingActor(actor) } @@ -146,8 +146,8 @@ class ActorValueTracker constructor() : JFrame() { this.isVisible = true } - fun setTrackingActor(actor: Actor) { - this.actorValue = actor.actorValue + fun setTrackingActor(actor: Actor?) { + this.actorValue = actor?.actorValue this.title = "AVTracker — $actor" diff --git a/src/net/torvald/terrarum/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/gameactors/ActorInventory.kt index c18aabb89..cd59e77ae 100644 --- a/src/net/torvald/terrarum/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/gameactors/ActorInventory.kt @@ -12,7 +12,7 @@ import java.util.concurrent.locks.ReentrantLock * Created by minjaesong on 16-03-15. */ -class ActorInventory(val actor: Pocketed, var maxCapacity: Int, private var capacityMode: Int) { +class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode: Int) { companion object { @Transient val CAPACITY_MODE_NO_ENCUMBER = 0 @@ -34,10 +34,10 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, private var capa fun add(itemID: Int, count: Int = 1) = add(ItemCodex[itemID], count) fun add(item: InventoryItem, count: Int = 1) { - if (item.id == Player.PLAYER_REF_ID) + if (item.id == Player.PLAYER_REF_ID || item.id == 0x51621D) // do not delete this magic throw IllegalArgumentException("Attempted to put human player into the inventory.") if (Terrarum.ingame != null && - item.id == Terrarum.ingame!!.player.referenceID) + (item.id == Terrarum.ingame?.player?.referenceID)) throw IllegalArgumentException("Attempted to put active player into the inventory.") // If we already have the item, increment the amount @@ -67,10 +67,10 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, private var capa add(item, -count) } else { - // depleted item; remove entry from inventory - itemList.remove(existingItem) // unequip, if applicable actor.unequipItem(existingItem.item) + // depleted item; remove entry from inventory + itemList.remove(existingItem) } } else { diff --git a/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt b/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt index dbc7a68f1..cfea0ebf8 100644 --- a/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt +++ b/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt @@ -75,7 +75,7 @@ object PlayerBuilderSigrid { // Test fill up inventory - p.inventory.add(16) + p.inventory.add(16, 512) p.equipItem(ItemCodex[16]) diff --git a/src/net/torvald/terrarum/gamecontroller/GameController.kt b/src/net/torvald/terrarum/gamecontroller/GameController.kt index 2d839e114..a269fa7d2 100644 --- a/src/net/torvald/terrarum/gamecontroller/GameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/GameController.kt @@ -70,15 +70,17 @@ object GameController { /////////////////// // Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP) - if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")) || input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) { - val itemOnGrip = ingame.player.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP] + if (ingame.player != null) { + if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")) || input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) { + val itemOnGrip = ingame.player!!.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP] - if (itemOnGrip != null) { - if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) { - ingame.player.consumePrimary(itemOnGrip) - } - else if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) { - ingame.player.consumeSecondary(itemOnGrip) + if (itemOnGrip != null) { + if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) { + ingame.player!!.consumePrimary(itemOnGrip) + } + else if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) { + ingame.player!!.consumeSecondary(itemOnGrip) + } } } } diff --git a/src/net/torvald/terrarum/gameitem/InventoryItem.kt b/src/net/torvald/terrarum/gameitem/InventoryItem.kt index 3bf2fefa3..a37b5acae 100644 --- a/src/net/torvald/terrarum/gameitem/InventoryItem.kt +++ b/src/net/torvald/terrarum/gameitem/InventoryItem.kt @@ -113,6 +113,8 @@ abstract class InventoryItem : Comparable { * The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item) * * @return true when used successfully, false otherwise + * + * note: DO NOT super(gc, g) this! */ open fun primaryUse(gc: GameContainer, delta: Int): Boolean = false @@ -121,6 +123,8 @@ abstract class InventoryItem : Comparable { * The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item) * * @return true when used successfully, false otherwise + * + * note: DO NOT super(gc, g) this! */ open fun secondaryUse(gc: GameContainer, delta: Int): Boolean = false diff --git a/src/net/torvald/terrarum/mapdrawer/MapCamera.kt b/src/net/torvald/terrarum/mapdrawer/MapCamera.kt index 7cd35d287..4852dc342 100644 --- a/src/net/torvald/terrarum/mapdrawer/MapCamera.kt +++ b/src/net/torvald/terrarum/mapdrawer/MapCamera.kt @@ -34,9 +34,9 @@ object MapCamera { // position - (WH / 2) x = Math.round(// X only: ROUNDWORLD implementation - player.hitbox.centeredX.toFloat() - width / 2) + (player?.hitbox?.centeredX?.toFloat() ?: 0f) - width / 2) y = Math.round(FastMath.clamp( - player.hitbox.centeredY.toFloat() - height / 2, + (player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2, TILE_SIZE.toFloat(), world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat() )) diff --git a/src/net/torvald/terrarum/tilestats/TileStats.kt b/src/net/torvald/terrarum/tilestats/TileStats.kt index 36eec3c2c..f5199c867 100644 --- a/src/net/torvald/terrarum/tilestats/TileStats.kt +++ b/src/net/torvald/terrarum/tilestats/TileStats.kt @@ -34,9 +34,9 @@ object TileStats { val renderHeight = FastMath.ceil(Terrarum.HEIGHT.toFloat()) val noZoomCameraX = Math.round(FastMath.clamp( - player.hitbox.centeredX.toFloat() - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat())) + (player?.hitbox?.centeredX?.toFloat() ?: 0f) - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat())) val noZoomCameraY = Math.round(FastMath.clamp( - player.hitbox.centeredY.toFloat() - renderHeight / 2, TSIZE.toFloat(), map.width * TSIZE - renderHeight - TSIZE.toFloat())) + (player?.hitbox?.centeredY?.toFloat() ?: 0f) - renderHeight / 2, TSIZE.toFloat(), map.width * TSIZE - renderHeight - TSIZE.toFloat())) val for_x_start = noZoomCameraX / TSIZE val for_y_start = noZoomCameraY / TSIZE diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index 09a186a45..1fd60ba9c 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -45,13 +45,13 @@ class BasicDebugInfoWindow : UICanvas { override fun update(gc: GameContainer, delta: Int) { val player = Terrarum.ingame!!.player - val hitbox = player.hitbox + val hitbox = player?.hitbox - xdelta = hitbox.pointedX - prevPlayerX - ydelta = hitbox.pointedY - prevPlayerY + xdelta = hitbox?.pointedX ?: 0 - prevPlayerX + ydelta = hitbox?.pointedY ?: 0 - prevPlayerY - prevPlayerX = hitbox.pointedX - prevPlayerY = hitbox.pointedY + prevPlayerX = hitbox?.pointedX ?: 0.0 + prevPlayerY = hitbox?.pointedY ?: 0.0 } override fun render(gc: GameContainer, g: Graphics) { @@ -67,8 +67,8 @@ class BasicDebugInfoWindow : UICanvas { g.font = Terrarum.fontSmallNumbers g.color = GameFontBase.codeToCol["y"] - val hitbox = player.hitbox - val nextHitbox = player.nextHitbox + val hitbox = player?.hitbox + val nextHitbox = player?.nextHitbox /** * First column @@ -76,25 +76,25 @@ class BasicDebugInfoWindow : UICanvas { printLine(g, 1, "posX " + ccG - + "${hitbox.pointedX}" + + "${hitbox?.pointedX}" + " (" - + "${(hitbox.pointedX / FeaturesDrawer.TILE_SIZE).toInt()}" + + "${(hitbox?.pointedX?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}" + ")") printLine(g, 2, "posY " + ccG - + hitbox.pointedY.toString() + + hitbox?.pointedY.toString() + " (" - + (hitbox.pointedY / FeaturesDrawer.TILE_SIZE).toInt().toString() + + (hitbox?.pointedY?.div(FeaturesDrawer.TILE_SIZE))?.toInt().toString() + ")") - printLine(g, 3, "veloX reported $ccG${player.moveDelta.x}") - printLine(g, 4, "veloY reported $ccG${player.moveDelta.y}") + printLine(g, 3, "veloX reported $ccG${player?.moveDelta?.x}") + printLine(g, 4, "veloY reported $ccG${player?.moveDelta?.y}") printLineColumn(g, 2, 3, "veloX measured $ccG${xdelta}") printLineColumn(g, 2, 4, "veloY measured $ccG${ydelta}") - printLine(g, 5, "grounded $ccG${player.grounded}") - printLine(g, 6, "noClip $ccG${player.noClip}") + printLine(g, 5, "grounded $ccG${player?.grounded}") + printLine(g, 6, "noClip $ccG${player?.noClip}") //printLine(g, 7, "jump $ccG${player.jumpAcc}") @@ -129,10 +129,10 @@ class BasicDebugInfoWindow : UICanvas { printLineColumn(g, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp) printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame!!.world.time.todaySeconds.toString().padStart(5, '0')}" + " (${Terrarum.ingame!!.world.time.getFormattedTime()})") - printLineColumn(g, 2, 6, "Mass $ccG${player.mass}") + printLineColumn(g, 2, 6, "Mass $ccG${player?.mass}") - printLineColumn(g, 2, 7, "p_WalkX $ccG${player.walkX}") - printLineColumn(g, 2, 8, "p_WalkY $ccG${player.walkY}") + printLineColumn(g, 2, 7, "p_WalkX $ccG${player?.walkX}") + printLineColumn(g, 2, 8, "p_WalkY $ccG${player?.walkY}") drawHistogram(g, LightmapRenderer.histogram, diff --git a/src/net/torvald/terrarum/ui/UIInventory.kt b/src/net/torvald/terrarum/ui/UIInventory.kt index 925394a63..cc9937b9e 100644 --- a/src/net/torvald/terrarum/ui/UIInventory.kt +++ b/src/net/torvald/terrarum/ui/UIInventory.kt @@ -5,6 +5,7 @@ import net.torvald.terrarum.Terrarum.QUICKSLOT_MAX 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.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.langpack.Lang @@ -125,6 +126,9 @@ class UIInventory( private var oldCatSelect = -1 + private var encumbrancePerc = 0f + private var isEncumbered = false + override fun update(gc: GameContainer, delta: Int) { catButtons.update(gc, delta) @@ -140,6 +144,12 @@ class UIInventory( if (rebuildList) { val filter = catButtonsToCatIdent[catButtons.selectedButton.labelText] + // encumbrance + encumbrancePerc = inventory!!.capacity.toFloat() / inventory!!.maxCapacity + isEncumbered = inventory!!.isEncumbered + + + inventorySortList = ArrayList() // filter items @@ -250,12 +260,14 @@ class UIInventory( ) // encumbrance bar blendNormal() - val encumbPerc = inventory!!.capacity.toFloat() / inventory!!.maxCapacity - g.color = if (inventory!!.isEncumbered) Color(0xccff0000.toInt()) else Color(0xcc00ff00.toInt()) + g.color = if (isEncumbered) Color(0xccff0000.toInt()) else Color(0xcc00ff00.toInt()) g.fillRect( width - 3 - weightBarWidth, height - controlHelpHeight + 3f, - minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbPerc)), // make sure 1px is always be seen + if (actor?.inventory?.capacityMode == CAPACITY_MODE_NO_ENCUMBER) + 1f + else // make sure 1px is always be seen + minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbrancePerc)), controlHelpHeight - 5f ) } diff --git a/src/net/torvald/terrarum/ui/UIPieMenu.kt b/src/net/torvald/terrarum/ui/UIPieMenu.kt index 54fdb2d82..64c0383f8 100644 --- a/src/net/torvald/terrarum/ui/UIPieMenu.kt +++ b/src/net/torvald/terrarum/ui/UIPieMenu.kt @@ -34,11 +34,11 @@ class UIPieMenu : UICanvas { var selection: Int = -1 override fun update(gc: GameContainer, delta: Int) { - if (selection >= 0) - Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = - selection % slotCount - - + if (Terrarum.ingame!!.player != null) { + if (selection >= 0) + Terrarum.ingame!!.player!!.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = + selection % slotCount + } } override fun render(gc: GameContainer, g: Graphics) { diff --git a/src/net/torvald/terrarum/ui/UIQuickBar.kt b/src/net/torvald/terrarum/ui/UIQuickBar.kt index fa5399e32..7bb87df32 100644 --- a/src/net/torvald/terrarum/ui/UIQuickBar.kt +++ b/src/net/torvald/terrarum/ui/UIQuickBar.kt @@ -25,8 +25,8 @@ class UIQuickBar : UICanvas, MouseControlled { override var handler: UIHandler? = null private var selection: Int - get() = Terrarum.ingame!!.player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0 - set(value) { Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = value } + get() = Terrarum.ingame!!.player?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0 + set(value) { Terrarum.ingame!!.player?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value) } override fun update(gc: GameContainer, delta: Int) { } diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index ff1101e4b..48a4174b5 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -81,17 +81,20 @@ object WeatherMixer { currentWeather = weatherList[WEATHER_GENERIC]!![0] - // test rain toggled by F2 - if (KeyToggler.isOn(Key.F2)) { - val playerPos = Terrarum.ingame!!.player.centrePosPoint - kotlin.repeat(4) { // 4 seems good - val rainParticle = ParticleTestRain( - playerPos.x + HQRNG().nextInt(Terrarum.WIDTH) - Terrarum.HALFW, - playerPos.y - Terrarum.HALFH - ) - Terrarum.ingame!!.addParticle(rainParticle) + if (Terrarum.ingame!!.player != null) { + // test rain toggled by F2 + if (KeyToggler.isOn(Key.F2)) { + val playerPos = Terrarum.ingame!!.player!!.centrePosPoint + kotlin.repeat(4) { + // 4 seems good + val rainParticle = ParticleTestRain( + playerPos.x + HQRNG().nextInt(Terrarum.WIDTH) - Terrarum.HALFW, + playerPos.y - Terrarum.HALFH + ) + Terrarum.ingame!!.addParticle(rainParticle) + } + globalLightNow.set(getGlobalLightOfTime(world.time.todaySeconds).darker(0.3f)) } - globalLightNow.set(getGlobalLightOfTime(world.time.todaySeconds).darker(0.3f)) } }