mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 04:41:51 +09:00
fixed a bug where wires cause quicksave to fail
This commit is contained in:
@@ -373,7 +373,7 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
||||
val flags2 = FileInputStream(file2).let { it.skip(49L); val r = it.read(); it.close(); r }
|
||||
val flags1 = FileInputStream(file1).let { it.skip(49L); val r = it.read(); it.close(); r }
|
||||
|
||||
if (!(flags2 == 0 && flags1 != 0)) {
|
||||
if (!(flags2 == 0 && flags1 != 0) || !file2.exists()) {
|
||||
file1.copyTo(file2, true)
|
||||
}
|
||||
} catch (e: NoSuchFileException) {
|
||||
|
||||
@@ -21,9 +21,9 @@ import net.torvald.terrarum.blockproperties.WireCodex
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameactors.ActorID
|
||||
import net.torvald.terrarum.gameactors.faction.FactionCodex
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.itemproperties.MaterialCodex
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.tvda.VDUtil
|
||||
import net.torvald.terrarum.tvda.VirtualDisk
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
@@ -251,13 +251,13 @@ object Terrarum : Disposable {
|
||||
|
||||
/** Position of the cursor in the world */
|
||||
val mouseX: Double
|
||||
get() = WorldCamera.zoomedX + Gdx.input.x / (ingame?.screenZoom ?: 1f).toDouble()
|
||||
get() = (WorldCamera.zoomedX + Gdx.input.x / (ingame?.screenZoom ?: 1f).toDouble()).fmod(WorldCamera.worldWidth.toDouble())
|
||||
/** Position of the cursor in the world */
|
||||
val mouseY: Double
|
||||
get() = WorldCamera.zoomedY + Gdx.input.y / (ingame?.screenZoom ?: 1f).toDouble()
|
||||
get() = (WorldCamera.zoomedY + Gdx.input.y / (ingame?.screenZoom ?: 1f).toDouble())
|
||||
/** Position of the cursor in the world */
|
||||
val oldMouseX: Double
|
||||
get() = WorldCamera.zoomedX + (Gdx.input.x - Gdx.input.deltaX) / (ingame?.screenZoom ?: 1f).toDouble()
|
||||
get() = (WorldCamera.zoomedX + (Gdx.input.x - Gdx.input.deltaX) / (ingame?.screenZoom ?: 1f).toDouble()).fmod(WorldCamera.worldWidth.toDouble())
|
||||
/** Position of the cursor in the world */
|
||||
val oldMouseY: Double
|
||||
get() = WorldCamera.zoomedY + (Gdx.input.y - Gdx.input.deltaY) / (ingame?.screenZoom ?: 1f).toDouble()
|
||||
@@ -539,8 +539,7 @@ fun Float.sqr() = this * this
|
||||
fun Double.sqrt() = Math.sqrt(this)
|
||||
fun Float.sqrt() = FastMath.sqrt(this)
|
||||
fun Int.abs() = this.absoluteValue
|
||||
fun Double.bipolarClamp(limit: Double) =
|
||||
this.coerceIn(-limit, limit)
|
||||
fun Double.bipolarClamp(limit: Double) = this.coerceIn(-limit, limit)
|
||||
fun Boolean.toInt() = if (this) 1 else 0
|
||||
fun Int.bitCount() = java.lang.Integer.bitCount(this)
|
||||
fun Long.bitCount() = java.lang.Long.bitCount(this)
|
||||
|
||||
@@ -199,7 +199,7 @@ open class GameWorld() : Disposable {
|
||||
fun getLayer(index: Int) = when(index) {
|
||||
0 -> layerTerrain
|
||||
1 -> layerWall
|
||||
else -> throw IllegalArgumentException("Unknown layer index: $index")
|
||||
else -> null//throw IllegalArgumentException("Unknown layer index: $index")
|
||||
}
|
||||
|
||||
fun coerceXY(x: Int, y: Int) = (x fmod width) to (y.coerceIn(0, height - 1))
|
||||
@@ -701,6 +701,7 @@ open class GameWorld() : Disposable {
|
||||
infix fun Int.fmod(other: Int) = Math.floorMod(this, other)
|
||||
infix fun Long.fmod(other: Long) = Math.floorMod(this, other)
|
||||
infix fun Float.fmod(other: Float) = if (this >= 0f) this % other else (this % other) + other
|
||||
infix fun Double.fmod(other: Double) = if (this >= 0.0) this % other else (this % other) + other
|
||||
|
||||
inline class FluidType(val value: Int) {
|
||||
infix fun sameAs(other: FluidType) = this.value.absoluteValue == other.value.absoluteValue
|
||||
|
||||
@@ -124,7 +124,7 @@ class GameSavingThread(val disk: VirtualDisk, val outFile: File, val ingame: Ter
|
||||
|
||||
Echo("Writing chunks... ${(cw*ch*layer) + chunkNumber + 1}/${cw*ch*layers.size}")
|
||||
|
||||
val chunkBytes = WriteWorld.encodeChunk(layers[layer], cx, cy)
|
||||
val chunkBytes = WriteWorld.encodeChunk(layers[layer]!!, cx, cy)
|
||||
val entryID = worldNum.toLong().shl(32) or layer.toLong().shl(24) or chunkNumber
|
||||
|
||||
val entryContent = EntryFile(chunkBytes)
|
||||
|
||||
@@ -91,27 +91,27 @@ class QuickSaveThread(val disk: VirtualDisk, val file: File, val ingame: Terraru
|
||||
chunks.forEachIndexed { layerNum, chunks ->
|
||||
|
||||
if (chunks.size != 0) {
|
||||
val layer = ingame.world.getLayer(layerNum)
|
||||
ingame.world.getLayer(layerNum)?.let { layer ->
|
||||
chunks.forEach { chunkNumber ->
|
||||
|
||||
chunks.forEach { chunkNumber ->
|
||||
Echo("Writing chunks... $chunksWrote/$chunkCount")
|
||||
|
||||
Echo("Writing chunks... $chunksWrote/$chunkCount")
|
||||
|
||||
val chunkXY = LandUtil.chunkNumToChunkXY(ingame.world, chunkNumber)
|
||||
val chunkXY = LandUtil.chunkNumToChunkXY(ingame.world, chunkNumber)
|
||||
|
||||
// println("Chunk xy from number $chunkNumber -> (${chunkXY.x}, ${chunkXY.y})")
|
||||
|
||||
val chunkBytes = WriteWorld.encodeChunk(layer, chunkXY.x, chunkXY.y)
|
||||
val entryID = worldNum.toLong().shl(32) or layerNum.toLong().shl(24) or chunkNumber.toLong()
|
||||
val chunkBytes = WriteWorld.encodeChunk(layer, chunkXY.x, chunkXY.y)
|
||||
val entryID = worldNum.toLong().shl(32) or layerNum.toLong().shl(24) or chunkNumber.toLong()
|
||||
|
||||
val entryContent = EntryFile(chunkBytes)
|
||||
val entry = DiskEntry(entryID, 0, creation_t, time_t, entryContent)
|
||||
// "W1L0-92,15"
|
||||
addFile(disk, entry); skimmer.appendEntryOnly(entry)
|
||||
val entryContent = EntryFile(chunkBytes)
|
||||
val entry = DiskEntry(entryID, 0, creation_t, time_t, entryContent)
|
||||
// "W1L0-92,15"
|
||||
addFile(disk, entry); skimmer.appendEntryOnly(entry)
|
||||
|
||||
WriteSavegame.saveProgress += chunkProgressMultiplier
|
||||
chunksWrote += 1
|
||||
WriteSavegame.saveProgress += chunkProgressMultiplier
|
||||
chunksWrote += 1
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ object LoadSavegame {
|
||||
val chunkFile = VDUtil.getAsNormalFile(disk, worldnum.shl(32) or layer.toLong().shl(24) or chunk)
|
||||
val chunkXY = LandUtil.chunkNumToChunkXY(world, chunk.toInt())
|
||||
|
||||
ReadWorld.decodeChunkToLayer(chunkFile.getContent(), worldLayer[layer], chunkXY.x, chunkXY.y)
|
||||
ReadWorld.decodeChunkToLayer(chunkFile.getContent(), worldLayer[layer]!!, chunkXY.x, chunkXY.y)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,8 +62,12 @@ object WorldCamera {
|
||||
|
||||
private val nullVec = Vector2(0.0, 0.0)
|
||||
|
||||
private var worldWidth = 0
|
||||
private var worldHeight = 0
|
||||
/** World width in pixels */
|
||||
var worldWidth = 0
|
||||
private set
|
||||
/** World height in pixels */
|
||||
var worldHeight = 0
|
||||
private set
|
||||
|
||||
fun update(world: GameWorld, player: ActorWithBody?) {
|
||||
if (player == null) return
|
||||
|
||||
Reference in New Issue
Block a user