mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
renderer is updated but wire pieces have some bugs on laying wire to the world
This commit is contained in:
@@ -38,7 +38,7 @@ class WireActor : ActorWithBody {
|
|||||||
/**
|
/**
|
||||||
* @param itemID must start with "wire@"
|
* @param itemID must start with "wire@"
|
||||||
*/
|
*/
|
||||||
fun setWire(itemID: ItemID, worldX: Int, worldY: Int) {
|
fun setWire(itemID: ItemID, worldX: Int, worldY: Int, cnx: Int) {
|
||||||
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, 0)
|
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, 0)
|
||||||
|
|
||||||
if (wireID != itemID) {
|
if (wireID != itemID) {
|
||||||
@@ -57,15 +57,7 @@ class WireActor : ActorWithBody {
|
|||||||
setPosition((worldX + 0.5) * TILE_SIZE, (worldY + 1.0) * TILE_SIZE - 1.0) // what the fuck?
|
setPosition((worldX + 0.5) * TILE_SIZE, (worldY + 1.0) * TILE_SIZE - 1.0) // what the fuck?
|
||||||
|
|
||||||
(sprite as SheetSpriteAnimation).currentRow = 0
|
(sprite as SheetSpriteAnimation).currentRow = 0
|
||||||
|
(sprite as SheetSpriteAnimation).currentFrame = cnx
|
||||||
val nearbyTiles = getNearbyTilesPos(worldX, worldY).map { world!!.getAllWiresFrom(it.x, it.y) }
|
|
||||||
var ret = 0
|
|
||||||
for (i in 0..3) {
|
|
||||||
if (nearbyTiles[i]?.contains(itemID) == true) {
|
|
||||||
ret = ret or (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(sprite as SheetSpriteAnimation).currentFrame = ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNearbyTilesPos(x: Int, y: Int): Array<Point2i> {
|
private fun getNearbyTilesPos(x: Int, y: Int): Array<Point2i> {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import net.torvald.terrarum.App.printdbg
|
|||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.blockproperties.Fluid
|
import net.torvald.terrarum.blockproperties.Fluid
|
||||||
import net.torvald.terrarum.gameactors.ActorID
|
import net.torvald.terrarum.gameactors.ActorID
|
||||||
import net.torvald.terrarum.gameactors.WireActor
|
|
||||||
import net.torvald.terrarum.gameitems.ItemID
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
import net.torvald.terrarum.itemproperties.ItemRemapTable
|
import net.torvald.terrarum.itemproperties.ItemRemapTable
|
||||||
import net.torvald.terrarum.itemproperties.ItemTable
|
import net.torvald.terrarum.itemproperties.ItemTable
|
||||||
@@ -355,7 +354,7 @@ open class GameWorld() : Disposable {
|
|||||||
Terrarum.ingame?.queueWireChangedEvent(tile, true, x, y)
|
Terrarum.ingame?.queueWireChangedEvent(tile, true, x, y)
|
||||||
Terrarum.ingame?.modified(LandUtil.LAYER_WIRE, x, y)
|
Terrarum.ingame?.modified(LandUtil.LAYER_WIRE, x, y)
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
// figure out wiring graphs
|
// figure out wiring graphs
|
||||||
val matchingNeighbours = WireActor.WIRE_NEARBY.mapIndexed { index, (tx, ty) ->
|
val matchingNeighbours = WireActor.WIRE_NEARBY.mapIndexed { index, (tx, ty) ->
|
||||||
(getAllWiresFrom(x + tx, y + ty)?.contains(tile) == true).toInt() shl index
|
(getAllWiresFrom(x + tx, y + ty)?.contains(tile) == true).toInt() shl index
|
||||||
@@ -369,7 +368,7 @@ open class GameWorld() : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wiringGraph[blockAddr]!!.remove(tile)
|
wiringGraph[blockAddr]!!.remove(tile)
|
||||||
wirings[blockAddr]!!.ws.remove(tile)
|
wirings[blockAddr]!!.ws.remove(tile)*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,14 +469,14 @@ open class GameWorld() : Disposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllWiresFrom(x: Int, y: Int): SortedArrayList<ItemID>? {
|
fun getAllWiresFrom(x: Int, y: Int): Pair<SortedArrayList<ItemID>?, WiringGraphMap?> {
|
||||||
val (x, y) = coerceXY(x, y)
|
val (x, y) = coerceXY(x, y)
|
||||||
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
||||||
return getAllWiresFrom(blockAddr)
|
return getAllWiresFrom(blockAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllWiresFrom(blockAddr: BlockAddress): SortedArrayList<ItemID>? {
|
fun getAllWiresFrom(blockAddr: BlockAddress): Pair<SortedArrayList<ItemID>?, WiringGraphMap?> {
|
||||||
return wirings[blockAddr]?.ws
|
return wirings[blockAddr]?.ws to wiringGraph[blockAddr]
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTileFrom(mode: Int, x: Int, y: Int): ItemID {
|
fun getTileFrom(mode: Int, x: Int, y: Int): ItemID {
|
||||||
|
|||||||
@@ -903,10 +903,13 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
for (y in for_y_start..for_y_end) {
|
for (y in for_y_start..for_y_end) {
|
||||||
for (x in for_x_start..for_x_end) {
|
for (x in for_x_start..for_x_end) {
|
||||||
if (wiringCounter >= maxRenderableWires) break
|
if (wiringCounter >= maxRenderableWires) break
|
||||||
world.getAllWiresFrom(x, y)?.forEach {
|
|
||||||
|
val (wires, nodes) = world.getAllWiresFrom(x, y)
|
||||||
|
|
||||||
|
wires?.forEach {
|
||||||
val wireActor = wireActorsContainer[wiringCounter]
|
val wireActor = wireActorsContainer[wiringCounter]
|
||||||
|
|
||||||
wireActor.setWire(it, x, y)
|
wireActor.setWire(it, x, y, nodes!![it]!!.cnx)
|
||||||
|
|
||||||
if (WireCodex[it].renderClass == selectedWireRenderClass || selectedWireRenderClass == "wire_render_all") {
|
if (WireCodex[it].renderClass == selectedWireRenderClass || selectedWireRenderClass == "wire_render_all") {
|
||||||
wireActor.renderOrder = Actor.RenderOrder.OVERLAY
|
wireActor.renderOrder = Actor.RenderOrder.OVERLAY
|
||||||
|
|||||||
@@ -134,8 +134,8 @@ object BlockBase {
|
|||||||
val thisTileWireCnx = ingame.world.getWireGraphOf(mouseTileX, mouseTileY, itemID)
|
val thisTileWireCnx = ingame.world.getWireGraphOf(mouseTileX, mouseTileY, itemID)
|
||||||
val oldTileWireCnx = ingame.world.getWireGraphOf(oldTileX, oldTileY, itemID)
|
val oldTileWireCnx = ingame.world.getWireGraphOf(oldTileX, oldTileY, itemID)
|
||||||
|
|
||||||
val thisTileOccupied = thisTileWires?.searchFor(itemID) != null
|
val thisTileOccupied = thisTileWires.first?.searchFor(itemID) != null
|
||||||
val oldTileOccupied = oldTileWires?.searchFor(itemID) != null
|
val oldTileOccupied = oldTileWires.first?.searchFor(itemID) != null
|
||||||
val connectedEachOther = connectedEachOther(thisTileWireCnx, oldTileWireCnx)
|
val connectedEachOther = connectedEachOther(thisTileWireCnx, oldTileWireCnx)
|
||||||
val thisTileWasDraggedOn = initialMouseDownTileX != mouseTileX || initialMouseDownTileY != mouseTileY
|
val thisTileWasDraggedOn = initialMouseDownTileX != mouseTileX || initialMouseDownTileY != mouseTileY
|
||||||
|
|
||||||
|
|||||||
@@ -39,9 +39,11 @@ class WireCutterAll(originalID: ItemID) : GameItem(originalID) {
|
|||||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) {
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) {
|
||||||
val ingame = Terrarum.ingame!! as TerrarumIngame
|
val ingame = Terrarum.ingame!! as TerrarumIngame
|
||||||
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
||||||
val wires = ingame.world.getAllWiresFrom(mouseTile.x, mouseTile.y)?.cloneToList()
|
|
||||||
|
|
||||||
wires?.forEach {
|
val wireNet = ingame.world.getAllWiresFrom(mouseTile.x, mouseTile.y)
|
||||||
|
val wireItems = wireNet.first?.cloneToList()
|
||||||
|
|
||||||
|
wireItems?.forEach {
|
||||||
ingame.world.removeTileWire(mouseTile.x, mouseTile.y, it, false)
|
ingame.world.removeTileWire(mouseTile.x, mouseTile.y, it, false)
|
||||||
ingame.queueActorAddition(DroppedItem(it, mouseTile.x * TILE_SIZED, mouseTile.y * TILE_SIZED))
|
ingame.queueActorAddition(DroppedItem(it, mouseTile.x * TILE_SIZED, mouseTile.y * TILE_SIZED))
|
||||||
} ?: return@mouseInInteractableRange -1L
|
} ?: return@mouseInInteractableRange -1L
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
|||||||
val tileNum = it.getTileFromTerrain(mouseTileX, mouseTileY)
|
val tileNum = it.getTileFromTerrain(mouseTileX, mouseTileY)
|
||||||
val wires = it.getAllWiresFrom(mouseTileX, mouseTileY)
|
val wires = it.getAllWiresFrom(mouseTileX, mouseTileY)
|
||||||
val fluid = it.getFluid(mouseTileX, mouseTileY)
|
val fluid = it.getFluid(mouseTileX, mouseTileY)
|
||||||
val wireCount = wires?.size?.toString() ?: "no"
|
val wireCount = wires.first?.size?.toString() ?: "no"
|
||||||
|
|
||||||
App.fontSmallNumbers.draw(batch, "$ccO$TERRAIN$ccG$tileNum", gap + 7f*(tileCursX + 3), line(tileCursY))
|
App.fontSmallNumbers.draw(batch, "$ccO$TERRAIN$ccG$tileNum", gap + 7f*(tileCursX + 3), line(tileCursY))
|
||||||
App.fontSmallNumbers.draw(batch, "$ccO$WALL$ccG$wallNum", gap + 7f*(tileCursX + 3), line(tileCursY + 1))
|
App.fontSmallNumbers.draw(batch, "$ccO$WALL$ccG$wallNum", gap + 7f*(tileCursX + 3), line(tileCursY + 1))
|
||||||
|
|||||||
Reference in New Issue
Block a user