mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 04:41:51 +09:00
fixed a bug where wire graphs would not laid down correctly
This commit is contained in:
@@ -24,6 +24,7 @@ import net.torvald.terrarum.concurrent.ThreadExecutor;
|
||||
import net.torvald.terrarum.controller.GdxControllerAdapter;
|
||||
import net.torvald.terrarum.controller.TerrarumController;
|
||||
import net.torvald.terrarum.controller.XinputControllerAdapter;
|
||||
import net.torvald.terrarum.gameactors.*;
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler;
|
||||
import net.torvald.terrarum.gameworld.GameWorld;
|
||||
import net.torvald.terrarum.imagefont.TinyAlphNum;
|
||||
@@ -46,6 +47,7 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
|
||||
import static net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED;
|
||||
import static net.torvald.terrarum.TerrarumKt.gdxClearAndSetBlend;
|
||||
import static net.torvald.terrarum.TerrarumKt.printStackTrace;
|
||||
|
||||
@@ -355,6 +357,7 @@ public class AppLoader implements ApplicationListener {
|
||||
glInfo.create();
|
||||
|
||||
CommonResourcePool.INSTANCE.addToLoadingList("blockmarkings_common", () -> new TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16, 0, 0, 0, 0, false));
|
||||
CommonResourcePool.INSTANCE.addToLoadingList("blockmarking_actor", () -> new BlockMarkerActor());
|
||||
|
||||
newTempFile("wenquanyi.tga"); // temp file required by the font
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.utils.Queue
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameactors.BlockMarkerActor
|
||||
import net.torvald.terrarum.gameitem.ItemID
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
@@ -78,6 +79,14 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
||||
|
||||
override fun show() {
|
||||
// the very basic show() implementation
|
||||
|
||||
// add blockmarking_actor into the actorlist
|
||||
(CommonResourcePool.get("blockmarking_actor") as BlockMarkerActor).let {
|
||||
it.isVisible = false // make sure the actor is invisible on new instance
|
||||
try { addNewActor(it) } catch (e: Error) {}
|
||||
}
|
||||
|
||||
|
||||
gameInitialised = true
|
||||
}
|
||||
|
||||
|
||||
@@ -289,7 +289,7 @@ object Terrarum : Disposable {
|
||||
fun generateUniqueReferenceID(renderOrder: Actor.RenderOrder): ActorID {
|
||||
fun hasCollision(value: ActorID) =
|
||||
try {
|
||||
Terrarum.ingame!!.theGameHasActor(value) ||
|
||||
Terrarum.ingame?.theGameHasActor(value) == true ||
|
||||
value < ItemCodex.ACTORID_MIN ||
|
||||
value !in when (renderOrder) {
|
||||
Actor.RenderOrder.BEHIND -> Actor.RANGE_BEHIND
|
||||
|
||||
@@ -40,7 +40,7 @@ abstract class Actor(val renderOrder: RenderOrder) : Comparable<Actor>, Runnable
|
||||
* Valid RefID is equal to or greater than 16777216.
|
||||
* @return Reference ID. (16777216-0x7FFF_FFFF)
|
||||
*/
|
||||
open var referenceID: ActorID = Terrarum.generateUniqueReferenceID(renderOrder) // once this was nullable without initialiser. If you're going to revert to that, add the reason why this should be nullable.
|
||||
open var referenceID: ActorID = Terrarum.generateUniqueReferenceID(renderOrder) // in old time this was nullable without initialiser. If you're going to revert to that, add the reason why this should be nullable.
|
||||
var actorValue = ActorValue(this) // FIXME cyclic reference on GSON
|
||||
@Volatile var flagDespawn = false
|
||||
|
||||
|
||||
49
src/net/torvald/terrarum/gameactors/BlockMarkerActor.kt
Normal file
49
src/net/torvald/terrarum/gameactors/BlockMarkerActor.kt
Normal file
@@ -0,0 +1,49 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.ReferencingRanges
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
class BlockMarkerActor : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = PhysProperties.MOBILE_OBJECT) {
|
||||
|
||||
override var referenceID: ActorID = 1048575 // custom refID
|
||||
override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0)
|
||||
|
||||
var color = Color.YELLOW
|
||||
var shape = 0
|
||||
|
||||
private val blockMarkings: TextureRegionPack
|
||||
get() = CommonResourcePool.getAsTextureRegionPack("blockmarkings_common")
|
||||
|
||||
init {
|
||||
this.referenceID = ReferencingRanges.ACTORS_OVERLAY.last
|
||||
this.isVisible = false
|
||||
}
|
||||
|
||||
override fun drawBody(batch: SpriteBatch) {
|
||||
if (isVisible) {
|
||||
batch.color = color
|
||||
batch.draw(blockMarkings.get(shape, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
|
||||
}
|
||||
}
|
||||
|
||||
override fun drawGlow(batch: SpriteBatch) { }
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
override fun update(delta: Float) {
|
||||
if (isVisible) {
|
||||
hitbox.setPosition(
|
||||
Terrarum.mouseTileX * 16.0,
|
||||
Terrarum.mouseTileY * 16.0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActorValueChange(key: String, value: Any?) { }
|
||||
|
||||
}
|
||||
@@ -79,6 +79,7 @@ open class GameWorld : Disposable {
|
||||
|
||||
private val wiringGraph = HashMap<BlockAddress, HashMap<ItemID, WiringSimCell>>()
|
||||
private val WIRE_POS_MAP = byteArrayOf(1,2,4,8)
|
||||
private val WIRE_ANTIPOS_MAP = byteArrayOf(4,8,1,2)
|
||||
|
||||
/**
|
||||
* Used by the renderer. When wirings are updated, `wirings` and this properties must be synchronised.
|
||||
@@ -341,7 +342,7 @@ open class GameWorld : Disposable {
|
||||
if (matchingNeighbours and WIRE_POS_MAP[i] > 0) {
|
||||
val (tx, ty) = WireActor.WIRE_NEARBY[i]
|
||||
val old = getWireGraphOf(x + tx, y + ty, tile) ?: 0
|
||||
setWireGraphOf(x + tx, y + ty, tile, old or WIRE_POS_MAP[i])
|
||||
setWireGraphOf(x + tx, y + ty, tile, old or WIRE_ANTIPOS_MAP[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameitems
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.blockproperties.WireCodex
|
||||
import net.torvald.terrarum.gameactors.BlockMarkerActor
|
||||
import net.torvald.terrarum.gameitem.GameItem
|
||||
import net.torvald.terrarum.gameitem.ItemID
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
@@ -30,10 +32,15 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
|
||||
}
|
||||
|
||||
private val sb = StringBuilder()
|
||||
private val blockMarker = CommonResourcePool.get("blockmarking_actor") as BlockMarkerActor
|
||||
|
||||
override fun effectWhenEquipped(delta: Float) {
|
||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "wire_render_all"
|
||||
|
||||
blockMarker.shape = 3
|
||||
blockMarker.color = Color.YELLOW
|
||||
blockMarker.isVisible = true
|
||||
blockMarker.update(delta)
|
||||
|
||||
val mx = Terrarum.mouseTileX
|
||||
val my = Terrarum.mouseTileY
|
||||
@@ -65,5 +72,6 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
|
||||
override fun effectOnUnequip(delta: Float) {
|
||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
||||
(Terrarum.ingame!! as TerrarumIngame).setTooltipMessage(null)
|
||||
blockMarker.isVisible = false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user