mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 04:41:51 +09:00
fix: held items now glow (or not glow) under UV as they should
This commit is contained in:
@@ -28,13 +28,14 @@ import java.util.*
|
||||
* Created by minjaesong on 2022-03-23.
|
||||
*/
|
||||
class AssembledSpriteAnimation(
|
||||
@Transient val adp: ADProperties,
|
||||
parentActor: ActorWithBody,
|
||||
@Transient val disk: SimpleFileSystem?, // specify if the resources for the animation is contained in the disk archive
|
||||
@Transient val bodypartToFileMap: EntryID? // which file in the disk contains bodypart-to-fileid mapping for this particular instance of sprite animation
|
||||
@Transient val adp: ADProperties,
|
||||
parentActor: ActorWithBody,
|
||||
@Transient val disk: SimpleFileSystem?, // specify if the resources for the animation is contained in the disk archive
|
||||
@Transient val bodypartToFileMap: EntryID?, // which file in the disk contains bodypart-to-fileid mapping for this particular instance of sprite animation
|
||||
@Transient val isGlow: Boolean
|
||||
) : SpriteAnimation(parentActor) {
|
||||
|
||||
constructor(adp: ADProperties, parentActor: ActorWithBody) : this(adp, parentActor, null, null)
|
||||
constructor(adp: ADProperties, parentActor: ActorWithBody, isGlow: Boolean) : this(adp, parentActor, null, null, isGlow)
|
||||
|
||||
var currentFrame = 0 // while this number is zero-based, the frame number on the ADP is one-based
|
||||
private set
|
||||
@@ -90,8 +91,11 @@ class AssembledSpriteAnimation(
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchItemImage(item: GameItem) = if (isGlow) ItemCodex.getItemImageGlow(item) else ItemCodex.getItemImage(item)
|
||||
|
||||
fun renderThisAnimation(batch: SpriteBatch, posX: Float, posY: Float, scale: Float, animName: String) {
|
||||
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 txFlp = -(parentActor.hitboxTranslateX) * scale
|
||||
@@ -111,9 +115,10 @@ class AssembledSpriteAnimation(
|
||||
if (flipHorizontal) bodypartPos = bodypartPos.invertX()
|
||||
bodypartPos += ADPropertyObject.Vector2i(1,0)
|
||||
|
||||
// draw held items/armours?
|
||||
if (name in jointNameToEquipPos) {
|
||||
ItemCodex[(parentActor as? Pocketed)?.inventory?.itemEquipped?.get(jointNameToEquipPos[name]!!)]?.let { item ->
|
||||
ItemCodex.getItemImage(item)?.let { image ->
|
||||
fetchItemImage(item)?.let { image ->
|
||||
val drawPos = adp.origin + bodypartPos // imgCentre for held items are (0,0)
|
||||
val w = image.regionWidth * scale
|
||||
val h = image.regionHeight * scale
|
||||
|
||||
@@ -139,6 +139,7 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
*
|
||||
*/
|
||||
@Transient open val itemImage: TextureRegion? = null
|
||||
@Transient open val itemImageGlow: TextureRegion? = null
|
||||
|
||||
/**
|
||||
* Apparent mass of the item. (basemass * scale^3)
|
||||
|
||||
@@ -124,10 +124,14 @@ class ItemCodex {
|
||||
|
||||
fun getItemImage(item: GameItem?): TextureRegion? {
|
||||
if (item == null) return null
|
||||
|
||||
return getItemImage(item.originalID)
|
||||
}
|
||||
|
||||
fun getItemImageGlow(item: GameItem?): TextureRegion? {
|
||||
if (item == null) return null
|
||||
return getItemImageGlow(item.originalID)
|
||||
}
|
||||
|
||||
fun getItemImage(itemID: ItemID?): TextureRegion? {
|
||||
if (itemID == null) return null
|
||||
|
||||
@@ -155,7 +159,35 @@ class ItemCodex {
|
||||
itemSheetNumber / App.tileMaker.TILES_IN_X
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun getItemImageGlow(itemID: ItemID?): TextureRegion? {
|
||||
if (itemID == null) return null
|
||||
|
||||
if (itemID.isDynamic()) {
|
||||
return getItemImageGlow(dynamicToStaticID(itemID))
|
||||
}
|
||||
else if (itemID.isItem()) {
|
||||
return itemCodex[itemID]?.itemImageGlow
|
||||
}
|
||||
else if (itemID.isWire()) {
|
||||
return itemCodex[itemID]?.itemImageGlow
|
||||
}
|
||||
else if (itemID.isWall()) {
|
||||
val itemSheetNumber = App.tileMaker.tileIDtoItemSheetNumber(itemID.substring(5))
|
||||
return BlocksDrawer.tileItemWallGlow.get(
|
||||
itemSheetNumber % App.tileMaker.TILES_IN_X,
|
||||
itemSheetNumber / App.tileMaker.TILES_IN_X
|
||||
)
|
||||
}
|
||||
// else: terrain
|
||||
else {
|
||||
val itemSheetNumber = App.tileMaker.tileIDtoItemSheetNumber(itemID)
|
||||
return BlocksDrawer.tileItemTerrainGlow.get(
|
||||
itemSheetNumber % App.tileMaker.TILES_IN_X,
|
||||
itemSheetNumber / App.tileMaker.TILES_IN_X
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun hasItem(itemID: ItemID): Boolean = dynamicItemInventory.containsKey(itemID)
|
||||
|
||||
@@ -27,8 +27,8 @@ object PlayerBuilderTestSubject1 {
|
||||
p.sprite!!.delays = floatArrayOf(2f, 1f/12f) // second value does nothing -- overridden by ActorHumanoid.updateSprite(float)
|
||||
p.sprite!!.setRowsAndFrames(2, 4)*/
|
||||
|
||||
p.animDesc?.let { p.sprite = AssembledSpriteAnimation(it, p) }
|
||||
p.animDescGlow?.let { p.spriteGlow = AssembledSpriteAnimation(it, p) }
|
||||
p.animDesc?.let { p.sprite = AssembledSpriteAnimation(it, p, false) }
|
||||
p.animDescGlow?.let { p.spriteGlow = AssembledSpriteAnimation(it, p, true) }
|
||||
//p.reassembleSprite(p.sprite, p.spriteGlow, null)
|
||||
p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT) ?: ActorHumanoid.BASE_HEIGHT, 21, 0)
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ object PlayerBuilderWerebeastTest {
|
||||
p.sprite!!.delays = floatArrayOf(2f, 1f/12f) // second value does nothing -- overridden by ActorHumanoid.updateSprite(float)
|
||||
p.sprite!!.setRowsAndFrames(2, 4)*/
|
||||
|
||||
p.animDesc?.let { p.sprite = AssembledSpriteAnimation(it, p) }
|
||||
p.animDescGlow?.let { p.spriteGlow = AssembledSpriteAnimation(it, p) }
|
||||
p.animDesc?.let { p.sprite = AssembledSpriteAnimation(it, p, false) }
|
||||
p.animDescGlow?.let { p.spriteGlow = AssembledSpriteAnimation(it, p, true) }
|
||||
//p.reassembleSprite(p.sprite, p.spriteGlow, null)
|
||||
p.setHitboxDimension(22, p.actorValue.getAsInt(AVKey.BASEHEIGHT)!!, 30, 0)
|
||||
|
||||
|
||||
@@ -165,18 +165,20 @@ object ReadActor {
|
||||
|
||||
actor.animDesc = ADProperties(ByteArray64Reader(animFile!!.bytes, Common.CHARSET))
|
||||
actor.sprite = AssembledSpriteAnimation(
|
||||
actor.animDesc!!,
|
||||
actor,
|
||||
if (bodypartsFile != null) disk else null,
|
||||
if (bodypartsFile != null) BODYPART_TO_ENTRY_MAP else null
|
||||
actor.animDesc!!,
|
||||
actor,
|
||||
if (bodypartsFile != null) disk else null,
|
||||
if (bodypartsFile != null) BODYPART_TO_ENTRY_MAP else null,
|
||||
false
|
||||
)
|
||||
if (animFileGlow != null) {
|
||||
actor.animDescGlow = ADProperties(ByteArray64Reader(animFileGlow.bytes, Common.CHARSET))
|
||||
actor.spriteGlow = AssembledSpriteAnimation(
|
||||
actor.animDescGlow!!,
|
||||
actor,
|
||||
if (bodypartsFile != null) disk else null,
|
||||
if (bodypartsFile != null) BODYPARTGLOW_TO_ENTRY_MAP else null
|
||||
actor.animDescGlow!!,
|
||||
actor,
|
||||
if (bodypartsFile != null) disk else null,
|
||||
if (bodypartsFile != null) BODYPARTGLOW_TO_ENTRY_MAP else null,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
@@ -190,8 +192,8 @@ object ReadActor {
|
||||
actor.reassembleSprite(actor.sprite!!, actor.spriteGlow, heldItem)*/
|
||||
}
|
||||
else if (actor is ActorWithBody && actor is HasAssembledSprite) {
|
||||
if (actor.animDesc != null) actor.sprite = AssembledSpriteAnimation(actor.animDesc!!, actor)
|
||||
if (actor.animDescGlow != null) actor.spriteGlow = AssembledSpriteAnimation(actor.animDescGlow!!, actor)
|
||||
if (actor.animDesc != null) actor.sprite = AssembledSpriteAnimation(actor.animDesc!!, actor, false)
|
||||
if (actor.animDescGlow != null) actor.spriteGlow = AssembledSpriteAnimation(actor.animDescGlow!!, actor, true)
|
||||
|
||||
//actor.reassembleSprite(actor.sprite, actor.spriteGlow, null)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,9 @@ internal object BlocksDrawer {
|
||||
lateinit var tilesTerrainBlend: TextureRegionPack; private set
|
||||
//val tilesWire: TextureRegionPack
|
||||
val tileItemTerrain: TextureRegionPack
|
||||
val tileItemTerrainGlow: TextureRegionPack
|
||||
val tileItemWall: TextureRegionPack
|
||||
val tileItemWallGlow: TextureRegionPack
|
||||
val tilesFluid: TextureRegionPack
|
||||
val tilesGlow: TextureRegionPack
|
||||
|
||||
@@ -119,7 +121,9 @@ internal object BlocksDrawer {
|
||||
// test print
|
||||
|
||||
tileItemTerrain = TextureRegionPack(App.tileMaker.itemTerrainTexture, TILE_SIZE, TILE_SIZE)
|
||||
tileItemTerrainGlow = TextureRegionPack(App.tileMaker.itemTerrainTextureGlow, TILE_SIZE, TILE_SIZE)
|
||||
tileItemWall = TextureRegionPack(App.tileMaker.itemWallTexture, TILE_SIZE, TILE_SIZE)
|
||||
tileItemWallGlow = TextureRegionPack(App.tileMaker.itemWallTextureGlow, TILE_SIZE, TILE_SIZE)
|
||||
|
||||
|
||||
// val texdata = tileItemTerrain.texture.textureData
|
||||
@@ -733,7 +737,9 @@ internal object BlocksDrawer {
|
||||
tilesGlow.dispose()
|
||||
//tilesWire.dispose()
|
||||
tileItemTerrain.dispose()
|
||||
tileItemTerrainGlow.dispose()
|
||||
tileItemWall.dispose()
|
||||
tileItemWallGlow.dispose()
|
||||
tilesFluid.dispose()
|
||||
tilesBuffer.dispose()
|
||||
_tilesBufferAsTex.dispose()
|
||||
|
||||
@@ -44,7 +44,9 @@ class CreateTileAtlas {
|
||||
lateinit var atlasFluid: Pixmap
|
||||
lateinit var atlasGlow: Pixmap // glowing won't be affected by the season... for now
|
||||
lateinit var itemTerrainTexture: Texture
|
||||
lateinit var itemTerrainTextureGlow: Texture
|
||||
lateinit var itemWallTexture: Texture
|
||||
lateinit var itemWallTextureGlow: Texture
|
||||
lateinit var terrainTileColourMap: HashMap<ItemID, Cvec>
|
||||
lateinit var tags: HashMap<ItemID, RenderTag> // TileID, RenderTag
|
||||
private set
|
||||
@@ -64,7 +66,9 @@ class CreateTileAtlas {
|
||||
private var itemSheetCursor = 16
|
||||
|
||||
internal val itemTerrainPixmap = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
internal val itemTerrainPixmapGlow = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
internal val itemWallPixmap = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
internal val itemWallPixmapGlow = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
|
||||
|
||||
/**
|
||||
@@ -164,13 +168,17 @@ class CreateTileAtlas {
|
||||
val destX = (t % TILES_IN_X) * TILE_SIZE
|
||||
val destY = (t / TILES_IN_X) * TILE_SIZE
|
||||
itemTerrainPixmap.drawPixmap(atlas, srcX, srcY, TILE_SIZE, TILE_SIZE, destX, destY, TILE_SIZE, TILE_SIZE)
|
||||
itemTerrainPixmapGlow.drawPixmap(atlasGlow, srcX, srcY, TILE_SIZE, TILE_SIZE, destX, destY, TILE_SIZE, TILE_SIZE)
|
||||
itemWallPixmap.drawPixmap(atlas, srcX, srcY, TILE_SIZE, TILE_SIZE, destX, destY, TILE_SIZE, TILE_SIZE)
|
||||
itemWallPixmapGlow.drawPixmap(atlasGlow, srcX, srcY, TILE_SIZE, TILE_SIZE, destX, destY, TILE_SIZE, TILE_SIZE)
|
||||
}
|
||||
// darken things for the wall
|
||||
for (y in 0 until itemWallPixmap.height) {
|
||||
for (x in 0 until itemWallPixmap.width) {
|
||||
val c = Color(itemWallPixmap.getPixel(x, y)).mulAndAssign(wallOverlayColour).toRGBA()
|
||||
itemWallPixmap.drawPixel(x, y, c)
|
||||
val c1 = Color(itemWallPixmap.getPixel(x, y)).mulAndAssign(wallOverlayColour).toRGBA()
|
||||
itemWallPixmap.drawPixel(x, y, c1)
|
||||
val c2 = Color(itemWallPixmapGlow.getPixel(x, y)).mulAndAssign(wallOverlayColour).toRGBA()
|
||||
itemWallPixmapGlow.drawPixel(x, y, c2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +211,9 @@ class CreateTileAtlas {
|
||||
}
|
||||
|
||||
itemTerrainTexture = Texture(itemTerrainPixmap)
|
||||
itemTerrainTextureGlow = Texture(itemTerrainPixmapGlow)
|
||||
itemWallTexture = Texture(itemWallPixmap)
|
||||
itemWallTextureGlow = Texture(itemWallPixmapGlow)
|
||||
// itemTerrainPixmap.dispose()
|
||||
// itemWallPixmap.dispose()
|
||||
initPixmap.dispose()
|
||||
@@ -295,13 +305,13 @@ class CreateTileAtlas {
|
||||
printdbg(this, "tileName ${id} ->> tileNumber ${atlasCursor}")
|
||||
}
|
||||
|
||||
private fun drawToAtlantes(pixmap: Pixmap, glow: Pixmap, tilesCount: Int) {
|
||||
private fun drawToAtlantes(matte: Pixmap, glow: Pixmap, tilesCount: Int) {
|
||||
if (atlasCursor >= TOTAL_TILES) {
|
||||
throw Error("Too much tiles for $MAX_TEX_SIZE texture size: $atlasCursor")
|
||||
}
|
||||
|
||||
val seasonal = pixmap.width == pixmap.height && pixmap.width == 14 * TILE_SIZE
|
||||
val txOfPixmap = pixmap.width / TILE_SIZE
|
||||
val seasonal = matte.width == matte.height && matte.width == 14 * TILE_SIZE
|
||||
val txOfPixmap = matte.width / TILE_SIZE
|
||||
val txOfPixmapGlow = glow.width / TILE_SIZE
|
||||
for (i in 0 until tilesCount) {
|
||||
//printdbg(this, "Rendering to atlas, tile# $atlasCursor, tilesCount = $tilesCount, seasonal = $seasonal")
|
||||
@@ -309,16 +319,16 @@ class CreateTileAtlas {
|
||||
// different texture for different seasons (224x224)
|
||||
if (seasonal) {
|
||||
val i = if (i < 41) i else i + 1 // to compensate the discontinuity between 40th and 41st tile
|
||||
_drawToAtlantes(pixmap, atlasCursor, i % 7, i / 7, 1)
|
||||
_drawToAtlantes(pixmap, atlasCursor, i % 7 + 7, i / 7, 2)
|
||||
_drawToAtlantes(pixmap, atlasCursor, i % 7 + 7, i / 7 + 7, 3)
|
||||
_drawToAtlantes(pixmap, atlasCursor, i % 7, i / 7 + 7, 4)
|
||||
_drawToAtlantes(matte, atlasCursor, i % 7, i / 7, 1)
|
||||
_drawToAtlantes(matte, atlasCursor, i % 7 + 7, i / 7, 2)
|
||||
_drawToAtlantes(matte, atlasCursor, i % 7 + 7, i / 7 + 7, 3)
|
||||
_drawToAtlantes(matte, atlasCursor, i % 7, i / 7 + 7, 4)
|
||||
_drawToAtlantes(glow, atlasCursor, i % 7, i / 7, 6)
|
||||
atlasCursor += 1
|
||||
}
|
||||
else {
|
||||
val i = if (i < 41) i else i + 1 // to compensate the discontinuity between 40th and 41st tile
|
||||
_drawToAtlantes(pixmap, atlasCursor, i % txOfPixmap, i / txOfPixmap, 0)
|
||||
_drawToAtlantes(matte, atlasCursor, i % txOfPixmap, i / txOfPixmap, 0)
|
||||
_drawToAtlantes(glow, atlasCursor, i % txOfPixmapGlow, i / txOfPixmapGlow, 6)
|
||||
atlasCursor += 1
|
||||
}
|
||||
@@ -389,7 +399,9 @@ class CreateTileAtlas {
|
||||
atlasFluid.dispose()
|
||||
atlasGlow.dispose()
|
||||
//itemTerrainTexture.dispose() //BlocksDrawer will dispose of it as it disposes of 'tileItemTerrain (TextureRegionPack)'
|
||||
//itemTerrainTextureGlow.dispose() //BlocksDrawer will dispose of it as it disposes of 'tileItemTerrain (TextureRegionPack)'
|
||||
//itemWallTexture.dispose() //BlocksDrawer will dispose of it as it disposes of 'tileItemWall (TextureRegionPack)'
|
||||
//itemWallTextureGlow.dispose() //BlocksDrawer will dispose of it as it disposes of 'tileItemWall (TextureRegionPack)'
|
||||
itemTerrainPixmap.dispose()
|
||||
itemWallPixmap.dispose()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user