mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 10:04:05 +09:00
fixture ghost is now red when it cant be placed there
This commit is contained in:
@@ -34,10 +34,10 @@ class ItemHomeComputer(originalID: ItemID) : GameItem(originalID) {
|
|||||||
equipPosition = EquipPosition.HAND_GRIP
|
equipPosition = EquipPosition.HAND_GRIP
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) {
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) { _, _, mtx, mty ->
|
||||||
val item = FixtureHomeComputer()
|
val item = FixtureHomeComputer()
|
||||||
|
|
||||||
if (item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY, if (actor is IngamePlayer) actor.uuid else null)) 1L else -1L
|
if (item.spawn(mtx, mty, if (actor is IngamePlayer) actor.uuid else null)) 1L else -1L
|
||||||
// return true when placed, false when cannot be placed
|
// return true when placed, false when cannot be placed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.spriteanimation.SpriteAnimation
|
import net.torvald.spriteanimation.SpriteAnimation
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
|
import net.torvald.terrarum.App.printdbg
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.INGAME
|
import net.torvald.terrarum.INGAME
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
@@ -53,19 +54,22 @@ class BlockMarkerActor : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = Phy
|
|||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
if (markerMode == MarkerMode.FIXTURE_GHOST) {
|
if (markerMode == MarkerMode.FIXTURE_GHOST) {
|
||||||
if (INGAME.actorNowPlaying != null) {
|
if (INGAME.actorNowPlaying != null) {
|
||||||
mouseInInteractableRange(INGAME.actorNowPlaying!!) {
|
// mouseInInteractableRange(INGAME.actorNowPlaying!!) { _, _, _, _ ->
|
||||||
|
|
||||||
batch.shader = App.shaderGhastlyWhite
|
batch.shader = App.shaderGhastlyWhite
|
||||||
if (ghost != null) {
|
if (ghost != null) {
|
||||||
batch.color = ghostColour
|
// batch.color = ghostColour
|
||||||
|
batch.shader.setUniformf("ghostColour", ghostColour.r, ghostColour.g, ghostColour.b, ghostColour.a)
|
||||||
drawSpriteInGoodPosition(ghost!!, batch)
|
drawSpriteInGoodPosition(ghost!!, batch)
|
||||||
}
|
}
|
||||||
0L
|
// 0L
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
batch.shader = App.shaderGhastlyWhite
|
batch.shader = App.shaderGhastlyWhite
|
||||||
if (ghost != null) {
|
if (ghost != null) {
|
||||||
batch.color = ghostColour
|
// batch.color = ghostColour
|
||||||
|
batch.shader.setUniformf("ghostColour", ghostColour.r, ghostColour.g, ghostColour.b, ghostColour.a)
|
||||||
drawSpriteInGoodPosition(ghost!!, batch)
|
drawSpriteInGoodPosition(ghost!!, batch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,5 +118,6 @@ class BlockMarkerActor : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = Phy
|
|||||||
|
|
||||||
fun setGhostColourNone() { ghostColour = Color.WHITE }
|
fun setGhostColourNone() { ghostColour = Color.WHITE }
|
||||||
fun setGhostColourAllow() { ghostColour = Color(-1) }
|
fun setGhostColourAllow() { ghostColour = Color(-1) }
|
||||||
|
fun setGhostColourDeny() { ghostColour = Color(0xff8080ff.toInt()) }
|
||||||
fun setGhostColourBlock() { ghostColour = Color(0) }
|
fun setGhostColourBlock() { ghostColour = Color(0) }
|
||||||
}
|
}
|
||||||
@@ -384,13 +384,13 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
|||||||
* The reach is calculated using the actor's reach, reach buff actorvalue and the actor's scale.
|
* The reach is calculated using the actor's reach, reach buff actorvalue and the actor's scale.
|
||||||
*
|
*
|
||||||
* @param actor actor to check the reach
|
* @param actor actor to check the reach
|
||||||
* @param action returns non-negative integer if the action was successfully performed
|
* @param action (Double, Double, Int, Int) to Long; takes `Terrarum.mouseX`, `Terrarum.mouseY`, `Terrarum.mouseTileX`, `Terrarum.mouseTileY` as an input and returns non-negative integer if the action was successfully performed
|
||||||
* @return an amount to remove from the inventory (>= 0); -1 if the action failed or not in interactable range
|
* @return an amount to remove from the inventory (>= 0); -1 if the action failed or not in interactable range
|
||||||
*/
|
*/
|
||||||
fun mouseInInteractableRange(actor: ActorWithBody, action: () -> Long): Long {
|
fun mouseInInteractableRange(actor: ActorWithBody, action: (Double, Double, Int, Int) -> Long): Long {
|
||||||
val mousePos1 = Vector2(Terrarum.mouseX, Terrarum.mouseY)
|
val mousePos1 = Vector2(Terrarum.mouseX, Terrarum.mouseY)
|
||||||
val distMax = actor.actorValue.getAsDouble(AVKey.REACH)!! * (actor.actorValue.getAsDouble(AVKey.REACHBUFF) ?: 1.0) * actor.scale // perform some error checking here
|
val distMax = actor.actorValue.getAsDouble(AVKey.REACH)!! * (actor.actorValue.getAsDouble(AVKey.REACHBUFF) ?: 1.0) * actor.scale // perform some error checking here
|
||||||
return if (distBetween(actor, mousePos1) <= distMax) action() else -1
|
return if (distBetween(actor, mousePos1) <= distMax) action(Terrarum.mouseX, Terrarum.mouseY, Terrarum.mouseTileX, Terrarum.mouseTileY) else -1
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -643,8 +643,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
// #2. If I'm not holding any item and I can do barehandaction (size big enough that barehandactionminheight check passes), perform it
|
// #2. If I'm not holding any item and I can do barehandaction (size big enough that barehandactionminheight check passes), perform it
|
||||||
else if (itemOnGrip == null) {
|
else if (itemOnGrip == null) {
|
||||||
mouseInInteractableRange(actor) {
|
mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
|
||||||
performBarehandAction(actor, delta)
|
performBarehandAction(actor, delta, mwx, mwy, mtx, mty)
|
||||||
0L
|
0L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -675,7 +675,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
// scan for the one with non-null UI.
|
// scan for the one with non-null UI.
|
||||||
// what if there's multiple of such fixtures? whatever, you are supposed to DISALLOW such situation.
|
// what if there's multiple of such fixtures? whatever, you are supposed to DISALLOW such situation.
|
||||||
for (kk in actorsUnderMouse.indices) {
|
for (kk in actorsUnderMouse.indices) {
|
||||||
if (mouseInInteractableRange(actor) {
|
if (mouseInInteractableRange(actor) { _, _, _, _ ->
|
||||||
actorsUnderMouse[kk].mainUI?.let {
|
actorsUnderMouse[kk].mainUI?.let {
|
||||||
uiOpened = true
|
uiOpened = true
|
||||||
|
|
||||||
@@ -1372,7 +1372,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
particlesContainer.appendHead(particle)
|
particlesContainer.appendHead(particle)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun performBarehandAction(actor: ActorWithBody, delta: Float) {
|
fun performBarehandAction(actor: ActorWithBody, delta: Float, mwx: Double, mwy: Double, mtx: Int, mty: Int) {
|
||||||
|
|
||||||
val canAttackOrDig = actor.scale * actor.baseHitboxH >= (actor.actorValue.getAsDouble(AVKey.BAREHAND_MINHEIGHT) ?: 4294967296.0)
|
val canAttackOrDig = actor.scale * actor.baseHitboxH >= (actor.actorValue.getAsDouble(AVKey.BAREHAND_MINHEIGHT) ?: 4294967296.0)
|
||||||
|
|
||||||
@@ -1391,8 +1391,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
val punchSize = actor.scale * actor.actorValue.getAsDouble(AVKey.BAREHAND_BASE_DIGSIZE)!!
|
val punchSize = actor.scale * actor.actorValue.getAsDouble(AVKey.BAREHAND_BASE_DIGSIZE)!!
|
||||||
|
|
||||||
// if there are attackable actor or fixtures
|
// if there are attackable actor or fixtures
|
||||||
val actorsUnderMouse: List<ActorWithBody> = getActorsAtVicinity(Terrarum.mouseX, Terrarum.mouseY, punchSize / 2.0).sortedBy {
|
val actorsUnderMouse: List<ActorWithBody> = getActorsAtVicinity(mwx, mwy, punchSize / 2.0).sortedBy {
|
||||||
(Terrarum.mouseX - it.hitbox.centeredX).sqr() + (Terrarum.mouseY - it.hitbox.centeredY).sqr()
|
(mwx - it.hitbox.centeredX).sqr() + (mwy - it.hitbox.centeredY).sqr()
|
||||||
} // sorted by the distance from the mouse
|
} // sorted by the distance from the mouse
|
||||||
|
|
||||||
// prioritise actors
|
// prioritise actors
|
||||||
@@ -1407,10 +1407,12 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
// pickup a fixture
|
// pickup a fixture
|
||||||
if (fixturesUnderHand.size > 0 && fixturesUnderHand[0].canBeDespawned &&
|
if (fixturesUnderHand.size > 0 && fixturesUnderHand[0].canBeDespawned &&
|
||||||
System.nanoTime() - fixturesUnderHand[0].spawnRequestedTime > 500000000) { // don't pick up the fixture if it was recently placed (0.5 seconds)
|
System.nanoTime() - fixturesUnderHand[0].spawnRequestedTime > 500000000) { // don't pick up the fixture if it was recently placed (0.5 seconds)
|
||||||
val fixture = fixturesUnderHand[0]
|
val fixture = fixturesUnderHand[0]
|
||||||
val fixtureItem = ItemCodex.fixtureToItemID(fixture)
|
val fixtureItem = ItemCodex.fixtureToItemID(fixture)
|
||||||
printdbg(this, "Fixture pickup at F${WORLD_UPDATE_TIMER}: ${fixture.javaClass.canonicalName} -> $fixtureItem")
|
printdbg(this, "Fixture pickup at F${WORLD_UPDATE_TIMER}: ${fixture.javaClass.canonicalName} -> $fixtureItem")
|
||||||
|
// 0. hide tooltips
|
||||||
|
setTooltipMessage(null)
|
||||||
// 1. put the fixture to the inventory
|
// 1. put the fixture to the inventory
|
||||||
fixture.flagDespawn()
|
fixture.flagDespawn()
|
||||||
// 2. register this item(fixture) to the quickslot so that the player sprite would be actually lifting the fixture
|
// 2. register this item(fixture) to the quickslot so that the player sprite would be actually lifting the fixture
|
||||||
@@ -1433,7 +1435,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
else if (canAttackOrDig) {
|
else if (canAttackOrDig) {
|
||||||
val punchBlockSize = punchSize.div(TILE_SIZED).floorToInt()
|
val punchBlockSize = punchSize.div(TILE_SIZED).floorToInt()
|
||||||
if (punchBlockSize > 0) {
|
if (punchBlockSize > 0) {
|
||||||
PickaxeCore.startPrimaryUse(actor, delta, null, Terrarum.mouseTileX, Terrarum.mouseTileY, 1.0 / punchBlockSize, punchBlockSize, punchBlockSize)
|
PickaxeCore.startPrimaryUse(actor, delta, null, mtx, mty, 1.0 / punchBlockSize, punchBlockSize, punchBlockSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,6 +225,24 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun canSpawnHere(posX0: Int, posY0: Int): Boolean {
|
||||||
|
val posX = (posX0 - blockBox.width.minus(1).div(2)) fmod world!!.width // width.minus(1) so that spawning position would be same as the ghost's position
|
||||||
|
val posY = posY0 - blockBox.height + 1
|
||||||
|
|
||||||
|
// check for existing blocks (and fixtures)
|
||||||
|
var hasCollision = false
|
||||||
|
worldBlockPos = Point2i(posX, posY)
|
||||||
|
forEachBlockbox { x, y, _, _ ->
|
||||||
|
if (!hasCollision) {
|
||||||
|
val tile = world!!.getTileFromTerrain(x, y)
|
||||||
|
if (!BlockCodex[tile].hasTag("INCONSEQUENTIAL")) {
|
||||||
|
hasCollision = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !hasCollision
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds this instance of the fixture to the world. Physical dimension is derived from [blockBox].
|
* Adds this instance of the fixture to the world. Physical dimension is derived from [blockBox].
|
||||||
*
|
*
|
||||||
@@ -243,24 +261,10 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
// posY: bottom of the blockBox
|
// posY: bottom of the blockBox
|
||||||
// using the actor's hitbox
|
// using the actor's hitbox
|
||||||
|
|
||||||
|
|
||||||
val posX = (posX0 - blockBox.width.minus(1).div(2)) fmod world!!.width // width.minus(1) so that spawning position would be same as the ghost's position
|
val posX = (posX0 - blockBox.width.minus(1).div(2)) fmod world!!.width // width.minus(1) so that spawning position would be same as the ghost's position
|
||||||
val posY = posY0 - blockBox.height + 1
|
val posY = posY0 - blockBox.height + 1
|
||||||
|
|
||||||
// set the position of this actor
|
if (!canSpawnHere(posX0, posY0)) {
|
||||||
worldBlockPos = Point2i(posX, posY)
|
|
||||||
|
|
||||||
// check for existing blocks (and fixtures)
|
|
||||||
var hasCollision = false
|
|
||||||
forEachBlockbox { x, y, _, _ ->
|
|
||||||
if (!hasCollision) {
|
|
||||||
val tile = world!!.getTileFromTerrain(x, y)
|
|
||||||
if (!BlockCodex[tile].hasTag("INCONSEQUENTIAL")) {
|
|
||||||
hasCollision = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasCollision) {
|
|
||||||
printdbg(this, "cannot spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, has tile collision; xy=($posX,$posY) tDim=(${blockBox.width},${blockBox.height})")
|
printdbg(this, "cannot spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, has tile collision; xy=($posX,$posY) tDim=(${blockBox.width},${blockBox.height})")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,23 +223,23 @@ open class FixtureSwingingDoorBase : FixtureBase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun mouseOnLeftSide(): Boolean {
|
private fun mouseOnLeftSide(mx: Double, my: Double): Boolean {
|
||||||
val ww = INGAME.world.width * TILE_SIZED
|
val ww = INGAME.world.width * TILE_SIZED
|
||||||
val pivot = this@FixtureSwingingDoorBase.hitbox.centeredX
|
val pivot = this@FixtureSwingingDoorBase.hitbox.centeredX
|
||||||
// note: this function uses startX while the dual other function uses endX; the "dist" must be same between two functions
|
// note: this function uses startX while the dual other function uses endX; the "dist" must be same between two functions
|
||||||
val dist = pivot - Terrarum.mouseX // NOTE: order is different from the other function
|
val dist = pivot - mx // NOTE: order is different from the other function
|
||||||
val dist2 = pivot - (Terrarum.mouseX - ww)
|
val dist2 = pivot - (mx - ww)
|
||||||
val distLim = this@FixtureSwingingDoorBase.hitbox.width
|
val distLim = this@FixtureSwingingDoorBase.hitbox.width
|
||||||
return (dist in 0.0..distLim || dist2 in 0.0..distLim) && (Terrarum.mouseY - hitbox.hitboxStart.y) in 0.0..hitbox.height
|
return (dist in 0.0..distLim || dist2 in 0.0..distLim) && (my - hitbox.hitboxStart.y) in 0.0..hitbox.height
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun mouseOnRightSide(): Boolean {
|
private fun mouseOnRightSide(mx: Double, my: Double): Boolean {
|
||||||
val ww = INGAME.world.width * TILE_SIZED
|
val ww = INGAME.world.width * TILE_SIZED
|
||||||
val pivot = this@FixtureSwingingDoorBase.hitbox.centeredX
|
val pivot = this@FixtureSwingingDoorBase.hitbox.centeredX
|
||||||
val dist = Terrarum.mouseX - pivot // NOTE: order is different from the other function
|
val dist = mx - pivot // NOTE: order is different from the other function
|
||||||
val dist2 = (Terrarum.mouseX + ww) - pivot
|
val dist2 = (mx + ww) - pivot
|
||||||
val distLim = this@FixtureSwingingDoorBase.hitbox.width
|
val distLim = this@FixtureSwingingDoorBase.hitbox.width
|
||||||
return dist in 0.0..distLim || dist2 in 0.0..distLim && (Terrarum.mouseY - hitbox.hitboxStart.y) in 0.0..hitbox.height
|
return dist in 0.0..distLim || dist2 in 0.0..distLim && (my - hitbox.hitboxStart.y) in 0.0..hitbox.height
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ActorWithBody.ontheLeftSideOfDoor(): Boolean {
|
private fun ActorWithBody.ontheLeftSideOfDoor(): Boolean {
|
||||||
@@ -313,16 +313,16 @@ open class FixtureSwingingDoorBase : FixtureBase {
|
|||||||
if (mouseUp && Gdx.input.isButtonPressed(App.getConfigInt("config_mousesecondary"))) {
|
if (mouseUp && Gdx.input.isButtonPressed(App.getConfigInt("config_mousesecondary"))) {
|
||||||
|
|
||||||
INGAME.actorNowPlaying?.let { player ->
|
INGAME.actorNowPlaying?.let { player ->
|
||||||
mouseInInteractableRange(player) {
|
mouseInInteractableRange(player) { mx, my, _, _ ->
|
||||||
// keep opened/closed as long as the mouse is down
|
// keep opened/closed as long as the mouse is down
|
||||||
if (doorStateTimer != 0f) {
|
if (doorStateTimer != 0f) {
|
||||||
oldStateBeforeMouseDown = doorState
|
oldStateBeforeMouseDown = doorState
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldStateBeforeMouseDown == 0) {
|
if (oldStateBeforeMouseDown == 0) {
|
||||||
if (mouseOnLeftSide())
|
if (mouseOnLeftSide(mx, my))
|
||||||
openToLeft(1)
|
openToLeft(1)
|
||||||
else if (mouseOnRightSide())
|
else if (mouseOnRightSide(mx, my))
|
||||||
openToRight(1)
|
openToRight(1)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -20,62 +20,63 @@ object BlockBase {
|
|||||||
* @param dontEncaseActors when set to true, blocks won't be placed where Actors are. You will want to set it false
|
* @param dontEncaseActors when set to true, blocks won't be placed where Actors are. You will want to set it false
|
||||||
* for wire items, otherwise you want it to be true.
|
* for wire items, otherwise you want it to be true.
|
||||||
*/
|
*/
|
||||||
fun blockStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, itemID: ItemID, delta: Float) = mouseInInteractableRange(actor) {
|
fun blockStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, itemID: ItemID, delta: Float) =
|
||||||
val ingame = Terrarum.ingame!! as TerrarumIngame
|
mouseInInteractableRange(actor) { mwx, mwy, mtx, mty ->
|
||||||
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble())
|
val ingame = Terrarum.ingame!! as TerrarumIngame
|
||||||
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
val mousePoint = Point2d(mtx.toDouble(), mty.toDouble())
|
||||||
|
val mouseTile = Point2i(mtx, mty)
|
||||||
|
|
||||||
// check for collision with actors (BLOCK only)
|
// check for collision with actors (BLOCK only)
|
||||||
// FIXME properly fix the collision detection: it OVERRIDES the tiki-torches which should not happen AT ALL
|
// FIXME properly fix the collision detection: it OVERRIDES the tiki-torches which should not happen AT ALL
|
||||||
// FIXME (h)IntTilewiseHitbox is badly defined
|
// FIXME (h)IntTilewiseHitbox is badly defined
|
||||||
// FIXME actually it's this code: not recognising hitbox's starting point correctly. Use F9 for visualisation
|
// FIXME actually it's this code: not recognising hitbox's starting point correctly. Use F9 for visualisation
|
||||||
// FIXME the above issue is resolved by using intTilewise instead of hInt, but the hitbox itself is still
|
// FIXME the above issue is resolved by using intTilewise instead of hInt, but the hitbox itself is still
|
||||||
// FIXME badly defined
|
// FIXME badly defined
|
||||||
|
|
||||||
if (gameItem.inventoryCategory == GameItem.Category.BLOCK) {
|
if (gameItem.inventoryCategory == GameItem.Category.BLOCK) {
|
||||||
var ret1 = true
|
var ret1 = true
|
||||||
ingame.actorContainerActive.filter { it is ActorWithBody }.forEach { val it = it as ActorWithBody
|
ingame.actorContainerActive.filter { it is ActorWithBody }.forEach { val it = it as ActorWithBody
|
||||||
if ((it is FixtureBase || it.physProp.usePhysics) && it.intTilewiseHitbox.intersects(mousePoint))
|
if ((it is FixtureBase || it.physProp.usePhysics) && it.intTilewiseHitbox.intersects(mousePoint))
|
||||||
ret1 = false // return is not allowed here
|
ret1 = false // return is not allowed here
|
||||||
|
}
|
||||||
|
if (!ret1) return@mouseInInteractableRange -1L
|
||||||
}
|
}
|
||||||
if (!ret1) return@mouseInInteractableRange -1L
|
|
||||||
|
val isWall = itemID.isWall()
|
||||||
|
val terrainUnderCursor = ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y)
|
||||||
|
val wallUnderCursor = ingame.world.getTileFromWall(mouseTile.x, mouseTile.y)
|
||||||
|
|
||||||
|
// return false if there is a same tile already (including non-solid!)
|
||||||
|
if (isWall && wallUnderCursor == itemID || !isWall && terrainUnderCursor == itemID)
|
||||||
|
return@mouseInInteractableRange -1L
|
||||||
|
|
||||||
|
// return false if there is a "solid" tile already
|
||||||
|
if (isWall && BlockCodex[wallUnderCursor].isSolid ||
|
||||||
|
!isWall && !BlockCodex[terrainUnderCursor].hasTag("INCONSEQUENTIAL"))
|
||||||
|
return@mouseInInteractableRange -1L
|
||||||
|
|
||||||
|
// filter passed, do the job
|
||||||
|
// FIXME this is only useful for Player
|
||||||
|
if (isWall) {
|
||||||
|
ingame.world.setTileWall(
|
||||||
|
mouseTile.x,
|
||||||
|
mouseTile.y,
|
||||||
|
itemID.substring(5),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ingame.world.setTileTerrain(
|
||||||
|
mouseTile.x,
|
||||||
|
mouseTile.y,
|
||||||
|
itemID,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
1L
|
||||||
}
|
}
|
||||||
|
|
||||||
val isWall = itemID.isWall()
|
|
||||||
val terrainUnderCursor = ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y)
|
|
||||||
val wallUnderCursor = ingame.world.getTileFromWall(mouseTile.x, mouseTile.y)
|
|
||||||
|
|
||||||
// return false if there is a same tile already (including non-solid!)
|
|
||||||
if (isWall && wallUnderCursor == itemID || !isWall && terrainUnderCursor == itemID)
|
|
||||||
return@mouseInInteractableRange -1L
|
|
||||||
|
|
||||||
// return false if there is a "solid" tile already
|
|
||||||
if (isWall && BlockCodex[wallUnderCursor].isSolid ||
|
|
||||||
!isWall && !BlockCodex[terrainUnderCursor].hasTag("INCONSEQUENTIAL"))
|
|
||||||
return@mouseInInteractableRange -1L
|
|
||||||
|
|
||||||
// filter passed, do the job
|
|
||||||
// FIXME this is only useful for Player
|
|
||||||
if (isWall) {
|
|
||||||
ingame.world.setTileWall(
|
|
||||||
mouseTile.x,
|
|
||||||
mouseTile.y,
|
|
||||||
itemID.substring(5),
|
|
||||||
false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ingame.world.setTileTerrain(
|
|
||||||
mouseTile.x,
|
|
||||||
mouseTile.y,
|
|
||||||
itemID,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
1L
|
|
||||||
}
|
|
||||||
|
|
||||||
fun blockEffectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
fun blockEffectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
||||||
}
|
}
|
||||||
@@ -126,40 +127,38 @@ object BlockBase {
|
|||||||
else false
|
else false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float) = mouseInInteractableRange(actor) {
|
fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float) = mouseInInteractableRange(actor) { _, _, mtx, mty ->
|
||||||
|
|
||||||
val itemID = gameItem.originalID
|
val itemID = gameItem.originalID
|
||||||
val ingame = Terrarum.ingame!! as TerrarumIngame
|
val ingame = Terrarum.ingame!! as TerrarumIngame
|
||||||
val mouseTileX = Terrarum.mouseTileX
|
|
||||||
val mouseTileY = Terrarum.mouseTileY
|
|
||||||
val ww = ingame.world.width
|
val ww = ingame.world.width
|
||||||
|
|
||||||
if (Gdx.input.isButtonJustPressed(App.getConfigInt("config_mouseprimary")) ||
|
if (Gdx.input.isButtonJustPressed(App.getConfigInt("config_mouseprimary")) ||
|
||||||
!isNeighbouring(ww, mouseTileX, mouseTileY, oldTileX, oldTileY)) {
|
!isNeighbouring(ww, mtx, mty, oldTileX, oldTileY)) {
|
||||||
initialMouseDownTileX = mouseTileX
|
initialMouseDownTileX = mtx
|
||||||
initialMouseDownTileY = mouseTileY
|
initialMouseDownTileY = mty
|
||||||
oldTileX = mouseTileX
|
oldTileX = mtx
|
||||||
oldTileY = mouseTileY
|
oldTileY = mty
|
||||||
}
|
}
|
||||||
|
|
||||||
val thisTileWires = ingame.world.getAllWiresFrom(mouseTileX, mouseTileY)
|
val thisTileWires = ingame.world.getAllWiresFrom(mtx, mty)
|
||||||
val oldTileWires = ingame.world.getAllWiresFrom(oldTileX, oldTileY)
|
val oldTileWires = ingame.world.getAllWiresFrom(oldTileX, oldTileY)
|
||||||
val thisTileWireCnx = ingame.world.getWireGraphOf(mouseTileX, mouseTileY, itemID)
|
val thisTileWireCnx = ingame.world.getWireGraphOf(mtx, mty, itemID)
|
||||||
val oldTileWireCnx = ingame.world.getWireGraphOf(oldTileX, oldTileY, itemID)
|
val oldTileWireCnx = ingame.world.getWireGraphOf(oldTileX, oldTileY, itemID)
|
||||||
|
|
||||||
val thisTileOccupied = thisTileWires.first?.searchFor(itemID) != null
|
val thisTileOccupied = thisTileWires.first?.searchFor(itemID) != null
|
||||||
val oldTileOccupied = oldTileWires.first?.searchFor(itemID) != null
|
val oldTileOccupied = oldTileWires.first?.searchFor(itemID) != null
|
||||||
|
|
||||||
val oldToNewVector = if (mouseTileX == ww - 1 && oldTileX == 0) 4
|
val oldToNewVector = if (mtx == ww - 1 && oldTileX == 0) 4
|
||||||
else if (mouseTileX == 0 && oldTileX == ww - 1) 1
|
else if (mtx == 0 && oldTileX == ww - 1) 1
|
||||||
else if (mouseTileX - oldTileX == 1) 1
|
else if (mtx - oldTileX == 1) 1
|
||||||
else if (mouseTileX - oldTileX == -1) 4
|
else if (mtx - oldTileX == -1) 4
|
||||||
else if (mouseTileY - oldTileY == 1) 2
|
else if (mty - oldTileY == 1) 2
|
||||||
else if (mouseTileY - oldTileY == -1) 8
|
else if (mty - oldTileY == -1) 8
|
||||||
else 0 // if xy == oxy, the vector will be 0
|
else 0 // if xy == oxy, the vector will be 0
|
||||||
|
|
||||||
val connectedEachOther = wireNodesConnectedEachOther(oldToNewVector, thisTileWireCnx, oldTileWireCnx)
|
val connectedEachOther = wireNodesConnectedEachOther(oldToNewVector, thisTileWireCnx, oldTileWireCnx)
|
||||||
val thisTileWasDraggedOn = initialMouseDownTileX != mouseTileX || initialMouseDownTileY != mouseTileY
|
val thisTileWasDraggedOn = initialMouseDownTileX != mtx || initialMouseDownTileY != mty
|
||||||
|
|
||||||
var ret = -1L
|
var ret = -1L
|
||||||
|
|
||||||
@@ -176,7 +175,7 @@ object BlockBase {
|
|||||||
if (!thisTileWasDraggedOn) {
|
if (!thisTileWasDraggedOn) {
|
||||||
if (thisTileOccupied) return@mouseInInteractableRange -1
|
if (thisTileOccupied) return@mouseInInteractableRange -1
|
||||||
else {
|
else {
|
||||||
placeWirePieceTo(ingame.world, itemID, mouseTileX, mouseTileY)
|
placeWirePieceTo(ingame.world, itemID, mtx, mty)
|
||||||
ret = 1
|
ret = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,18 +184,18 @@ object BlockBase {
|
|||||||
ret -1
|
ret -1
|
||||||
}
|
}
|
||||||
else if (thisTileOccupied && oldTileOccupied) {
|
else if (thisTileOccupied && oldTileOccupied) {
|
||||||
setConnectivity(ingame.world, oldToNewVector, itemID, mouseTileX, mouseTileY, oldTileX, oldTileY)
|
setConnectivity(ingame.world, oldToNewVector, itemID, mtx, mty, oldTileX, oldTileY)
|
||||||
ret = 0
|
ret = 0
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
placeWirePieceTo(ingame.world, itemID, mouseTileX, mouseTileY)
|
placeWirePieceTo(ingame.world, itemID, mtx, mty)
|
||||||
setConnectivity(ingame.world, oldToNewVector, itemID, mouseTileX, mouseTileY, oldTileX, oldTileY)
|
setConnectivity(ingame.world, oldToNewVector, itemID, mtx, mty, oldTileX, oldTileY)
|
||||||
ret = 1
|
ret = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
oldTileX = mouseTileX
|
oldTileX = mtx
|
||||||
oldTileY = mouseTileY
|
oldTileY = mty
|
||||||
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
|||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
|
import net.torvald.terrarum.App.printdbg
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitems.GameItem
|
import net.torvald.terrarum.gameitems.GameItem
|
||||||
import net.torvald.terrarum.gameitems.ItemID
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
@@ -67,10 +68,20 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
|
|||||||
|
|
||||||
|
|
||||||
(INGAME as TerrarumIngame).blockMarkingActor.let {
|
(INGAME as TerrarumIngame).blockMarkingActor.let {
|
||||||
it.setGhost(ghostItem.get())
|
val item = ghostItem.get()
|
||||||
|
|
||||||
|
it.setGhost(item)
|
||||||
it.update(delta)
|
it.update(delta)
|
||||||
it.setGhostColourBlock()
|
it.setGhostColourBlock()
|
||||||
mouseInInteractableRange(actor) { it.setGhostColourAllow(); 0L }
|
mouseInInteractableRange(actor) { _, _, mx, my ->
|
||||||
|
if (item.canSpawnHere(mx, my)) {
|
||||||
|
it.setGhostColourAllow()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
it.setGhostColourDeny()
|
||||||
|
}
|
||||||
|
0L
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,10 +94,10 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) {
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) { _, _, mx, my ->
|
||||||
val item = ghostItem.getAndSet(makeFixture()) // renew the "ghost" otherwise you'll be spawning exactly the same fixture again; old ghost will be returned
|
val item = ghostItem.getAndSet(makeFixture()) // renew the "ghost" otherwise you'll be spawning exactly the same fixture again; old ghost will be returned
|
||||||
|
|
||||||
if (item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY, if (actor is IngamePlayer) actor.uuid else null)) 1 else -1
|
if (item.spawn(mx, my, if (actor is IngamePlayer) actor.uuid else null)) 1 else -1
|
||||||
// return true when placed, false when cannot be placed
|
// return true when placed, false when cannot be placed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ in vec4 v_color;
|
|||||||
in vec2 v_texCoords;
|
in vec2 v_texCoords;
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
|
|
||||||
|
uniform vec4 ghostColour = vec4(1.0);
|
||||||
|
|
||||||
const vec2 boolean = vec2(0.0, 1.0);
|
const vec2 boolean = vec2(0.0, 1.0);
|
||||||
const vec4 desaturate = vec4(0.2126, 0.7152, 0.0722, 0.0);
|
const vec4 desaturate = vec4(0.2126, 0.7152, 0.0722, 0.0);
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
@@ -11,6 +13,5 @@ void main(void) {
|
|||||||
vec4 incolour = texture(u_texture, v_texCoords);
|
vec4 incolour = texture(u_texture, v_texCoords);
|
||||||
float lum = dot(incolour * desaturate, boolean.yyyx) * 0.5 + 0.5;
|
float lum = dot(incolour * desaturate, boolean.yyyx) * 0.5 + 0.5;
|
||||||
|
|
||||||
// fragColor = v_color * (vec4(lum) * boolean.yyyx + incolour * boolean.xxxy);
|
fragColor = ghostColour * fma(vec4(lum), boolean.yyyx, incolour * boolean.xxxy);
|
||||||
fragColor = v_color * fma(vec4(lum), boolean.yyyx, incolour * boolean.xxxy);
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user