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

@@ -63,7 +63,8 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
}
}
val disposables = HashSet<Disposable>()
/** things to be disposed of when the current instance of the game disposed of */
// val disposables = HashSet<Disposable>()
lateinit var worldDisk: VirtualDisk; internal set
lateinit var playerDisk: VirtualDisk; internal set
@@ -231,7 +232,7 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
actorContainerInactive.forEach { it.dispose() }
world.dispose()
disposables.forEach { it.tryDispose() }
// disposables.forEach { it.tryDispose() }
}
////////////

View File

@@ -98,7 +98,7 @@ open class ActorWithBody : Actor {
val mouseUp: Boolean
get() = hitbox.containsPoint((world?.width ?: 0) * TILE_SIZED, Terrarum.mouseX, Terrarum.mouseY)
@Transient private val tooltipHash = System.nanoTime()
@Transient protected val tooltipHash = System.nanoTime()
var hitboxTranslateX: Int = 0// relative to spritePosX
protected set
@@ -678,13 +678,16 @@ open class ActorWithBody : Actor {
}
}
if (tooltipText == null || !mouseUp) {
if (tooltipText == null || !mouseUp || flagDespawn) {
tooltipShowing[tooltipHash] = false
}
// isStationary = (hitbox - oldHitbox).magnitudeSquared < PHYS_EPSILON_VELO
isStationary = isCloseEnough(hitbox.startX, oldHitbox.startX) && // this is supposed to be more accurate, idk
isCloseEnough(hitbox.startY, oldHitbox.startY)
printdbg(this, tooltipShowing.keys.sorted())
}
fun getDrag(externalForce: Vector2): Vector2 {
@@ -1929,6 +1932,7 @@ open class ActorWithBody : Actor {
internal open fun flagDespawn() {
flagDespawn = true
tooltipShowing.remove(tooltipHash)
}
open fun getSpriteHead(): TextureRegion? {
@@ -2252,6 +2256,7 @@ open class ActorWithBody : Actor {
App.disposables.add(sprite)
App.disposables.add(spriteGlow)
App.disposables.add(spriteEmissive)
tooltipShowing.remove(tooltipHash)
}
}

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
}