From 8bf3d9666fbff3332c5bec92a570fc6f711ace9c Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 20 Mar 2024 03:33:24 +0900 Subject: [PATCH] test copper sign and it has no sprite --- assets/mods/basegame/items/itemid.csv | 7 +- .../fixtures/text_sign_glass_copper.tga | 4 +- .../modulebasegame/gameactors/FixtureBase.kt | 24 ++- .../gameactors/FixtureTapestry.kt | 14 +- .../gameactors/FixtureTextSignCopper.kt | 151 ++++++++++++++++++ .../gameitems/ItemTextSignCopper.kt | 26 +++ 6 files changed, 210 insertions(+), 16 deletions(-) create mode 100644 src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTextSignCopper.kt create mode 100644 src/net/torvald/terrarum/modulebasegame/gameitems/ItemTextSignCopper.kt diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index 9cf8a03f3..dd0604641 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -121,7 +121,12 @@ id;classname;tags 32777;net.torvald.terrarum.modulebasegame.gameitems.MusicDisc09;MUSIC,PHONO # data storage (tapestries; 256) -#33023;net.torvald.terrarum.modulebasegame.gameitems.ItemTapestry;FIXTURE +#33024;net.torvald.terrarum.modulebasegame.gameitems.ItemTapestry;FIXTURE,BASEOBJECT + +# data storage (text signs; 256) +33280;net.torvald.terrarum.modulebasegame.gameitems.ItemTextSignCopper;FIXTURE,BASEOBJECT + + # fluids on storage # preferably autogenerated diff --git a/assets/mods/basegame/sprites/fixtures/text_sign_glass_copper.tga b/assets/mods/basegame/sprites/fixtures/text_sign_glass_copper.tga index 275ffb09b..f27df651e 100644 --- a/assets/mods/basegame/sprites/fixtures/text_sign_glass_copper.tga +++ b/assets/mods/basegame/sprites/fixtures/text_sign_glass_copper.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7458034a38e0ee3379ad356307342db5a45f20b0a9fe7eb30a24b6acc52b97fd -size 40978 +oid sha256:fd667660f1cfd8c1442358322ee830e7fed4e7863ed7301261e563e969442145 +size 32786 diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 3f1302ce2..b375eb23a 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -27,6 +27,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { @Transient open val spawnNeedsWall: Boolean = false @Transient open val spawnNeedsFloor: Boolean = true + @Transient open val spawnNeedsCeiling: Boolean = false // if both spawnNeedsWall and spawnNeedsFloor are true, the condition will be interpreted as OR-condition @@ -178,8 +179,8 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { } // check for floors, if spawnNeedsFloor == true - if (spawnNeedsFloor) { - val y = posY + blockBox.height + if (spawnNeedsFloor || spawnNeedsCeiling) { + val y = posY + if (spawnNeedsFloor) blockBox.height else -1 val xs = posX until posX + blockBox.width cannotSpawnNoFloor = xs.any { x -> world!!.getTileFromTerrain(x, y).let { @@ -188,9 +189,9 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { } } - if (spawnNeedsWall && spawnNeedsFloor) + if (spawnNeedsWall && (spawnNeedsFloor || spawnNeedsCeiling)) cannotSpawn = cannotSpawn or (cannotSpawnNoWall && cannotSpawnNoFloor) - else if (spawnNeedsFloor) + else if (spawnNeedsFloor || spawnNeedsCeiling) cannotSpawn = cannotSpawn or cannotSpawnNoFloor else if (spawnNeedsWall) cannotSpawn = cannotSpawn or cannotSpawnNoWall @@ -210,10 +211,14 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { var soundSource = if (spawnNeedsWall) 1 else if (spawnNeedsFloor) 0 + else if (spawnNeedsCeiling) 3 else 2 // 1: wall, 0: floor, 2: if wall is not solid, use wall; else, use floor val wallTile = world!!.getTileFromWall(posXc, posYb) - val terrTile = world!!.getTileFromTerrain(posXc, posYb + 1) + val terrTile = if (soundSource == 3) + world!!.getTileFromTerrain(posXc, posYb - blockBox.height) + else + world!!.getTileFromTerrain(posXc, posYb + 1) if (soundSource == 2) { soundSource = if (BlockCodex[wallTile].isSolid) @@ -224,7 +229,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { when (soundSource) { 1 -> PickaxeCore.makeNoiseTileBurst(this, wallTile) - 0 -> PickaxeCore.makeNoiseTileBurst(this, terrTile) + 0, 3 -> PickaxeCore.makeNoiseTileBurst(this, terrTile) } // make some dust @@ -235,6 +240,13 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { PickaxeCore.makeDust(tile, x, y - 1, 4 + (Math.random() + Math.random()).roundToInt()) } } + else if (soundSource == 3) { + val y = posY + for (x in posX until posX + blockBox.width) { + val tile = world!!.getTileFromTerrain(x, y) + PickaxeCore.makeDust(tile, x, y - 1, 4 + (Math.random() + Math.random()).roundToInt()) + } + } else { for (y in posY until posY + blockBox.height) { for (x in posX until posX + blockBox.width) { diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTapestry.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTapestry.kt index 0e892e0a9..b08135a42 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTapestry.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTapestry.kt @@ -34,16 +34,16 @@ internal class FixtureTapestry : FixtureBase { private var tilewiseHitboxWidth by Delegates.notNull() private var tilewiseHitboxHeight by Delegates.notNull() - private constructor() : super( - BlockBox(BlockBox.NO_COLLISION, 1, 1), - renderOrder = RenderOrder.BEHIND, - nameFun = { Lang["ITEM_TAPESTRY"] } + constructor() : super( + BlockBox(BlockBox.NO_COLLISION, 1, 1), + renderOrder = RenderOrder.BEHIND, + nameFun = { Lang["ITEM_TAPESTRY"] } ) constructor(rawBytes: ByteArray, framingMaterial: ItemID) : super( - BlockBox(BlockBox.NO_COLLISION, 1, 1), - renderOrder = RenderOrder.BEHIND, - nameFun = { Lang["ITEM_TAPESTRY"] } + BlockBox(BlockBox.NO_COLLISION, 1, 1), + renderOrder = RenderOrder.BEHIND, + nameFun = { Lang["ITEM_TAPESTRY"] } ) { this.rawBytes = rawBytes this.frameBlock = framingMaterial diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTextSignCopper.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTextSignCopper.kt new file mode 100644 index 000000000..035ce2b5d --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTextSignCopper.kt @@ -0,0 +1,151 @@ +package net.torvald.terrarum.modulebasegame.gameactors + +import com.badlogic.gdx.graphics.Pixmap +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.spriteanimation.SheetSpriteAnimation +import net.torvald.terrarum.App +import net.torvald.terrarum.CommonResourcePool +import net.torvald.terrarum.ModMgr +import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE +import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.toInt +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack +import java.util.* + +/** + * Created by minjaesong on 2024-03-20. + */ +class FixtureTextSignCopper : Electric { + + @Transient override val spawnNeedsCeiling = true + @Transient override val spawnNeedsFloor = false + @Transient override val spawnNeedsWall = false + + + + var text = "헬로 월드!" + var panelCount = 5 + + constructor() : super( + BlockBox(BlockBox.NO_COLLISION, 2, 2), + renderOrder = RenderOrder.BEHIND, + nameFun = { Lang["ITEM_COPPER_SIGN"] } + ) + + override fun spawn(posX: Int, posY: Int, installersUUID: UUID?): Boolean = spawn(posX, posY, installersUUID, panelCount.coerceAtLeast(2), 2) + + override fun reload() { + super.reload() + + // must be re-spawned on reload to make it visible after load + spawn( + intTilewiseHitbox.canonicalX.toInt(), + intTilewiseHitbox.canonicalY.toInt(), + actorThatInstalledThisFixture, + panelCount.coerceAtLeast(2), + 2 + ) + setEmitterAndSink() + setSprites(panelCount) + updateSignal() + } + private fun setEmitterAndSink() { + clearStatus() + setWireSinkAt(0, 0, "digital_bit") + setWireSinkAt(panelCount - 1, 0, "digital_bit") + } + + init { + CommonResourcePool.addToLoadingList("pixmap:copper_sign") { + Pixmap(ModMgr.getGdxFile("basegame", "sprites/fixtures/text_sign_glass_copper.tga")) + } + CommonResourcePool.loadAll() + } + + @Transient private var textOverlay: SheetSpriteAnimation? = null + @Transient private var textOverlayEmissive: SheetSpriteAnimation? = null + + /** + * This only constructs the base panel + */ + private fun setSprites(panelCount: Int) { + val panelCount = panelCount.coerceAtLeast(2) + val pixmap = CommonResourcePool.getAs("pixmap:copper_sign") + + val W = TILE_SIZE + val H = 4 * TILE_SIZE + val ROW0 = 0 + val ROW1 = H + + val pixmapSprite = Pixmap(W * panelCount, H, Pixmap.Format.RGBA8888) + val pixmapSpriteEmsv = Pixmap(W * panelCount, H, Pixmap.Format.RGBA8888) + val pixmapOverlay = Pixmap(W * panelCount, H, Pixmap.Format.RGBA8888) + val pixmapOverlayEmsv = Pixmap(W * panelCount, H, Pixmap.Format.RGBA8888) + + pixmapSprite.drawPixmap(pixmap, 0, 0, 0, ROW0, W, H) + pixmapSprite.drawPixmap(pixmap, W * (panelCount - 1), 0, 32, ROW0, W, H) + pixmapSpriteEmsv.drawPixmap(pixmap, 0, 0, 0, ROW1, W, H) + pixmapSpriteEmsv.drawPixmap(pixmap, W * (panelCount - 1), 0, 32, ROW1, W, H) + for (mid in 1 until panelCount - 1) { + pixmapSprite.drawPixmap(pixmap, W * mid, 0, 16, ROW0, W, H) + pixmapSpriteEmsv.drawPixmap(pixmap, W * mid, 0, 16, ROW1, W, H) + } + + for (tiles in 0 until panelCount) { + pixmapOverlay.drawPixmap(pixmap, W * tiles, 0, 48, ROW0, W, H) + pixmapOverlayEmsv.drawPixmap(pixmap, W * tiles, 0, 48, ROW1, W, H) + } + + makeNewSprite(TextureRegionPack(Texture(pixmapSprite), W * panelCount, H / 2)).let { + it.setRowsAndFrames(2, 1) + it.delays = FloatArray(1) { Float.POSITIVE_INFINITY } + } + makeNewSpriteEmissive(TextureRegionPack(Texture(pixmapSpriteEmsv), W * panelCount, H / 2)).let { + it.setRowsAndFrames(2, 1) + it.delays = FloatArray(1) { Float.POSITIVE_INFINITY } + } + + textOverlay = SheetSpriteAnimation(this).also { + it.setSpriteImage(TextureRegionPack(Texture(pixmapOverlay), W, H / 2)) + it.setRowsAndFrames(2, 1) + } + textOverlayEmissive = SheetSpriteAnimation(this).also { + it.setSpriteImage(TextureRegionPack(Texture(pixmapOverlayEmsv), W, H / 2)) + it.setRowsAndFrames(2, 1) + } + + + pixmapSprite.dispose() + pixmapSpriteEmsv.dispose() + pixmapOverlay.dispose() + pixmapOverlayEmsv.dispose() + } + + + @Transient var lit = true + + override fun drawEmissive(frameDelta: Float, batch: SpriteBatch) { + super.drawEmissive(frameDelta, batch) + } + + override fun drawBody(frameDelta: Float, batch: SpriteBatch) { + super.drawBody(frameDelta, batch) + } + + override fun updateSignal() { + lit = !(isSignalHigh(0, 0) || isSignalHigh(panelCount - 1, 0)) // isHigh and isLow are not mutually exclusive! + + (sprite as? SheetSpriteAnimation)?.currentRow = 1 - lit.toInt() + (spriteEmissive as? SheetSpriteAnimation)?.currentRow = 1 - lit.toInt() + textOverlay?.currentRow = 1 - lit.toInt() + textOverlayEmissive?.currentRow = 1 - lit.toInt() + } + + override fun dispose() { + super.dispose() + if (textOverlay != null) App.disposables.add(textOverlay) + if (textOverlayEmissive != null) App.disposables.add(textOverlayEmissive) + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemTextSignCopper.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemTextSignCopper.kt new file mode 100644 index 000000000..99298be89 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemTextSignCopper.kt @@ -0,0 +1,26 @@ +package net.torvald.terrarum.modulebasegame.gameitems + +import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.terrarum.CommonResourcePool +import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.gameactors.ActorWithBody +import net.torvald.terrarum.gameitems.ItemID +import net.torvald.terrarum.modulebasegame.TerrarumIngame +import net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalEmitter + +/** + * Created by minjaesong on 2024-03-20. + */ +class ItemTextSignCopper(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureTextSignCopper") { + + override var dynamicID: ItemID = originalID + override var baseMass = 10.0 + override val canBeDynamic = false + override val materialId = "" + override val itemImage: TextureRegion + get() = CommonResourcePool.getAsItemSheet("basegame.items").get(10, 3) + + override var baseToolSize: Double? = baseMass + override var originalName = "ITEM_COPPER_SIGN" + +} \ No newline at end of file