revived the held item lighting

This commit is contained in:
minjaesong
2024-02-05 17:18:28 +09:00
parent 2d42525092
commit 3491926e7c
5 changed files with 65 additions and 13 deletions

View File

@@ -153,10 +153,10 @@ class AssembledSpriteAnimation(
val animNameRoot = animName.substring(0, animName.indexOfLast { it == '_' }).ifBlank { return@renderThisAnimation }
// quick fix for the temporary de-sync bug in which when the update-rate per frame is much greater than once, it attempts to load animation with blank name
val tx = (parentActor.hitboxTranslateX) * scale
val tx = -(parentActor.hitboxTranslateX) * scale
val txFlp = -(parentActor.hitboxTranslateX) * scale
// flipping will not be symmetrical if baseHitboxWidth is odd number
val ty = (parentActor.hitboxTranslateY - parentActor.baseHitboxH) * scale
val ty = -(parentActor.hitboxTranslateY - parentActor.baseHitboxH) * scale
val tyFlp = (parentActor.hitboxTranslateY) * scale
@@ -186,11 +186,11 @@ class AssembledSpriteAnimation(
if (flipHorizontal && flipVertical)
batch.draw(image, fposX + txFlp, fposY + tyFlp, -w, -h)
else if (flipHorizontal && !flipVertical)
batch.draw(image, fposX + txFlp, fposY - ty, -w, h)
batch.draw(image, fposX + txFlp, fposY + ty, -w, h)
else if (!flipHorizontal && flipVertical)
batch.draw(image, fposX - tx, fposY + tyFlp, w, -h)
batch.draw(image, fposX + tx, fposY + tyFlp, w, -h)
else
batch.draw(image, fposX - tx, fposY - ty, w, h)
batch.draw(image, fposX + tx, fposY + ty, w, h)
}
}
}
@@ -210,11 +210,11 @@ class AssembledSpriteAnimation(
if (flipHorizontal && flipVertical)
batch.draw(image, fposX + txFlp, fposY + tyFlp, -w, -h)
else if (flipHorizontal && !flipVertical)
batch.draw(image, fposX + txFlp, fposY - ty, -w, h)
batch.draw(image, fposX + txFlp, fposY + ty, -w, h)
else if (!flipHorizontal && flipVertical)
batch.draw(image, fposX - tx, fposY + tyFlp, w, -h)
batch.draw(image, fposX + tx, fposY + tyFlp, w, -h)
else
batch.draw(image, fposX - tx, fposY - ty, w, h)
batch.draw(image, fposX + tx, fposY + ty, w, h)
}
}

View File

@@ -61,6 +61,7 @@ internal object CommandInterpreter {
System.err.print("[CommandInterpreter] ")
e.printStackTrace()
EchoError(Lang["ERROR_GENERIC_TEXT"])
EchoError(e.localizedMessage)
}
}
catch (e: NullPointerException) {

View File

@@ -42,9 +42,9 @@ open class DroppedItem : ActorWithBody {
private val randKey1 = (Math.random() * 256).toInt()
private val randKey2 = (Math.random() * 256).toInt()
override var lightBoxList = arrayListOf(Lightbox(this.hitbox.clone().setPosition(0.0, 0.0), Cvec(0)))
override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 0.0, TILE_SIZED, TILE_SIZED), Cvec(0)))
// the Cvec will be calculated dynamically on Update
override var shadeBoxList = arrayListOf(Lightbox(this.hitbox.clone().setPosition(0.0, 0.0), Cvec(0)))
override var shadeBoxList = arrayListOf(Lightbox(Hitbox(0.0, 0.0, TILE_SIZED, TILE_SIZED), Cvec(0)))
// the Cvec will be calculated dynamically on Update
/**

View File

@@ -55,7 +55,7 @@ class ADProperties {
internal lateinit var skeletons: HashMap<String, Skeleton>; private set
/** properties that defines position of joint of the bodypart */
internal val bodypartJoints = HashMap<String, ADPropertyObject.Vector2i>()
/** properties that are recognised as animations (ANIM_RUN, ANIM)IDLE) */
/** properties that are recognised as animations (ANIM_RUN, ANIM_IDLE) */
internal lateinit var animations: HashMap<String, Animation>; private set
/** an "animation frame" property (ANIM_RUN_1, ANIM_RUN_2) */
internal lateinit var transforms: HashMap<String, List<Transform>>; private set

View File

@@ -6,16 +6,25 @@ import com.badlogic.gdx.graphics.Texture
import com.jme3.math.FastMath
import net.torvald.gdx.graphics.Cvec
import net.torvald.gdx.graphics.UnsafeCvecArray
import net.torvald.spriteanimation.AssembledSpriteAnimation
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.blockproperties.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Lightbox
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.isBlock
import net.torvald.terrarum.gameitems.isWall
import net.torvald.terrarum.gameworld.BlockAddress
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
import net.torvald.terrarum.modulebasegame.ui.abs
import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.spriteassembler.ADPropertyObject
import java.util.*
import kotlin.math.*
@@ -356,10 +365,52 @@ object LightmapRenderer {
actorContainer.forEach {
val lightBoxCopy = it.lightBoxList.subList(0, it.lightBoxList.size) // make copy to prevent ConcurrentModificationException
val shadeBoxCopy = it.shadeBoxList.subList(0, it.shadeBoxList.size) // make copy to prevent ConcurrentModificationException
val scale = it.scale
// add lightbox for held item
val heldItemLightBox = if (it.sprite is AssembledSpriteAnimation && it is Pocketed) {
val sprite = it.sprite as AssembledSpriteAnimation
val adp = sprite.adp
val currentAnimNameRoot = sprite.currentAnimation
val currentAnimNameFull = "${sprite.currentAnimation}_${1 + sprite.currentFrame}"
val anim = adp.animations[currentAnimNameRoot]!!
val HELD_ITEM = "HELD_ITEM"
val transform = adp.getTransform(currentAnimNameFull)
val skeleton = anim.skeleton
val heldItemTransform = transform.firstOrNull { it.joint.name == HELD_ITEM }?.translate ?: ADPropertyObject.Vector2i(0, 0)
val heldItemJoint = skeleton.joints.firstOrNull { it.name == HELD_ITEM }
if (heldItemJoint != null) {
val relativeHeldItemTopLeftPos =
adp.origin + (heldItemJoint.position + heldItemTransform).invertY() + ADPropertyObject.Vector2i(1,0)
val tx = -(it.hitboxTranslateX).toDouble()
val ty = if (sprite.flipVertical) (it.hitboxTranslateY).toDouble() else -(it.hitboxTranslateY - it.baseHitboxH).toDouble()
val heldItem = it.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
val light = if (heldItem != null && (heldItem.isBlock() || heldItem.isWall()))
BlockCodex[heldItem].getLumCol(0, 0)
else
Cvec(0)
Lightbox(Hitbox(
relativeHeldItemTopLeftPos.x + tx,
relativeHeldItemTopLeftPos.y + ty - TILE_SIZED,
TILE_SIZED, TILE_SIZED
), light)
}
else
Lightbox(Hitbox(0.0, 0.0, 1.0, 1.0), Cvec(0))
}
else
Lightbox(Hitbox(0.0, 0.0, 1.0, 1.0), Cvec(0))
// put lanterns to the area the lightBox is occupying
lightBoxCopy.forEach { (box, colour) ->
val scale = it.scale
(lightBoxCopy + heldItemLightBox).forEach { (box, colour) ->
val boxX = it.hitbox.startX + (box.startX * scale)
val boxY = it.hitbox.startY + (box.startY * scale)
val boxW = box.width * scale