diff --git a/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt b/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt index dc616a17c..1eeb1cf35 100644 --- a/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt +++ b/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt @@ -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 diff --git a/src/net/torvald/terrarum/gameitems/GameItem.kt b/src/net/torvald/terrarum/gameitems/GameItem.kt index 4cd2c764e..196f067c4 100644 --- a/src/net/torvald/terrarum/gameitems/GameItem.kt +++ b/src/net/torvald/terrarum/gameitems/GameItem.kt @@ -139,6 +139,7 @@ abstract class GameItem(val originalID: ItemID) : Comparable, Cloneabl * */ @Transient open val itemImage: TextureRegion? = null + @Transient open val itemImageGlow: TextureRegion? = null /** * Apparent mass of the item. (basemass * scale^3) diff --git a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt index 0bf1cc6dc..966fdf107 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt @@ -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) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderTestSubject1.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderTestSubject1.kt index 219f943f8..d4083cb10 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderTestSubject1.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderTestSubject1.kt @@ -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) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderWerebeastTest.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderWerebeastTest.kt index cf3c4ea1d..fb9c31a9f 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderWerebeastTest.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderWerebeastTest.kt @@ -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) diff --git a/src/net/torvald/terrarum/modulebasegame/serialise/WriteActor.kt b/src/net/torvald/terrarum/modulebasegame/serialise/WriteActor.kt index 2c9b57180..5e9442cc3 100644 --- a/src/net/torvald/terrarum/modulebasegame/serialise/WriteActor.kt +++ b/src/net/torvald/terrarum/modulebasegame/serialise/WriteActor.kt @@ -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) } diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt index 55e8ab7c8..d07e2b8f3 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt @@ -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() diff --git a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt index c45278382..f5bea1057 100644 --- a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt +++ b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt @@ -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 lateinit var tags: HashMap // 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()