save/load kinda mostly working but fixtures are not getting their sprites back

This commit is contained in:
minjaesong
2021-09-06 17:31:37 +09:00
parent ec08f8d07e
commit 1accf985e7
29 changed files with 230 additions and 126 deletions

View File

@@ -177,6 +177,7 @@ object IngameRenderer : Disposable {
operator fun invoke(
gamePaused: Boolean,
zoom: Float = 1f,
actorsRenderBehind : List<ActorWithBody>? = null,
actorsRenderMiddle : List<ActorWithBody>? = null,
actorsRenderMidTop : List<ActorWithBody>? = null,
@@ -194,7 +195,6 @@ object IngameRenderer : Disposable {
//renderingParticleCount = particlesContainer?.size ?: 0
//renderingParticleCount = (particlesContainer?.buffer?.map { (!it.flagDespawn).toInt() } ?: listOf(0)).sum()
renderingUIsCount = uiContainer?.countVisible() ?: 0
val zoom = Terrarum.ingame?.screenZoom ?: 1f
invokeInit()

View File

@@ -233,7 +233,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
IngameRenderer.setRenderedWorld(world)
super.show() // gameInitialised = true
super.show() // this function sets gameInitialised = true
}
data class NewWorldParameters(
@@ -245,11 +245,11 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
data class Codices(
val meta: WriteMeta.WorldMeta,
val block: BlockCodex,
// val block: BlockCodex,
val item: ItemCodex,
val wire: WireCodex,
val material: MaterialCodex,
val faction: FactionCodex,
// val wire: WireCodex,
// val material: MaterialCodex,
// val faction: FactionCodex,
val apocryphas: Map<String, Any>
)
@@ -270,18 +270,13 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
printdbg(this, "loaded successfully.")
}
else {
printdbg(this, "Ingame setting things up from the savegame")
RoguelikeRandomiser.loadFromSave(codices.meta.randseed0, codices.meta.randseed1)
WeatherMixer.loadFromSave(codices.meta.weatseed0, codices.meta.weatseed1)
// Load BlockCodex //
// Load WireCodex //
// Load ItemCodex //
Terrarum.itemCodex = codices.item
// Load MaterialCodex //
Terrarum.itemCodex.loadFromSave(codices.item)
Terrarum.apocryphas = HashMap(codices.apocryphas)
}
}
@@ -683,6 +678,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
IngameRenderer.invoke(
paused,
screenZoom,
visibleActorsRenderBehind,
visibleActorsRenderMiddle,
visibleActorsRenderMidTop,

View File

@@ -18,7 +18,7 @@ object ImportWorld : ConsoleCommand {
if (args.size == 2) {
try {
val reader = java.io.FileReader(AppLoader.defaultDir + "/Exports/${args[1]}.json")
ReadWorld(Terrarum.ingame!! as TerrarumIngame, reader)
ReadWorld.readWorldAndSetNewWorld(Terrarum.ingame!! as TerrarumIngame, reader)
Echo("Importworld: imported a world from ${args[1]}.json")
}
catch (e: IOException) {
@@ -41,7 +41,7 @@ object ImportActor : ConsoleCommand {
if (args.size == 2) {
try {
val reader = java.io.FileReader(AppLoader.defaultDir + "/Exports/${args[1]}.json")
ReadActor(Terrarum.ingame!! as TerrarumIngame, reader)
ReadActor.readActorAndAddToWorld(Terrarum.ingame!! as TerrarumIngame, reader)
Echo("Importactor: imported an actor from ${args[1]}.json")
}
catch (e: IOException) {

View File

@@ -1,6 +1,10 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.ELLIPSIS
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.ccC
import net.torvald.terrarum.ccG
import net.torvald.terrarum.ccR
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.ByteArray64Reader
@@ -20,12 +24,13 @@ object Load : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
try {
Echo("${ccC}Changing context, ${ccR}do not touch the controller$ccC and ${ccG}wait$ccC$ELLIPSIS")
val charset = Common.CHARSET
val file = File(AppLoader.defaultDir + "/Exports/${args[1]}")
val disk = VDUtil.readDiskArchive(file, charset = charset)
val meta = ReadMeta(disk)
println(meta.loadorder.joinToString())
LoadSavegame(disk)
}
catch (e: IOException) {
Echo("Load: IOException raised.")

View File

@@ -13,7 +13,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
@ConsoleNoExport
internal object SpawnTikiTorch : ConsoleCommand {
override fun execute(args: Array<String>) {
val torch = FixtureTikiTorch { "Tiki Torch" }
val torch = FixtureTikiTorch()
torch.setPosition(Terrarum.mouseX, Terrarum.mouseY)
Terrarum.ingame!!.addNewActor(torch)

View File

@@ -26,6 +26,8 @@ interface Electric {
}
/**
* Protip: do not make child classes take any argument, especially no function (function "classes" have no zero-arg constructor)
*
* Created by minjaesong on 2016-06-17.
*/
open class FixtureBase : ActorWithBody, CuedByTerrainChange {
@@ -37,7 +39,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
var mainUI: UICanvas? = null
var inventory: FixtureInventory? = null
protected constructor()
protected constructor() : super(RenderOrder.BEHIND, PhysProperties.IMMOBILE, null)
constructor(blockBox0: BlockBox,
blockBoxProps: BlockBoxProps = BlockBoxProps(0),
@@ -45,7 +47,8 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
nameFun: () -> String,
mainUI: UICanvas? = null,
inventory: FixtureInventory? = null,
id: ActorID? = null) : super(renderOrder, PhysProperties.IMMOBILE, id) {
id: ActorID? = null
) : super(renderOrder, PhysProperties.IMMOBILE, id) {
blockBox = blockBox0
this.blockBoxProps = blockBoxProps
this.renderOrder = renderOrder
@@ -223,7 +226,10 @@ inline class BlockBoxProps(val flags: Int) {
* @param width Width of the block box, tile-wise
* @param height Height of the block box, tile-wise
*/
data class BlockBox(val collisionType: ItemID, val width: Int, val height: Int) {
data class BlockBox(
val collisionType: ItemID = NO_COLLISION,
val width: Int = 0,
val height: Int = 0) {
/*fun redefine(collisionType: Int, width: Int, height: Int) {
redefine(collisionType)
@@ -246,6 +252,6 @@ data class BlockBox(val collisionType: ItemID, val width: Int, val height: Int)
const val NO_PASS_RIGHT = Block.ACTORBLOCK_NO_PASS_RIGHT
const val NO_PASS_LEFT = Block.ACTORBLOCK_NO_PASS_LEFT
val NULL = BlockBox(NO_COLLISION, 0, 0)
val NULL = BlockBox()
}
}

View File

@@ -4,6 +4,7 @@ import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.blockproperties.WireCodex
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import org.dyn4j.geometry.Vector2
@@ -13,13 +14,15 @@ class FixtureLogicSignalEmitter : FixtureBase, Electric {
override val wireEmission: HashMap<BlockBoxIndex, Vector2> = HashMap()
override val wireConsumption: HashMap<BlockBoxIndex, Vector2> = HashMap()
protected constructor()
constructor(nameFun: () -> String) : super(
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 1, 1),
nameFun = nameFun)
nameFun = { Lang["ITEM_LOGIC_SIGNAL_EMITTER"] }
)
init {
println("INIT AGAIN FixtureLogicSignalEmitter")
density = 1400.0
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, -1)

View File

@@ -32,13 +32,11 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
internal class FixtureStorageChest : FixtureBase {
private constructor()
constructor(nameFun: () -> String) : super(
constructor() : super(
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1),
mainUI = UIStorageChest(),
inventory = FixtureInventory(40, CAPACITY_MODE_COUNT),
nameFun = nameFun
nameFun = { Lang["ITEM_STORAGE_CHEST"] }
) {
(mainUI as UIStorageChest).chestInventory = this.inventory!!

View File

@@ -12,6 +12,7 @@ import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameparticles.ParticleVanishingSprite
import net.torvald.terrarum.gameparticles.ParticleVanishingText
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.util.*
@@ -34,11 +35,9 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
override val lightBoxList: ArrayList<Hitbox> = ArrayList(1)
private constructor()
constructor(nameFun: () -> String) : super(
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 1, 2),
nameFun = nameFun
nameFun = { Lang["ITEM_TIKI_TORCH"] }
) {
// loading textures

View File

@@ -19,7 +19,7 @@ class TapestryObject : FixtureBase {
var artName = ""; private set
var artAuthor = ""; private set
private constructor()
private constructor() : super()
constructor(pixmap: Pixmap, artName: String, artAuthor: String, nameFun: () -> String) : super() {
this.artName = artName

View File

@@ -15,7 +15,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalEmitter
class ItemLogicSignalEmitter(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID
override val originalName = "ITEM_TIKI_TORCH"
override val originalName = "ITEM_LOGIC_SIGNAL_EMITTER"
override var baseMass = FixtureLogicSignalEmitter.MASS
override var stackable = true
override var inventoryCategory = Category.FIXTURE
@@ -38,7 +38,7 @@ class ItemLogicSignalEmitter(originalID: ItemID) : GameItem(originalID) {
}
override fun startPrimaryUse(delta: Float): Boolean {
val item = FixtureLogicSignalEmitter { Lang[originalName] }
val item = FixtureLogicSignalEmitter()
return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY)
// return true when placed, false when cannot be placed

View File

@@ -32,7 +32,7 @@ class ItemStorageChest(originalID: ItemID) : GameItem(originalID) {
}
override fun startPrimaryUse(delta: Float): Boolean {
val item = FixtureStorageChest { Lang[originalName] }
val item = FixtureStorageChest()
return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
// return true when placed, false when cannot be placed

View File

@@ -31,7 +31,7 @@ class TikiTorchTester(originalID: ItemID) : GameItem(originalID) {
}
override fun startPrimaryUse(delta: Float): Boolean {
val item = FixtureTikiTorch { Lang[originalName] }
val item = FixtureTikiTorch()
return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
// return true when placed, false when cannot be placed