player is now nullable; wtf is calling Ingame 5 times?

This commit is contained in:
minjaesong
2018-09-17 01:46:50 +09:00
parent 967eafe8a3
commit 03b642ddd3
35 changed files with 252 additions and 150 deletions

View File

@@ -41,14 +41,17 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
if (ingame.canPlayerControl) {
if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary")) || Gdx.input.isButtonPressed(Terrarum.getConfigInt("mousesecondary"))) {
val itemOnGrip = ingame.playableActor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
val itemOnGrip = player.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
itemOnGrip?.let {
if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary"))) {
ingame.playableActor.consumePrimary(it)
player.consumePrimary(it)
}
if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mousesecondary"))) {
ingame.playableActor.consumeSecondary(it)
player.consumeSecondary(it)
}
}
}
@@ -63,7 +66,7 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
override fun keyDown(keycode: Int): Boolean {
if (ingame.canPlayerControl) {
ingame.playableActor.keyDown(keycode)
ingame.actorNowPlaying?.keyDown(keycode)
}
if (Terrarum.getConfigIntArray("keyquickselalt").contains(keycode)
@@ -112,7 +115,7 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (ingame.canPlayerControl) {
val itemOnGrip = ingame.playableActor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
val itemOnGrip = ingame.actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP) ?: null
if (itemOnGrip != null) {
if (button == Terrarum.getConfigInt("mouseprimary")) {