From 99a60716b8f18fc73be6bd92bbfdebd7153cfa6f Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 28 Jul 2022 20:21:06 +0900 Subject: [PATCH] overridable door base so that door variants can be created --- .../gameactors/FixtureSwingingDoorBase.kt | 98 ++++++++++++++----- .../gameactors/FixtureSwingingDoorRosewood.kt | 26 +++++ .../modulebasegame/gameitems/ItemTestDoor.kt | 6 +- 3 files changed, 104 insertions(+), 26 deletions(-) create mode 100644 src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorRosewood.kt diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt index b9d20cb35..3f991f2d8 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt @@ -1,5 +1,6 @@ package net.torvald.terrarum.modulebasegame.gameactors +import net.torvald.gdx.graphics.Cvec import net.torvald.spriteanimation.SheetSpriteAnimation import net.torvald.terrarum.* import net.torvald.terrarum.App.printdbg @@ -7,6 +8,7 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.gameactors.* +import net.torvald.terrarum.langpack.Lang import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import org.dyn4j.geometry.Vector2 import java.util.* @@ -21,24 +23,25 @@ import kotlin.math.absoluteValue open class FixtureSwingingDoorBase : FixtureBase, Luminous { /* OVERRIDE THESE TO CUSTOMISE */ - open val tw = 2 // tilewise width of the door when opened - open val th = 3 // tilewise height of the door - open val twClosed = 1 // tilewise width of the door when closed - open val opacity = BlockCodex[Block.STONE].opacity - open val isOpacityActuallyLuminosity = false - open val moduleName = "basegame" - open val texturePath = "sprites/fixtures/door_test.tga" - open val textureIdentifier = "fixtures-door_test.tga" - open val customNameFun = { "DOOR_BASE" } - open val doorClosedHoldLength: Second = 0.1f - open val doorOpenedHoldLength: Second = 0.25f + var tw = 2 // tilewise width of the door when opened + var twClosed = 1 // tilewise width of the door when closed + var th = 3 // tilewise height of the door + var opacity = BlockCodex[Block.STONE].opacity + var isOpacityActuallyLuminosity = false + var moduleName = "basegame" + var texturePath = "sprites/fixtures/door_test.tga" + var textureIdentifier = "fixtures-door_test.tga" + var doorClosedHoldLength: Second = 0.1f + var doorOpenedHoldLength: Second = 0.25f + var nameKey = "DOOR_BASE" // goes into the savegame + var nameKeyReadFromLang = true // goes into the savegame /* END OF CUTOMISABLE PARAMETERS */ - private val tilewiseHitboxWidth = tw * 2 - twClosed - private val tilewiseHitboxHeight = th - private val pixelwiseHitboxWidth = TILE_SIZE * tilewiseHitboxWidth - private val pixelwiseHitboxHeight = TILE_SIZE * tilewiseHitboxHeight - private val tilewiseDistToAxis = tw - twClosed + private var tilewiseHitboxWidth = tw * 2 - twClosed + private var tilewiseHitboxHeight = th + private var pixelwiseHitboxWidth = TILE_SIZE * tilewiseHitboxWidth + private var pixelwiseHitboxHeight = TILE_SIZE * tilewiseHitboxHeight + private var tilewiseDistToAxis = tw - twClosed @Transient override val lightBoxList: ArrayList = ArrayList() @Transient override val shadeBoxList: ArrayList = ArrayList() @@ -46,19 +49,62 @@ open class FixtureSwingingDoorBase : FixtureBase, Luminous { protected var doorState = 0 // -1: open toward left, 0: closed, 1: open toward right protected var doorStateTimer: Second = 0f - @Transient private val doorHoldLength: HashMap = hashMapOf( - -1 to doorClosedHoldLength, - 1 to doorClosedHoldLength, - 0 to doorOpenedHoldLength - ) - -// @Transient private var placeActorBlockLatch = false + @Transient private lateinit var customNameFun: () -> String + @Transient private lateinit var doorHoldLength: HashMap constructor() : super( BlockBox(BlockBox.FULL_COLLISION, 1, 1), // temporary value, will be overwritten by spawn() nameFun = { "item not loaded properly, alas!" } ) { + _construct( + 2, + 1, + 3, + BlockCodex[Block.STONE].opacity, + false, + "basegame", + "sprites/fixtures/door_test.tga", + "fixtures-door_test.tga", + "DOOR_BASE", + true + ) + } + protected fun _construct( + tw: Int, // tilewise width of the door when opened + twClosed: Int, // tilewise width of the door when closed + th: Int, // tilewise height of the door + opacity: Cvec, + isOpacityActuallyLuminosity: Boolean, + moduleName: String, + texturePath: String, + textureIdentifier: String, + nameKey: String, + nameKeyReadFromLang: Boolean, + doorCloseHoldLength: Second = 0.1f, + doorOpenedHoldLength: Second = 0.25f + ) { + this.tw = tw + this.twClosed = twClosed + this.th = th + this.opacity = opacity + this.isOpacityActuallyLuminosity = isOpacityActuallyLuminosity + this.moduleName = moduleName + this.texturePath = texturePath + this.textureIdentifier = textureIdentifier + this.nameKey = nameKey + this.nameKeyReadFromLang = nameKeyReadFromLang + this.doorClosedHoldLength = doorCloseHoldLength + this.doorOpenedHoldLength = doorOpenedHoldLength + + this.tilewiseHitboxWidth = tw * 2 - twClosed + this.tilewiseHitboxHeight = th + this.pixelwiseHitboxWidth = TILE_SIZE * tilewiseHitboxWidth + this.pixelwiseHitboxHeight = TILE_SIZE * tilewiseHitboxHeight + this.tilewiseDistToAxis = tw - twClosed + + + this.customNameFun = { if (nameKeyReadFromLang) Lang[nameKey] else nameKey } nameFun = customNameFun density = 1200.0 @@ -82,6 +128,12 @@ open class FixtureSwingingDoorBase : FixtureBase, Luminous { setHitboxDimension(TILE_SIZE * tilewiseHitboxWidth, TILE_SIZE * tilewiseHitboxHeight, 0, 0) blockBox = BlockBox(BlockBox.FULL_COLLISION, tilewiseHitboxWidth, tilewiseHitboxHeight) + doorHoldLength = hashMapOf( + -1 to doorClosedHoldLength, + 1 to doorClosedHoldLength, + 0 to doorOpenedHoldLength + ) + reload() } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorRosewood.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorRosewood.kt new file mode 100644 index 000000000..53cac431e --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorRosewood.kt @@ -0,0 +1,26 @@ +package net.torvald.terrarum.modulebasegame.gameactors + +import net.torvald.terrarum.BlockCodex +import net.torvald.terrarum.blockproperties.Block + +/** + * Created by minjaesong on 2022-07-28. + */ +class FixtureSwingingDoorRosewood : FixtureSwingingDoorBase { + + constructor() : super() { + _construct( + 2, + 1, + 3, + BlockCodex[Block.STONE].opacity, + false, + "basegame", + "sprites/fixtures/door_basegame-51.tga", + "fixtures-door_basegame-51.tga", + "DOOR_ROSEWOOD", + true + ) + } + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemTestDoor.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemTestDoor.kt index 08b0f792f..fefa0acb3 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemTestDoor.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemTestDoor.kt @@ -5,12 +5,12 @@ import net.torvald.terrarum.CommonResourcePool import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase -import net.torvald.terrarum.modulebasegame.gameactors.FixtureSwingingDoorBase +import net.torvald.terrarum.modulebasegame.gameactors.FixtureSwingingDoorRosewood /** * Created by minjaesong on 2022-07-15. */ -class ItemTestDoor(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureSwingingDoorBase") { +class ItemTestDoor(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureSwingingDoorRosewood") { override var dynamicID: ItemID = originalID override val originalName = "ITEM_DOOR" @@ -29,7 +29,7 @@ class ItemTestDoor(originalID: ItemID) : FixtureItemBase(originalID, "net.torval } override val makeFixture: () -> FixtureBase = { - FixtureSwingingDoorBase() + FixtureSwingingDoorRosewood() } } \ No newline at end of file