all potentially serialisable actors now have no-arg constructor

This commit is contained in:
minjaesong
2021-08-28 18:58:46 +09:00
parent 043bd3a1db
commit 3a6100107e
18 changed files with 135 additions and 78 deletions

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.gameactors.ai.ActorAI
* Created by minjaesong on 2016-01-31.
*/
interface AIControlled {
val ai: ActorAI
var ai: ActorAI
fun moveLeft(amount: Float = 1f)
fun moveRight(amount: Float = 1f)

View File

@@ -12,7 +12,7 @@ typealias ActorID = Int
*
* Created by minjaesong on 2015-12-31.
*/
abstract class Actor() : Comparable<Actor>, Runnable {
abstract class Actor : Comparable<Actor>, Runnable {
/**
* Valid RefID is equal to or greater than 16777216.
@@ -21,6 +21,8 @@ abstract class Actor() : Comparable<Actor>, Runnable {
open var referenceID: ActorID = 0 // in old time this was nullable without initialiser. If you're going to revert to that, add the reason why this should be nullable.
var renderOrder = RenderOrder.MIDDLE
protected constructor()
// needs zero-arg constructor for serialiser to work
constructor(renderOrder: RenderOrder, id: ActorID?) : this() {
referenceID = id ?: Terrarum.generateUniqueReferenceID(renderOrder)

View File

@@ -36,14 +36,14 @@ import kotlin.math.roundToInt
*
* Created by minjaesong on 2016-01-13.
*/
open class ActorWithBody() : Actor() {
open class ActorWithBody : Actor {
var physProp = PhysProperties.HUMANOID_DEFAULT
constructor(renderOrder: RenderOrder, physProp: PhysProperties, id: ActorID? = null) : this() {
protected constructor()
constructor(renderOrder: RenderOrder, physProp: PhysProperties, id: ActorID? = null) : super(renderOrder, id) {
this.physProp = physProp
this.renderOrder = renderOrder
id?.let { this.referenceID = id }
}
@Transient val COLLISION_TEST_MODE = false

View File

@@ -14,7 +14,7 @@ import net.torvald.terrarum.toInt
*
* Created by minjaesong on 2021-07-30.
*/
class WireActor(id: ActorID) : ActorWithBody(RenderOrder.OVERLAY, PhysProperties.IMMOBILE, id) {
class WireActor : ActorWithBody {
companion object {
val WIRE_NEARBY = arrayOf(
@@ -25,6 +25,10 @@ class WireActor(id: ActorID) : ActorWithBody(RenderOrder.OVERLAY, PhysProperties
)
}
private constructor()
constructor(id: ActorID) : super(RenderOrder.OVERLAY, PhysProperties.IMMOBILE, id)
init {
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, 0)
}