mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 04:41:51 +09:00
all potentially serialisable actors now have no-arg constructor
This commit is contained in:
@@ -355,7 +355,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
}
|
||||
|
||||
private class CameraPlayer(val demoWorld: GameWorld, override val ai: ActorAI) : ActorWithBody(RenderOrder.FRONT, physProp = PhysProperties.MOBILE_OBJECT), AIControlled {
|
||||
private class CameraPlayer(val demoWorld: GameWorld, override var ai: ActorAI) : ActorWithBody(RenderOrder.FRONT, physProp = PhysProperties.MOBILE_OBJECT), AIControlled {
|
||||
|
||||
override val hitbox = Hitbox(0.0, 0.0, 2.0, 2.0)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -26,9 +26,11 @@ import java.util.*
|
||||
*
|
||||
* Created by minjaesong on 2016-10-24.
|
||||
*/
|
||||
open class ActorHumanoid() : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure {
|
||||
open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure {
|
||||
|
||||
constructor(birth: Long, death: Long? = null, physProp: PhysProperties = PhysProperties.HUMANOID_DEFAULT) : this() {
|
||||
protected constructor()
|
||||
|
||||
constructor(birth: Long, death: Long? = null, physProp: PhysProperties = PhysProperties.HUMANOID_DEFAULT) : super() {
|
||||
actorValue[AVKey.__HISTORICAL_BORNTIME] = birth
|
||||
death?.let { actorValue[AVKey.__HISTORICAL_DEADTIME] = death }
|
||||
this.physProp = physProp
|
||||
|
||||
@@ -17,13 +17,18 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
/**
|
||||
* Created by minjaesong on 2016-03-15.
|
||||
*/
|
||||
open class DroppedItem(private val itemID: ItemID, topLeftX: Int, topLeftY: Int) : ActorWithBody(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT) {
|
||||
open class DroppedItem : ActorWithBody {
|
||||
|
||||
private var itemID: ItemID = ""
|
||||
private val textureRegion = ItemCodex.getItemImage(itemID)
|
||||
|
||||
var itemCount = 1
|
||||
|
||||
init {
|
||||
protected constructor()
|
||||
|
||||
constructor(itemID: ItemID, topLeftX: Int, topLeftY: Int) : super(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT) {
|
||||
this.itemID = itemID
|
||||
|
||||
if (itemID.startsWith("actor@"))
|
||||
throw RuntimeException("Attempted to create DroppedItem actor of a real actor; the real actor must be dropped instead.")
|
||||
|
||||
|
||||
@@ -27,22 +27,34 @@ interface Electric {
|
||||
/**
|
||||
* Created by minjaesong on 2016-06-17.
|
||||
*/
|
||||
open class FixtureBase(
|
||||
blockBox0: BlockBox,
|
||||
val blockBoxProps: BlockBoxProps = BlockBoxProps(0),
|
||||
renderOrder: RenderOrder = RenderOrder.MIDDLE,
|
||||
val nameFun: () -> String,
|
||||
val mainUI: UICanvas? = null,
|
||||
val inventory: FixtureInventory? = null,
|
||||
id: ActorID? = null
|
||||
// disabling physics (not allowing the fixture to move) WILL make things easier in many ways
|
||||
) : ActorWithBody(renderOrder, PhysProperties.IMMOBILE, id), CuedByTerrainChange {
|
||||
open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
|
||||
var blockBox: BlockBox = blockBox0
|
||||
protected set // something like TapestryObject will want to redefine this
|
||||
lateinit var blockBox: BlockBox // something like TapestryObject will want to redefine this
|
||||
fun blockBoxIndexToPoint2i(it: BlockBoxIndex): Point2i = this.blockBox.width.let { w -> Point2i(it % w, it / w) }
|
||||
var blockBoxProps: BlockBoxProps = BlockBoxProps(0)
|
||||
var nameFun: () -> String = { "" }
|
||||
var mainUI: UICanvas? = null
|
||||
var inventory: FixtureInventory? = null
|
||||
|
||||
protected constructor()
|
||||
|
||||
constructor(blockBox0: BlockBox,
|
||||
blockBoxProps: BlockBoxProps = BlockBoxProps(0),
|
||||
renderOrder: RenderOrder = RenderOrder.MIDDLE,
|
||||
nameFun: () -> String,
|
||||
mainUI: UICanvas? = null,
|
||||
inventory: FixtureInventory? = null,
|
||||
id: ActorID? = null) : super(renderOrder, PhysProperties.IMMOBILE, id) {
|
||||
blockBox = blockBox0
|
||||
this.blockBoxProps = blockBoxProps
|
||||
this.renderOrder = renderOrder
|
||||
this.nameFun = nameFun
|
||||
this.mainUI = mainUI
|
||||
this.inventory = inventory
|
||||
|
||||
if (mainUI != null)
|
||||
AppLoader.disposableSingletonsPool.add(mainUI)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tile-wise position of this fixture when it's placed on the world, top-left origin. Null if it's not on the world
|
||||
@@ -50,11 +62,6 @@ open class FixtureBase(
|
||||
var worldBlockPos: Point2i? = null
|
||||
private set
|
||||
|
||||
init {
|
||||
if (mainUI != null)
|
||||
AppLoader.disposableSingletonsPool.add(mainUI)
|
||||
}
|
||||
|
||||
fun forEachBlockbox(action: (Int, Int) -> Unit) {
|
||||
worldBlockPos!!.let { (posX, posY) ->
|
||||
for (y in posY until posY + blockBox.height) {
|
||||
|
||||
@@ -7,13 +7,18 @@ import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
class FixtureLogicSignalEmitter(nameFun: () -> String)
|
||||
: FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1, 1), nameFun = nameFun), Electric {
|
||||
class FixtureLogicSignalEmitter : FixtureBase, Electric {
|
||||
|
||||
override val wireEmitterTypes: HashMap<String, BlockBoxIndex> = HashMap()
|
||||
override val wireEmission: HashMap<BlockBoxIndex, Vector2> = HashMap()
|
||||
override val wireConsumption: HashMap<BlockBoxIndex, Vector2> = HashMap()
|
||||
|
||||
protected constructor()
|
||||
|
||||
constructor(nameFun: () -> String) : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 1, 1),
|
||||
nameFun = nameFun)
|
||||
|
||||
init {
|
||||
density = 1400.0
|
||||
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, -1)
|
||||
|
||||
@@ -30,14 +30,17 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
/**
|
||||
* Created by minjaesong on 2019-07-08.
|
||||
*/
|
||||
internal class FixtureStorageChest(nameFun: () -> String) : FixtureBase(
|
||||
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1),
|
||||
inventory = FixtureInventory(40, CAPACITY_MODE_COUNT),
|
||||
mainUI = UIStorageChest(),
|
||||
nameFun = nameFun
|
||||
) {
|
||||
internal class FixtureStorageChest : FixtureBase {
|
||||
|
||||
private constructor()
|
||||
|
||||
constructor(nameFun: () -> String) : super(
|
||||
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1),
|
||||
mainUI = UIStorageChest(),
|
||||
inventory = FixtureInventory(40, CAPACITY_MODE_COUNT),
|
||||
nameFun = nameFun
|
||||
) {
|
||||
|
||||
init {
|
||||
(mainUI as UIStorageChest).chestInventory = this.inventory!!
|
||||
(mainUI as UIStorageChest).chestNameFun = this.nameFun
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ import kotlin.math.roundToInt
|
||||
/**
|
||||
* Created by minjaesong on 2016-06-17.
|
||||
*/
|
||||
internal class FixtureTikiTorch(nameFun: () -> String) : FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1, 2), nameFun = nameFun), Luminous {
|
||||
internal class FixtureTikiTorch : FixtureBase, Luminous {
|
||||
|
||||
private val rng = HQRNG()
|
||||
private val rndHash1: Int
|
||||
private val rndHash2: Int
|
||||
private val rndHash1 = rng.nextInt()
|
||||
private val rndHash2 = rng.nextInt()
|
||||
|
||||
override var color: Cvec
|
||||
get() = BlockCodex[Block.TORCH].getLumCol(rndHash1, rndHash2)
|
||||
@@ -32,9 +32,15 @@ internal class FixtureTikiTorch(nameFun: () -> String) : FixtureBase(BlockBox(Bl
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override val lightBoxList: ArrayList<Hitbox>
|
||||
override val lightBoxList: ArrayList<Hitbox> = ArrayList(1)
|
||||
|
||||
private constructor()
|
||||
|
||||
constructor(nameFun: () -> String) : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 1, 2),
|
||||
nameFun = nameFun
|
||||
) {
|
||||
|
||||
init {
|
||||
// loading textures
|
||||
CommonResourcePool.addToLoadingList("sprites-fixtures-tiki_torch.tga") {
|
||||
TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/tiki_torch.tga"), 16, 32)
|
||||
@@ -48,17 +54,12 @@ internal class FixtureTikiTorch(nameFun: () -> String) : FixtureBase(BlockBox(Bl
|
||||
|
||||
setHitboxDimension(16, 32, 0, 0)
|
||||
|
||||
lightBoxList = ArrayList(1)
|
||||
lightBoxList.add(Hitbox(6.0, 5.0, 4.0, 3.0))
|
||||
|
||||
makeNewSprite(CommonResourcePool.getAsTextureRegionPack("sprites-fixtures-tiki_torch.tga"))
|
||||
sprite!!.setRowsAndFrames(1, 2)
|
||||
|
||||
actorValue[AVKey.BASEMASS] = MASS
|
||||
|
||||
rndHash1 = rng.nextInt()
|
||||
rndHash2 = rng.nextInt()
|
||||
|
||||
}
|
||||
|
||||
private var nextDelay = 0.25f
|
||||
|
||||
@@ -12,16 +12,20 @@ import net.torvald.terrarum.itemproperties.Material
|
||||
*
|
||||
* Created by minjaesong on 2016-01-31.
|
||||
*/
|
||||
open class HumanoidNPC(
|
||||
override val ai: ActorAI, // it's there for written-in-Kotlin, "hard-wired" AIs
|
||||
born: Long
|
||||
//forceAssignRefID: Int? = null
|
||||
) : ActorHumanoid(born), AIControlled, CanBeAnItem {
|
||||
open class HumanoidNPC : ActorHumanoid, AIControlled, CanBeAnItem {
|
||||
|
||||
override lateinit var ai: ActorAI
|
||||
|
||||
companion object {
|
||||
val DEFAULT_COLLISION_TYPE = COLLISION_DYNAMIC
|
||||
}
|
||||
|
||||
protected constructor()
|
||||
|
||||
constructor(ai: ActorAI, born: Long) : super(born) {
|
||||
this.ai = ai
|
||||
}
|
||||
|
||||
init {
|
||||
collisionType = DEFAULT_COLLISION_TYPE
|
||||
}
|
||||
|
||||
@@ -11,13 +11,14 @@ import net.torvald.terrarum.gameactors.AVKey
|
||||
* Created by minjaesong on 2015-12-31.
|
||||
*/
|
||||
|
||||
class IngamePlayer() : ActorHumanoid(), HasAssembledSprite {
|
||||
class IngamePlayer : ActorHumanoid, HasAssembledSprite {
|
||||
|
||||
override var animDescPath = "invalid"
|
||||
override var animDescPathGlow: String? = null
|
||||
|
||||
private constructor()
|
||||
|
||||
constructor(animDescPath: String, animDescPathGlow: String?, born: Long) : this() {
|
||||
constructor(animDescPath: String, animDescPathGlow: String?, born: Long) : super(born) {
|
||||
this.animDescPath = animDescPath
|
||||
this.animDescPathGlow = animDescPathGlow
|
||||
actorValue[AVKey.__HISTORICAL_BORNTIME] = born
|
||||
|
||||
@@ -6,12 +6,13 @@ import org.dyn4j.geometry.Vector2
|
||||
/**
|
||||
* Created by minjaesong on 2016-08-29.
|
||||
*/
|
||||
class ProjectileHoming(
|
||||
type: Int,
|
||||
fromPoint: Vector2, // projected coord
|
||||
toPoint: Vector2 // arriving coord
|
||||
) : ProjectileSimple(type, fromPoint, toPoint) {
|
||||
class ProjectileHoming : ProjectileSimple {
|
||||
|
||||
protected constructor()
|
||||
|
||||
constructor(type: Int,
|
||||
fromPoint: Vector2, // projected coord
|
||||
toPoint: Vector2 // arriving coord
|
||||
) : super(type, fromPoint, toPoint)
|
||||
|
||||
}
|
||||
@@ -21,16 +21,13 @@ import java.util.*
|
||||
*/
|
||||
|
||||
// TODO simplified, lightweight physics (does not call PhysicsSolver)
|
||||
open class ProjectileSimple(
|
||||
private val type: Int,
|
||||
fromPoint: Vector2, // projected coord
|
||||
toPoint: Vector2 // arriving coord
|
||||
) : ActorWithBody(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT), Luminous, Projectile {
|
||||
open class ProjectileSimple : ActorWithBody, Luminous, Projectile {
|
||||
|
||||
val damage: Int
|
||||
val displayColour: Color
|
||||
private var type: Int = 0
|
||||
var damage: Int = 0
|
||||
lateinit var displayColour: Color
|
||||
/** scalar part of velocity */
|
||||
val speed: Int
|
||||
var speed: Int = 0
|
||||
|
||||
|
||||
override var color: Cvec
|
||||
@@ -48,9 +45,17 @@ open class ProjectileSimple(
|
||||
private val lifetimeMax = 2500
|
||||
private var lifetimeCounter = 0f
|
||||
|
||||
private val posPre: Point2d
|
||||
private lateinit var posPre: Point2d
|
||||
|
||||
protected constructor()
|
||||
|
||||
constructor(type: Int,
|
||||
fromPoint: Vector2, // projected coord
|
||||
toPoint: Vector2 // arriving coord
|
||||
) : super(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT) {
|
||||
this.type = type
|
||||
|
||||
|
||||
init {
|
||||
setPosition(fromPoint.x, fromPoint.y)
|
||||
posPre = Point2d(fromPoint.x, fromPoint.y)
|
||||
// lightbox sized 8x8 centered to the bullet
|
||||
|
||||
@@ -12,13 +12,20 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
/**
|
||||
* Created by minjaesong on 2017-01-07.
|
||||
*/
|
||||
class TapestryObject(pixmap: Pixmap, val artName: String, val artAuthor: String, nameFun: () -> String) :
|
||||
FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1, 1), renderOrder = RenderOrder.BEHIND, nameFun = nameFun) // placeholder blockbox
|
||||
{
|
||||
class TapestryObject : FixtureBase {
|
||||
|
||||
// physics = false only speeds up for ~2 frames with 50 tapestries
|
||||
|
||||
init {
|
||||
var artName = ""; private set
|
||||
var artAuthor = ""; private set
|
||||
|
||||
private constructor()
|
||||
|
||||
constructor(pixmap: Pixmap, artName: String, artAuthor: String, nameFun: () -> String) : super() {
|
||||
this.artName = artName
|
||||
this.artAuthor = artAuthor
|
||||
this.nameFun = nameFun
|
||||
|
||||
val texture = Texture(pixmap)
|
||||
pixmap.dispose()
|
||||
texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
@@ -30,7 +37,8 @@ class TapestryObject(pixmap: Pixmap, val artName: String, val artAuthor: String,
|
||||
// you CAN'T destroy the image
|
||||
|
||||
// redefine blockbox
|
||||
blockBox = BlockBox(BlockBox.NO_COLLISION, texture.width.div(TILE_SIZEF).ceilInt(), texture.height.div(TILE_SIZEF).ceilInt())
|
||||
this.blockBox = BlockBox(BlockBox.NO_COLLISION, texture.width.div(TILE_SIZEF).ceilInt(), texture.height.div(TILE_SIZEF).ceilInt())
|
||||
this.renderOrder = RenderOrder.BEHIND
|
||||
}
|
||||
|
||||
override fun update(delta: Float) {
|
||||
|
||||
@@ -5,11 +5,22 @@ import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import net.torvald.terrarum.gameactors.Luminous
|
||||
import net.torvald.terrarum.gameactors.PhysProperties
|
||||
import net.torvald.terrarum.gameitem.ItemID
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-04-26.
|
||||
*/
|
||||
class WeaponSwung(val itemID: Int) : ActorWithBody(RenderOrder.MIDTOP, PhysProperties.IMMOBILE), Luminous {
|
||||
class WeaponSwung : ActorWithBody, Luminous {
|
||||
|
||||
var itemID: ItemID = ""; private set
|
||||
|
||||
private constructor()
|
||||
|
||||
constructor(itemID: ItemID) : super(RenderOrder.MIDTOP, PhysProperties.IMMOBILE) {
|
||||
this.itemID = itemID
|
||||
}
|
||||
|
||||
|
||||
// just let the solver use AABB; it's cheap but works just enough
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,8 +20,6 @@ class ReadActor(val ingame: TerrarumIngame) {
|
||||
}
|
||||
|
||||
open fun invoke(worldDataStream: Reader) {
|
||||
IngamePlayer()
|
||||
|
||||
postRead(Common.jsoner.fromJson(IngamePlayer::class.java, worldDataStream))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user