mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 21:14:04 +09:00
wire ports view
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.WireEmissionType
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-03-05.
|
||||
@@ -18,15 +23,6 @@ interface InternalActor {
|
||||
*/
|
||||
class WireActor : ActorWithBody, NoSerialise, InternalActor {
|
||||
|
||||
companion object {
|
||||
val WIRE_NEARBY = arrayOf(
|
||||
(+1 to 0), // tileR
|
||||
(0 to +1), // tileB
|
||||
(-1 to 0), // tileL
|
||||
(0 to -1) // tileT
|
||||
)
|
||||
}
|
||||
|
||||
private constructor()
|
||||
|
||||
constructor(id: ActorID) : super(RenderOrder.OVERLAY, PhysProperties.IMMOBILE(), id)
|
||||
@@ -39,7 +35,6 @@ class WireActor : ActorWithBody, NoSerialise, InternalActor {
|
||||
private var worldX = 0
|
||||
private var worldY = 0
|
||||
|
||||
|
||||
/**
|
||||
* @param itemID must start with "wire@"
|
||||
*/
|
||||
@@ -65,34 +60,77 @@ class WireActor : ActorWithBody, NoSerialise, InternalActor {
|
||||
(sprite as SheetSpriteAnimation).currentFrame = cnx
|
||||
}
|
||||
|
||||
private fun getNearbyTilesPos(x: Int, y: Int): Array<Point2i> {
|
||||
return arrayOf(
|
||||
Point2i(x + 1, y),
|
||||
Point2i(x, y + 1),
|
||||
Point2i(x - 1, y),
|
||||
Point2i(x, y - 1)
|
||||
)
|
||||
override fun updateImpl(delta: Float) {
|
||||
}
|
||||
|
||||
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
|
||||
if (isVisible && sprite != null) {
|
||||
(sprite as SheetSpriteAnimation).currentRow = (world?.getWireEmitStateOf(worldX, worldY, wireID)?.isNotZero == true).toInt()
|
||||
BlendMode.resolve(drawMode, batch)
|
||||
drawSpriteInGoodPosition(frameDelta, sprite!!, batch)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-03-07.
|
||||
*/
|
||||
class WirePortActor : ActorWithBody, NoSerialise, InternalActor {
|
||||
|
||||
|
||||
private constructor()
|
||||
|
||||
constructor(id: ActorID) : super(RenderOrder.OVERLAY, PhysProperties.IMMOBILE(), id)
|
||||
|
||||
init {
|
||||
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, 0)
|
||||
renderOrder = RenderOrder.OVERLAY
|
||||
}
|
||||
|
||||
private var portID: WireEmissionType = ""
|
||||
private var worldX = 0
|
||||
private var worldY = 0
|
||||
|
||||
/**
|
||||
*/
|
||||
fun setPort(emissionType: WireEmissionType, worldX: Int, worldY: Int) {
|
||||
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, 0)
|
||||
|
||||
if (portID != emissionType) {
|
||||
WireCodex.getWirePortSpritesheet(emissionType)?.let { (sheet, x, y) ->
|
||||
if (sprite == null) {
|
||||
makeNewSprite(sheet).let {
|
||||
it.delays = floatArrayOf(Float.POSITIVE_INFINITY,Float.POSITIVE_INFINITY,Float.POSITIVE_INFINITY,Float.POSITIVE_INFINITY)
|
||||
it.setRowsAndFrames(1, 16)
|
||||
}
|
||||
}
|
||||
else {
|
||||
(sprite as SheetSpriteAnimation).let {
|
||||
it.setSpriteImage(sheet)
|
||||
}
|
||||
}
|
||||
|
||||
(sprite as SheetSpriteAnimation).let {
|
||||
it.currentFrame = x
|
||||
it.currentRow = y
|
||||
}
|
||||
|
||||
portID = emissionType
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.worldX = worldX
|
||||
this.worldY = worldY
|
||||
|
||||
setPosition((worldX + 0.5) * TILE_SIZE, (worldY + 1.0) * TILE_SIZE - 1.0) // what the fuck?
|
||||
}
|
||||
|
||||
override fun updateImpl(delta: Float) {
|
||||
}
|
||||
|
||||
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
|
||||
if (isVisible && sprite != null) {
|
||||
if (WireCodex[wireID].accepts == "digital_3bits") {
|
||||
// "digital_3bits" must come right after three wires it bundles
|
||||
val rootID = wireID.substringBefore(':') + ":"
|
||||
var row = 0
|
||||
(WireCodex[wireID].numericID - 3 .. WireCodex[wireID].numericID - 1).forEachIndexed { index, it ->
|
||||
val itemID = rootID + it
|
||||
row = row or ((world?.getWireEmitStateOf(worldX, worldY, itemID)?.isNotZero == true).toInt() shl index)
|
||||
}
|
||||
(sprite as SheetSpriteAnimation).currentRow = row
|
||||
}
|
||||
else {
|
||||
(sprite as SheetSpriteAnimation).currentRow = (world?.getWireEmitStateOf(worldX, worldY, wireID)?.isNotZero == true).toInt()
|
||||
}
|
||||
|
||||
if (isVisible && sprite != null && (Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass.isNotBlank()) {
|
||||
BlendMode.resolve(drawMode, batch)
|
||||
drawSpriteInGoodPosition(frameDelta, sprite!!, batch)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user