diff --git a/ModuleComputers/src/net/torvald/terrarum/modulecomputers/gameitems/ItemHomeComputer.kt b/ModuleComputers/src/net/torvald/terrarum/modulecomputers/gameitems/ItemHomeComputer.kt index c783cee57..30e04f2eb 100644 --- a/ModuleComputers/src/net/torvald/terrarum/modulecomputers/gameitems/ItemHomeComputer.kt +++ b/ModuleComputers/src/net/torvald/terrarum/modulecomputers/gameitems/ItemHomeComputer.kt @@ -34,10 +34,10 @@ class ItemHomeComputer(originalID: ItemID) : GameItem(originalID) { 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() - 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 } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/BlockMarkerActor.kt b/src/net/torvald/terrarum/gameactors/BlockMarkerActor.kt index b104a053f..b6aefdb9d 100644 --- a/src/net/torvald/terrarum/gameactors/BlockMarkerActor.kt +++ b/src/net/torvald/terrarum/gameactors/BlockMarkerActor.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.spriteanimation.SpriteAnimation import net.torvald.terrarum.App +import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.CommonResourcePool import net.torvald.terrarum.INGAME import net.torvald.terrarum.Terrarum @@ -53,19 +54,22 @@ class BlockMarkerActor : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = Phy if (isVisible) { if (markerMode == MarkerMode.FIXTURE_GHOST) { if (INGAME.actorNowPlaying != null) { - mouseInInteractableRange(INGAME.actorNowPlaying!!) { +// mouseInInteractableRange(INGAME.actorNowPlaying!!) { _, _, _, _ -> + batch.shader = App.shaderGhastlyWhite if (ghost != null) { - batch.color = ghostColour +// batch.color = ghostColour + batch.shader.setUniformf("ghostColour", ghostColour.r, ghostColour.g, ghostColour.b, ghostColour.a) drawSpriteInGoodPosition(ghost!!, batch) } - 0L - } +// 0L +// } } else { batch.shader = App.shaderGhastlyWhite if (ghost != null) { - batch.color = ghostColour +// batch.color = ghostColour + batch.shader.setUniformf("ghostColour", ghostColour.r, ghostColour.g, ghostColour.b, ghostColour.a) drawSpriteInGoodPosition(ghost!!, batch) } } @@ -114,5 +118,6 @@ class BlockMarkerActor : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = Phy fun setGhostColourNone() { ghostColour = Color.WHITE } fun setGhostColourAllow() { ghostColour = Color(-1) } + fun setGhostColourDeny() { ghostColour = Color(0xff8080ff.toInt()) } fun setGhostColourBlock() { ghostColour = Color(0) } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameitems/GameItem.kt b/src/net/torvald/terrarum/gameitems/GameItem.kt index a6158d852..387c73dd0 100644 --- a/src/net/torvald/terrarum/gameitems/GameItem.kt +++ b/src/net/torvald/terrarum/gameitems/GameItem.kt @@ -384,13 +384,13 @@ abstract class GameItem(val originalID: ItemID) : Comparable, Cloneabl * 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 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 */ -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 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 } /** diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index 3a68e7907..abd037123 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -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 else if (itemOnGrip == null) { - mouseInInteractableRange(actor) { - performBarehandAction(actor, delta) + mouseInInteractableRange(actor) { mwx, mwy, mtx, mty -> + performBarehandAction(actor, delta, mwx, mwy, mtx, mty) 0L } } @@ -675,7 +675,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { // scan for the one with non-null UI. // what if there's multiple of such fixtures? whatever, you are supposed to DISALLOW such situation. for (kk in actorsUnderMouse.indices) { - if (mouseInInteractableRange(actor) { + if (mouseInInteractableRange(actor) { _, _, _, _ -> actorsUnderMouse[kk].mainUI?.let { uiOpened = true @@ -1372,7 +1372,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { 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) @@ -1391,8 +1391,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { val punchSize = actor.scale * actor.actorValue.getAsDouble(AVKey.BAREHAND_BASE_DIGSIZE)!! // if there are attackable actor or fixtures - val actorsUnderMouse: List = getActorsAtVicinity(Terrarum.mouseX, Terrarum.mouseY, punchSize / 2.0).sortedBy { - (Terrarum.mouseX - it.hitbox.centeredX).sqr() + (Terrarum.mouseY - it.hitbox.centeredY).sqr() + val actorsUnderMouse: List = getActorsAtVicinity(mwx, mwy, punchSize / 2.0).sortedBy { + (mwx - it.hitbox.centeredX).sqr() + (mwy - it.hitbox.centeredY).sqr() } // sorted by the distance from the mouse // prioritise actors @@ -1407,10 +1407,12 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { // pickup a fixture 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 fixtureItem = ItemCodex.fixtureToItemID(fixture) 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 fixture.flagDespawn() // 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) { val punchBlockSize = punchSize.div(TILE_SIZED).floorToInt() 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) } } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index cfebabf48..171533c6c 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -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]. * @@ -243,24 +261,10 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { // posY: bottom of the blockBox // 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 posY = posY0 - blockBox.height + 1 - // set the position of this actor - 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) { + if (!canSpawnHere(posX0, posY0)) { 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 } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt index dd38b9abc..6874b1aa9 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt @@ -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 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 - val dist = pivot - Terrarum.mouseX // NOTE: order is different from the other function - val dist2 = pivot - (Terrarum.mouseX - ww) + val dist = pivot - mx // NOTE: order is different from the other function + val dist2 = pivot - (mx - ww) 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 pivot = this@FixtureSwingingDoorBase.hitbox.centeredX - val dist = Terrarum.mouseX - pivot // NOTE: order is different from the other function - val dist2 = (Terrarum.mouseX + ww) - pivot + val dist = mx - pivot // NOTE: order is different from the other function + val dist2 = (mx + ww) - pivot 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 { @@ -313,16 +313,16 @@ open class FixtureSwingingDoorBase : FixtureBase { if (mouseUp && Gdx.input.isButtonPressed(App.getConfigInt("config_mousesecondary"))) { INGAME.actorNowPlaying?.let { player -> - mouseInInteractableRange(player) { + mouseInInteractableRange(player) { mx, my, _, _ -> // keep opened/closed as long as the mouse is down if (doorStateTimer != 0f) { oldStateBeforeMouseDown = doorState } if (oldStateBeforeMouseDown == 0) { - if (mouseOnLeftSide()) + if (mouseOnLeftSide(mx, my)) openToLeft(1) - else if (mouseOnRightSide()) + else if (mouseOnRightSide(mx, my)) openToRight(1) } else { diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt index d52a09944..12d18ee7c 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt @@ -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 * for wire items, otherwise you want it to be true. */ - fun blockStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, itemID: ItemID, delta: Float) = mouseInInteractableRange(actor) { - val ingame = Terrarum.ingame!! as TerrarumIngame - val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble()) - val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY) + fun blockStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, itemID: ItemID, delta: Float) = + mouseInInteractableRange(actor) { mwx, mwy, mtx, mty -> + val ingame = Terrarum.ingame!! as TerrarumIngame + val mousePoint = Point2d(mtx.toDouble(), mty.toDouble()) + val mouseTile = Point2i(mtx, mty) - // 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 (h)IntTilewiseHitbox is badly defined - // 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 badly defined + // 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 (h)IntTilewiseHitbox is badly defined + // 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 badly defined - if (gameItem.inventoryCategory == GameItem.Category.BLOCK) { - var ret1 = true - ingame.actorContainerActive.filter { it is ActorWithBody }.forEach { val it = it as ActorWithBody - if ((it is FixtureBase || it.physProp.usePhysics) && it.intTilewiseHitbox.intersects(mousePoint)) - ret1 = false // return is not allowed here + if (gameItem.inventoryCategory == GameItem.Category.BLOCK) { + var ret1 = true + ingame.actorContainerActive.filter { it is ActorWithBody }.forEach { val it = it as ActorWithBody + if ((it is FixtureBase || it.physProp.usePhysics) && it.intTilewiseHitbox.intersects(mousePoint)) + 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) { (Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "" } @@ -126,40 +127,38 @@ object BlockBase { 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 ingame = Terrarum.ingame!! as TerrarumIngame - val mouseTileX = Terrarum.mouseTileX - val mouseTileY = Terrarum.mouseTileY val ww = ingame.world.width if (Gdx.input.isButtonJustPressed(App.getConfigInt("config_mouseprimary")) || - !isNeighbouring(ww, mouseTileX, mouseTileY, oldTileX, oldTileY)) { - initialMouseDownTileX = mouseTileX - initialMouseDownTileY = mouseTileY - oldTileX = mouseTileX - oldTileY = mouseTileY + !isNeighbouring(ww, mtx, mty, oldTileX, oldTileY)) { + initialMouseDownTileX = mtx + initialMouseDownTileY = mty + oldTileX = mtx + oldTileY = mty } - val thisTileWires = ingame.world.getAllWiresFrom(mouseTileX, mouseTileY) + val thisTileWires = ingame.world.getAllWiresFrom(mtx, mty) 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 thisTileOccupied = thisTileWires.first?.searchFor(itemID) != null val oldTileOccupied = oldTileWires.first?.searchFor(itemID) != null - val oldToNewVector = if (mouseTileX == ww - 1 && oldTileX == 0) 4 - else if (mouseTileX == 0 && oldTileX == ww - 1) 1 - else if (mouseTileX - oldTileX == 1) 1 - else if (mouseTileX - oldTileX == -1) 4 - else if (mouseTileY - oldTileY == 1) 2 - else if (mouseTileY - oldTileY == -1) 8 + val oldToNewVector = if (mtx == ww - 1 && oldTileX == 0) 4 + else if (mtx == 0 && oldTileX == ww - 1) 1 + else if (mtx - oldTileX == 1) 1 + else if (mtx - oldTileX == -1) 4 + else if (mty - oldTileY == 1) 2 + else if (mty - oldTileY == -1) 8 else 0 // if xy == oxy, the vector will be 0 val connectedEachOther = wireNodesConnectedEachOther(oldToNewVector, thisTileWireCnx, oldTileWireCnx) - val thisTileWasDraggedOn = initialMouseDownTileX != mouseTileX || initialMouseDownTileY != mouseTileY + val thisTileWasDraggedOn = initialMouseDownTileX != mtx || initialMouseDownTileY != mty var ret = -1L @@ -176,7 +175,7 @@ object BlockBase { if (!thisTileWasDraggedOn) { if (thisTileOccupied) return@mouseInInteractableRange -1 else { - placeWirePieceTo(ingame.world, itemID, mouseTileX, mouseTileY) + placeWirePieceTo(ingame.world, itemID, mtx, mty) ret = 1 } } @@ -185,18 +184,18 @@ object BlockBase { ret -1 } else if (thisTileOccupied && oldTileOccupied) { - setConnectivity(ingame.world, oldToNewVector, itemID, mouseTileX, mouseTileY, oldTileX, oldTileY) + setConnectivity(ingame.world, oldToNewVector, itemID, mtx, mty, oldTileX, oldTileY) ret = 0 } else { - placeWirePieceTo(ingame.world, itemID, mouseTileX, mouseTileY) - setConnectivity(ingame.world, oldToNewVector, itemID, mouseTileX, mouseTileY, oldTileX, oldTileY) + placeWirePieceTo(ingame.world, itemID, mtx, mty) + setConnectivity(ingame.world, oldToNewVector, itemID, mtx, mty, oldTileX, oldTileY) ret = 1 } } - oldTileX = mouseTileX - oldTileY = mouseTileY + oldTileX = mtx + oldTileY = mty ret } diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/FixtureItemBase.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/FixtureItemBase.kt index cfdfe043e..8d7372c1e 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/FixtureItemBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/FixtureItemBase.kt @@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameitems import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.terrarum.* +import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.ItemID @@ -67,10 +68,20 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G (INGAME as TerrarumIngame).blockMarkingActor.let { - it.setGhost(ghostItem.get()) + val item = ghostItem.get() + + it.setGhost(item) it.update(delta) 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 - 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 } diff --git a/src/shaders/ghastlywhite.frag b/src/shaders/ghastlywhite.frag index 652d643cb..845582ed4 100644 --- a/src/shaders/ghastlywhite.frag +++ b/src/shaders/ghastlywhite.frag @@ -3,6 +3,8 @@ in vec4 v_color; in vec2 v_texCoords; uniform sampler2D u_texture; +uniform vec4 ghostColour = vec4(1.0); + const vec2 boolean = vec2(0.0, 1.0); const vec4 desaturate = vec4(0.2126, 0.7152, 0.0722, 0.0); out vec4 fragColor; @@ -11,6 +13,5 @@ void main(void) { vec4 incolour = texture(u_texture, v_texCoords); float lum = dot(incolour * desaturate, boolean.yyyx) * 0.5 + 0.5; -// fragColor = v_color * (vec4(lum) * boolean.yyyx + incolour * boolean.xxxy); - fragColor = v_color * fma(vec4(lum), boolean.yyyx, incolour * boolean.xxxy); + fragColor = ghostColour * fma(vec4(lum), boolean.yyyx, incolour * boolean.xxxy); } \ No newline at end of file