tapestry now persists after load

This commit is contained in:
minjaesong
2024-03-11 23:54:02 +09:00
parent 8aa866f040
commit b05ae829cc
5 changed files with 73 additions and 57 deletions

View File

@@ -185,6 +185,53 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
return !cannotSpawn
}
/**
* @param posX top-left
* @param posY top-left
*/
open fun makeNoiseAndDust(posX: Int, posY: Int) {
val posYb = posY + blockBox.height - 1
val posXc = posX + blockBox.width / 2
// make some noise
var soundSource =
if (spawnNeedsWall) 1
else if (spawnNeedsFloor) 0
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)
if (soundSource == 2) {
soundSource = if (BlockCodex[wallTile].isSolid)
1
else
0
}
when (soundSource) {
1 -> PickaxeCore.makeNoiseTileBurst(this, wallTile)
0 -> PickaxeCore.makeNoiseTileBurst(this, terrTile)
}
// make some dust
if (soundSource == 0) {
val y = posY + blockBox.height
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) {
val tile = world!!.getTileFromWall(x, y)
PickaxeCore.makeDust(tile, x, y, 2 + (Math.random() + Math.random()).roundToInt())
}
}
}
}
/**
* Adds this instance of the fixture to the world. Physical dimension is derived from [blockBox].
*
@@ -245,53 +292,6 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
return true
}
/**
* @param posX top-left
* @param posY top-left
*/
open fun makeNoiseAndDust(posX: Int, posY: Int) {
val posYb = posY + blockBox.height - 1
val posXc = posX + blockBox.width / 2
// make some noise
var soundSource =
if (spawnNeedsWall) 1
else if (spawnNeedsFloor) 0
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)
if (soundSource == 2) {
soundSource = if (BlockCodex[wallTile].isSolid)
1
else
0
}
when (soundSource) {
1 -> PickaxeCore.makeNoiseTileBurst(this, wallTile)
0 -> PickaxeCore.makeNoiseTileBurst(this, terrTile)
}
// make some dust
if (soundSource == 0) {
val y = posY + blockBox.height
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) {
val tile = world!!.getTileFromWall(x, y)
PickaxeCore.makeDust(tile, x, y, 2 + (Math.random() + Math.random()).roundToInt())
}
}
}
}
/**
* Identical to `spawn(Int, Int)` except it takes user-defined hitbox dimension instead of taking value from [blockBox].
* Useful if [blockBox] cannot be determined on the time of the constructor call.
@@ -457,8 +457,6 @@ interface CuedByWireChange {
fun updateForWireChange(cue: IngameInstance.BlockChangeQueueItem)
}
interface DeferredSpawn
/**
* Standard 32-bit binary flags.
*

View File

@@ -4,6 +4,8 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.tooltipShowing
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import org.dyn4j.geometry.Vector2
@@ -39,7 +41,9 @@ class FixtureLogicSignalEmitter : Electric {
setWireEmissionAt(0, 0, Vector2(1.0, 0.0))
}
override fun dispose() { }
override fun dispose() {
tooltipShowing.remove(tooltipHash)
}
companion object {
const val MASS = 1.0

View File

@@ -16,7 +16,7 @@ import kotlin.properties.Delegates
/**
* Created by minjaesong on 2017-01-07.
*/
internal class FixtureTapestry : FixtureBase, DeferredSpawn {
internal class FixtureTapestry : FixtureBase {
@Transient override val spawnNeedsWall = true
@Transient override val spawnNeedsFloor = false
@@ -106,9 +106,17 @@ internal class FixtureTapestry : FixtureBase, DeferredSpawn {
pixmap.dispose()
INGAME.disposables.add(texture)
}
App.disposables.add(texture)
spawn(
intTilewiseHitbox.canonicalX.toInt(),
intTilewiseHitbox.canonicalY.toInt(),
actorThatInstalledThisFixture,
tilewiseHitboxWidth,
tilewiseHitboxHeight
)
}
override var tooltipText: String? = "TEST\nSTRING"//if (artName.length + artAuthor.length > 0) "$artName\n$artAuthor" else null
}