mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
game load wip
This commit is contained in:
@@ -1,8 +1,16 @@
|
||||
package net.torvald.terrarum.serialise
|
||||
|
||||
import net.torvald.spriteanimation.HasAssembledSprite
|
||||
import net.torvald.spriteanimation.SpriteAnimation
|
||||
import net.torvald.terrarum.NoSuchActorWithIDException
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.ByteArray64
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.ByteArray64Writer
|
||||
import java.io.Reader
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-08-24.
|
||||
@@ -23,4 +31,54 @@ object WriteActor {
|
||||
return baw.toByteArray64()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Actor's JSON representation is expected to have "class" property on the root object, such as:
|
||||
* ```
|
||||
* "class":"net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer"
|
||||
* ```
|
||||
*
|
||||
* Created by minjaesong on 2021-08-27.
|
||||
*/
|
||||
object ReadActor {
|
||||
|
||||
fun readActorOnly(worldDataStream: Reader): Actor =
|
||||
Common.jsoner.fromJson(null, worldDataStream)
|
||||
|
||||
operator fun invoke(ingame: TerrarumIngame, worldDataStream: Reader): Actor =
|
||||
postRead(ingame, readActorOnly(worldDataStream))
|
||||
|
||||
private fun postRead(ingame: TerrarumIngame, actor: Actor): Actor {
|
||||
// filling in Transients
|
||||
actor.actorValue.actor = actor
|
||||
|
||||
if (actor is Pocketed)
|
||||
actor.inventory.actor = actor
|
||||
|
||||
if (actor is ActorWithBody) {
|
||||
actor.sprite = SpriteAnimation(actor)
|
||||
|
||||
if (actor is HasAssembledSprite) {
|
||||
if (actor.animDescPathGlow != null) actor.spriteGlow = SpriteAnimation(actor)
|
||||
actor.reassembleSprite(actor.sprite!!, actor.spriteGlow)
|
||||
}
|
||||
}
|
||||
// replace existing player
|
||||
val oldPlayerID = ingame.actorNowPlaying?.referenceID
|
||||
try {
|
||||
ingame.forceRemoveActor(ingame.getActorByID(actor.referenceID))
|
||||
}
|
||||
catch (e: NoSuchActorWithIDException) { /* no actor to delete, you may proceed */ }
|
||||
ingame.addNewActor(actor)
|
||||
|
||||
if (actor.referenceID == oldPlayerID)
|
||||
ingame.actorNowPlaying = actor as ActorHumanoid
|
||||
|
||||
|
||||
return actor
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user