setting up the inventory using builder (during init) requires ingame.player to be nullable, lateinit won't work

This commit is contained in:
Song Minjae
2017-04-11 23:07:29 +09:00
parent 1301121aa9
commit 037e84d6e2
21 changed files with 132 additions and 103 deletions

View File

@@ -71,9 +71,10 @@ class StateInGame : BasicGameState() {
lateinit var debugWindow: UIHandler lateinit var debugWindow: UIHandler
lateinit var notifier: 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 :) private var playableActorDelegate: PlayableActorDelegate? = null // DO NOT LATEINIT!
get() = playableActorDelegate.actor internal val player: ActorHumanoid? // currently POSSESSED actor :)
get() = playableActorDelegate?.actor
var screenZoom = 1.0f var screenZoom = 1.0f
val ZOOM_MAX = 2.0f val ZOOM_MAX = 2.0f
@@ -141,9 +142,9 @@ class StateInGame : BasicGameState() {
// add new player and put it to actorContainer // add new player and put it to actorContainer
//playableActorDelegate = PlayableActorDelegate(PlayerBuilderSigrid()) playableActorDelegate = PlayableActorDelegate(PlayerBuilderSigrid())
playableActorDelegate = PlayableActorDelegate(PlayerBuilderTestSubject1()) //playableActorDelegate = PlayableActorDelegate(PlayerBuilderTestSubject1())
addNewActor(player) addNewActor(player!!)
// test actor // test actor
@@ -342,10 +343,10 @@ class StateInGame : BasicGameState() {
} }
// take care of old delegate // take care of old delegate
playableActorDelegate.actor.collisionType = HumanoidNPC.DEFAULT_COLLISION_TYPE playableActorDelegate!!.actor.collisionType = HumanoidNPC.DEFAULT_COLLISION_TYPE
// accept new delegate // accept new delegate
playableActorDelegate = PlayableActorDelegate(getActorByID(refid) as ActorHumanoid) playableActorDelegate = PlayableActorDelegate(getActorByID(refid) as ActorHumanoid)
playableActorDelegate.actor.collisionType = ActorWithSprite.COLLISION_KINEMATIC playableActorDelegate!!.actor.collisionType = ActorWithSprite.COLLISION_KINEMATIC
WorldSimulator(player, UPDATE_DELTA) WorldSimulator(player, UPDATE_DELTA)
} }
@@ -392,7 +393,7 @@ class StateInGame : BasicGameState() {
///////////////// /////////////////
actorsRenderMiddle.forEach { it.drawBody(worldG) } actorsRenderMiddle.forEach { it.drawBody(worldG) }
actorsRenderMidTop.forEach { it.drawBody(worldG) } actorsRenderMidTop.forEach { it.drawBody(worldG) }
player.drawBody(worldG) player?.drawBody(worldG)
actorsRenderFront.forEach { it.drawBody(worldG) } actorsRenderFront.forEach { it.drawBody(worldG) }
// --> Change of blend mode <-- introduced by ActorVisible // // --> Change of blend mode <-- introduced by ActorVisible //
@@ -419,7 +420,7 @@ class StateInGame : BasicGameState() {
////////////////////// //////////////////////
actorsRenderMiddle.forEach { it.drawGlow(worldG) } actorsRenderMiddle.forEach { it.drawGlow(worldG) }
actorsRenderMidTop.forEach { it.drawGlow(worldG) } actorsRenderMidTop.forEach { it.drawGlow(worldG) }
player.drawGlow(worldG) player?.drawGlow(worldG)
actorsRenderFront.forEach { it.drawGlow(worldG) } actorsRenderFront.forEach { it.drawGlow(worldG) }
// --> blendLightenOnly() <-- introduced by ActorVisible // // --> blendLightenOnly() <-- introduced by ActorVisible //
@@ -521,7 +522,7 @@ class StateInGame : BasicGameState() {
GameController.keyPressed(key, c) GameController.keyPressed(key, c)
if (canPlayerMove) { if (canPlayerMove) {
player.keyPressed(key, c) player?.keyPressed(key, c)
} }
if (Terrarum.getConfigIntArray("keyquickselalt").contains(key) if (Terrarum.getConfigIntArray("keyquickselalt").contains(key)
@@ -747,7 +748,8 @@ class StateInGame : BasicGameState() {
* This is how remove function of [java.util.ArrayList] is defined. * This is how remove function of [java.util.ArrayList] is defined.
*/ */
fun removeActor(actor: Actor) { 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) val indexToDelete = actorContainer.binarySearch(actor.referenceID)
if (indexToDelete >= 0) { if (indexToDelete >= 0) {
actorContainer.removeAt(indexToDelete) actorContainer.removeAt(indexToDelete)

View File

@@ -138,11 +138,11 @@ class UIItemInventoryElem(
val itemEquipSlot = item!!.equipPosition val itemEquipSlot = item!!.equipPosition
val player = Terrarum.ingame!!.player val player = Terrarum.ingame!!.player
if (item != player.inventory.itemEquipped[itemEquipSlot]) { // if this item is unequipped, equip it if (item != player?.inventory?.itemEquipped?.get(itemEquipSlot)) { // if this item is unequipped, equip it
player.equipItem(item!!) player?.equipItem(item!!)
} }
else { // if not, unequip it else { // if not, unequip it
player.unequipItem(item!!) player?.unequipItem(item!!)
} }
} }

View File

@@ -13,7 +13,7 @@ internal object ExportAV : ConsoleCommand {
if (args.size == 2) { if (args.size == 2) {
try { try {
JsonWriter.writeToFile( JsonWriter.writeToFile(
Terrarum.ingame!!.player.actorValue, Terrarum.ingame!!.player!!.actorValue,
Terrarum.defaultDir + "/Exports/" + args[1] + ".json") Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
Echo("ExportAV: exported to " + args[1] + ".json") Echo("ExportAV: exported to " + args[1] + ".json")

View File

@@ -17,9 +17,9 @@ internal object GetAV : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
try { try {
if (args.size == 1) { if (args.size == 1 && Terrarum.ingame!!.player != null) {
// print all actorvalue of player // print all actorvalue of player
val av = Terrarum.ingame!!.player.actorValue val av = Terrarum.ingame!!.player!!.actorValue
val keyset = av.keySet val keyset = av.keySet
Echo("$ccW== ActorValue list for ${ccY}player $ccW==") 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 if (!args[1].isNum()) { // args[1] is ActorValue name
Echo("${ccW}player.$ccM${args[1]} $ccW= " + Echo("${ccW}player.$ccM${args[1]} $ccW= " +
ccG + ccG +
Terrarum.ingame!!.player.actorValue[args[1]] + Terrarum.ingame!!.player!!.actorValue[args[1]] +
" $ccO" + " $ccO" +
Terrarum.ingame!!.player.actorValue[args[1]]!!.javaClass.simpleName Terrarum.ingame!!.player!!.actorValue[args[1]]!!.javaClass.simpleName
) )
println("[GetAV] player.${args[1]} = " + 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 { else {

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarum.itemproperties.ItemCodex
*/ */
internal object Inventory : ConsoleCommand { internal object Inventory : ConsoleCommand {
private var target: Pocketed = Terrarum.ingame!!.player private var target: Pocketed? = Terrarum.ingame!!.player
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
if (args.size == 1) { if (args.size == 1) {
@@ -30,15 +30,17 @@ internal object Inventory : ConsoleCommand {
} }
private fun listInventory() { private fun listInventory() {
if (target.inventory.getTotalUniqueCount() == 0) { if (target != null) {
Echo("(inventory empty)") if (target!!.inventory.getTotalUniqueCount() == 0) {
} Echo("(inventory empty)")
else { }
target.inventory.forEach { else {
if (it.amount == 0) { target!!.inventory.forEach {
EchoError("Unexpected zero-amounted item: ID ${it.item.id}") 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) { 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) { 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 the item does not exist, add it first
if (!target.inventory.hasItem(item)) { if (!target!!.inventory.hasItem(item)) {
target.inventory.add(item) target!!.inventory.add(item)
}
target!!.inventory.itemEquipped[item.equipPosition] = item
} }
target.inventory.itemEquipped[item.equipPosition] = item
} }
override fun printUsage() { override fun printUsage() {

View File

@@ -66,7 +66,7 @@ internal object SetAV : ConsoleCommand {
return 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") Echo("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$newValue")
println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.") println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.")
} }

View File

@@ -10,7 +10,7 @@ object SetScale : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
if (args.size == 2 || args.size == 3) { if (args.size == 2 || args.size == 3) {
try { 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 scale = args[if (args.size == 3) 2 else 1].toDouble()
val target = Terrarum.ingame!!.getActorByID(targetID) val target = Terrarum.ingame!!.getActorByID(targetID)

View File

@@ -24,7 +24,7 @@ internal object Teleport : ConsoleCommand {
return return
} }
Terrarum.ingame!!.player.setPosition(x.toDouble(), y.toDouble()) Terrarum.ingame!!.player!!.setPosition(x.toDouble(), y.toDouble())
} }
else if (args.size == 4) { else if (args.size == 4) {
if (args[2].toLowerCase() != "to") { if (args[2].toLowerCase() != "to") {
@@ -36,7 +36,7 @@ internal object Teleport : ConsoleCommand {
try { try {
val fromActorID = args[1].toInt() val fromActorID = args[1].toInt()
val targetActorID = if (args[3].toLowerCase() == "player") val targetActorID = if (args[3].toLowerCase() == "player")
Terrarum.ingame!!.player.referenceID Terrarum.ingame!!.player!!.referenceID
else else
args[3].toInt() args[3].toInt()

View File

@@ -8,9 +8,9 @@ import net.torvald.terrarum.Terrarum
*/ */
internal object ToggleNoClip : ConsoleCommand { internal object ToggleNoClip : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
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()) Echo("Set no-clip status to " + (!status).toString())
} }

View File

@@ -19,7 +19,7 @@ import javax.swing.*
*/ */
class ActorValueTracker constructor() : JFrame() { class ActorValueTracker constructor() : JFrame() {
constructor(actor: Actor) : this() { constructor(actor: Actor?) : this() {
setTrackingActor(actor) setTrackingActor(actor)
} }
@@ -146,8 +146,8 @@ class ActorValueTracker constructor() : JFrame() {
this.isVisible = true this.isVisible = true
} }
fun setTrackingActor(actor: Actor) { fun setTrackingActor(actor: Actor?) {
this.actorValue = actor.actorValue this.actorValue = actor?.actorValue
this.title = "AVTracker — $actor" this.title = "AVTracker — $actor"

View File

@@ -12,7 +12,7 @@ import java.util.concurrent.locks.ReentrantLock
* Created by minjaesong on 16-03-15. * 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 { companion object {
@Transient val CAPACITY_MODE_NO_ENCUMBER = 0 @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(itemID: Int, count: Int = 1) = add(ItemCodex[itemID], count)
fun add(item: InventoryItem, count: Int = 1) { 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.") throw IllegalArgumentException("Attempted to put human player into the inventory.")
if (Terrarum.ingame != null && 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.") throw IllegalArgumentException("Attempted to put active player into the inventory.")
// If we already have the item, increment the amount // 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) add(item, -count)
} }
else { else {
// depleted item; remove entry from inventory
itemList.remove(existingItem)
// unequip, if applicable // unequip, if applicable
actor.unequipItem(existingItem.item) actor.unequipItem(existingItem.item)
// depleted item; remove entry from inventory
itemList.remove(existingItem)
} }
} }
else { else {

View File

@@ -75,7 +75,7 @@ object PlayerBuilderSigrid {
// Test fill up inventory // Test fill up inventory
p.inventory.add(16) p.inventory.add(16, 512)
p.equipItem(ItemCodex[16]) p.equipItem(ItemCodex[16])

View File

@@ -70,15 +70,17 @@ object GameController {
/////////////////// ///////////////////
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP) // Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")) || input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) { if (ingame.player != null) {
val itemOnGrip = ingame.player.inventory.itemEquipped[InventoryItem.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 (itemOnGrip != null) { if (itemOnGrip != null) {
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) { if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) {
ingame.player.consumePrimary(itemOnGrip) ingame.player!!.consumePrimary(itemOnGrip)
} }
else if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) { else if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
ingame.player.consumeSecondary(itemOnGrip) ingame.player!!.consumeSecondary(itemOnGrip)
}
} }
} }
} }

View File

@@ -113,6 +113,8 @@ abstract class InventoryItem : Comparable<InventoryItem> {
* The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item) * 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 * @return true when used successfully, false otherwise
*
* note: DO NOT super(gc, g) this!
*/ */
open fun primaryUse(gc: GameContainer, delta: Int): Boolean = false open fun primaryUse(gc: GameContainer, delta: Int): Boolean = false
@@ -121,6 +123,8 @@ abstract class InventoryItem : Comparable<InventoryItem> {
* The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item) * 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 * @return true when used successfully, false otherwise
*
* note: DO NOT super(gc, g) this!
*/ */
open fun secondaryUse(gc: GameContainer, delta: Int): Boolean = false open fun secondaryUse(gc: GameContainer, delta: Int): Boolean = false

View File

@@ -34,9 +34,9 @@ object MapCamera {
// position - (WH / 2) // position - (WH / 2)
x = Math.round(// X only: ROUNDWORLD implementation 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( y = Math.round(FastMath.clamp(
player.hitbox.centeredY.toFloat() - height / 2, (player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2,
TILE_SIZE.toFloat(), TILE_SIZE.toFloat(),
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat() world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
)) ))

View File

@@ -34,9 +34,9 @@ object TileStats {
val renderHeight = FastMath.ceil(Terrarum.HEIGHT.toFloat()) val renderHeight = FastMath.ceil(Terrarum.HEIGHT.toFloat())
val noZoomCameraX = Math.round(FastMath.clamp( 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( 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_x_start = noZoomCameraX / TSIZE
val for_y_start = noZoomCameraY / TSIZE val for_y_start = noZoomCameraY / TSIZE

View File

@@ -45,13 +45,13 @@ class BasicDebugInfoWindow : UICanvas {
override fun update(gc: GameContainer, delta: Int) { override fun update(gc: GameContainer, delta: Int) {
val player = Terrarum.ingame!!.player val player = Terrarum.ingame!!.player
val hitbox = player.hitbox val hitbox = player?.hitbox
xdelta = hitbox.pointedX - prevPlayerX xdelta = hitbox?.pointedX ?: 0 - prevPlayerX
ydelta = hitbox.pointedY - prevPlayerY ydelta = hitbox?.pointedY ?: 0 - prevPlayerY
prevPlayerX = hitbox.pointedX prevPlayerX = hitbox?.pointedX ?: 0.0
prevPlayerY = hitbox.pointedY prevPlayerY = hitbox?.pointedY ?: 0.0
} }
override fun render(gc: GameContainer, g: Graphics) { override fun render(gc: GameContainer, g: Graphics) {
@@ -67,8 +67,8 @@ class BasicDebugInfoWindow : UICanvas {
g.font = Terrarum.fontSmallNumbers g.font = Terrarum.fontSmallNumbers
g.color = GameFontBase.codeToCol["y"] g.color = GameFontBase.codeToCol["y"]
val hitbox = player.hitbox val hitbox = player?.hitbox
val nextHitbox = player.nextHitbox val nextHitbox = player?.nextHitbox
/** /**
* First column * First column
@@ -76,25 +76,25 @@ class BasicDebugInfoWindow : UICanvas {
printLine(g, 1, "posX " printLine(g, 1, "posX "
+ ccG + ccG
+ "${hitbox.pointedX}" + "${hitbox?.pointedX}"
+ " (" + " ("
+ "${(hitbox.pointedX / FeaturesDrawer.TILE_SIZE).toInt()}" + "${(hitbox?.pointedX?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
+ ")") + ")")
printLine(g, 2, "posY " printLine(g, 2, "posY "
+ ccG + 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, 3, "veloX reported $ccG${player?.moveDelta?.x}")
printLine(g, 4, "veloY reported $ccG${player.moveDelta.y}") printLine(g, 4, "veloY reported $ccG${player?.moveDelta?.y}")
printLineColumn(g, 2, 3, "veloX measured $ccG${xdelta}") printLineColumn(g, 2, 3, "veloX measured $ccG${xdelta}")
printLineColumn(g, 2, 4, "veloY measured $ccG${ydelta}") printLineColumn(g, 2, 4, "veloY measured $ccG${ydelta}")
printLine(g, 5, "grounded $ccG${player.grounded}") printLine(g, 5, "grounded $ccG${player?.grounded}")
printLine(g, 6, "noClip $ccG${player.noClip}") printLine(g, 6, "noClip $ccG${player?.noClip}")
//printLine(g, 7, "jump $ccG${player.jumpAcc}") //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, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp)
printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame!!.world.time.todaySeconds.toString().padStart(5, '0')}" + printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame!!.world.time.todaySeconds.toString().padStart(5, '0')}" +
" (${Terrarum.ingame!!.world.time.getFormattedTime()})") " (${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, 7, "p_WalkX $ccG${player?.walkX}")
printLineColumn(g, 2, 8, "p_WalkY $ccG${player.walkY}") printLineColumn(g, 2, 8, "p_WalkY $ccG${player?.walkY}")
drawHistogram(g, LightmapRenderer.histogram, drawHistogram(g, LightmapRenderer.histogram,

View File

@@ -5,6 +5,7 @@ import net.torvald.terrarum.Terrarum.QUICKSLOT_MAX
import net.torvald.terrarum.Terrarum.joypadLabelNinA import net.torvald.terrarum.Terrarum.joypadLabelNinA
import net.torvald.terrarum.Terrarum.joypadLabelNinY import net.torvald.terrarum.Terrarum.joypadLabelNinY
import net.torvald.terrarum.gameactors.* 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.gameitem.InventoryItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
@@ -125,6 +126,9 @@ class UIInventory(
private var oldCatSelect = -1 private var oldCatSelect = -1
private var encumbrancePerc = 0f
private var isEncumbered = false
override fun update(gc: GameContainer, delta: Int) { override fun update(gc: GameContainer, delta: Int) {
catButtons.update(gc, delta) catButtons.update(gc, delta)
@@ -140,6 +144,12 @@ class UIInventory(
if (rebuildList) { if (rebuildList) {
val filter = catButtonsToCatIdent[catButtons.selectedButton.labelText] val filter = catButtonsToCatIdent[catButtons.selectedButton.labelText]
// encumbrance
encumbrancePerc = inventory!!.capacity.toFloat() / inventory!!.maxCapacity
isEncumbered = inventory!!.isEncumbered
inventorySortList = ArrayList<InventoryPair>() inventorySortList = ArrayList<InventoryPair>()
// filter items // filter items
@@ -250,12 +260,14 @@ class UIInventory(
) )
// encumbrance bar // encumbrance bar
blendNormal() blendNormal()
val encumbPerc = inventory!!.capacity.toFloat() / inventory!!.maxCapacity g.color = if (isEncumbered) Color(0xccff0000.toInt()) else Color(0xcc00ff00.toInt())
g.color = if (inventory!!.isEncumbered) Color(0xccff0000.toInt()) else Color(0xcc00ff00.toInt())
g.fillRect( g.fillRect(
width - 3 - weightBarWidth, width - 3 - weightBarWidth,
height - controlHelpHeight + 3f, 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 controlHelpHeight - 5f
) )
} }

View File

@@ -34,11 +34,11 @@ class UIPieMenu : UICanvas {
var selection: Int = -1 var selection: Int = -1
override fun update(gc: GameContainer, delta: Int) { override fun update(gc: GameContainer, delta: Int) {
if (selection >= 0) if (Terrarum.ingame!!.player != null) {
Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = if (selection >= 0)
selection % slotCount Terrarum.ingame!!.player!!.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
selection % slotCount
}
} }
override fun render(gc: GameContainer, g: Graphics) { override fun render(gc: GameContainer, g: Graphics) {

View File

@@ -25,8 +25,8 @@ class UIQuickBar : UICanvas, MouseControlled {
override var handler: UIHandler? = null override var handler: UIHandler? = null
private var selection: Int private var selection: Int
get() = Terrarum.ingame!!.player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0 get() = Terrarum.ingame!!.player?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = value } set(value) { Terrarum.ingame!!.player?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value) }
override fun update(gc: GameContainer, delta: Int) { override fun update(gc: GameContainer, delta: Int) {
} }

View File

@@ -81,17 +81,20 @@ object WeatherMixer {
currentWeather = weatherList[WEATHER_GENERIC]!![0] currentWeather = weatherList[WEATHER_GENERIC]!![0]
// test rain toggled by F2 if (Terrarum.ingame!!.player != null) {
if (KeyToggler.isOn(Key.F2)) { // test rain toggled by F2
val playerPos = Terrarum.ingame!!.player.centrePosPoint if (KeyToggler.isOn(Key.F2)) {
kotlin.repeat(4) { // 4 seems good val playerPos = Terrarum.ingame!!.player!!.centrePosPoint
val rainParticle = ParticleTestRain( kotlin.repeat(4) {
playerPos.x + HQRNG().nextInt(Terrarum.WIDTH) - Terrarum.HALFW, // 4 seems good
playerPos.y - Terrarum.HALFH val rainParticle = ParticleTestRain(
) playerPos.x + HQRNG().nextInt(Terrarum.WIDTH) - Terrarum.HALFW,
Terrarum.ingame!!.addParticle(rainParticle) 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))
} }
} }