This commit is contained in:
minjaesong
2025-03-30 18:07:02 +09:00
parent 0c35faa548
commit 51da0612d2
15 changed files with 96 additions and 36 deletions

View File

@@ -12,6 +12,7 @@ class EntryPoint : ModuleEntryPoint() {
override fun invoke() {
ModMgr.GameItemLoader.invoke(moduleName)
ModMgr.GameBlockLoader.invoke(moduleName)
ModMgr.GameWatchdogLoader.register(moduleName, NetFrameWatchdog())
println("[${moduleName[0].toUpperCase()}${moduleName.substring(1)}] Dirtboard(tm) go drrrrr")
}

View File

@@ -1,14 +1,10 @@
package net.torvald.terrarum.modulecomputers.gameactors
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
import net.torvald.terrarum.gameactors.drawBodyInGoodPosition
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.BlockBox
import net.torvald.terrarum.modulebasegame.gameactors.Electric
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
@@ -16,7 +12,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
class FixtureComputerConsole : Electric {
@Transient override val spawnNeedsFloor = true
@Transient override val spawnNeedsStableFloor = true
@Transient override val spawnNeedsWall = false
constructor() : super(
@@ -24,27 +20,31 @@ class FixtureComputerConsole : Electric {
nameFun = { Lang["ITEM_COMPUTER_CONSOLE"] }
)
@Transient lateinit var itemImageSheet: TextureRegionPack
init {
val itemImage = FixtureItemBase.getItemImageFromSingleImage("dwarventech", "sprites/fixtures/computer_operator_terminal.tga")
makeNewSprite(TextureRegionPack(itemImage.texture, 2*TILE_SIZE, 2*TILE_SIZE)).let {
it.setRowsAndFrames(1,1)
}
}
}
/**
* Created by minjaesong on 2025-03-30.
*/
class FixtureComputerProcessor : Electric {
@Transient override val spawnNeedsStableFloor = true
@Transient override val spawnNeedsWall = false
constructor() : super(
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 2, 3),
nameFun = { Lang["ITEM_COMPUTER_PROCESSOR"] }
)
init {
itemImageSheet = CommonResourcePool.getOrPut("spritesheet:dwarventech/sprites/fixtures/computers.tga") {
TextureRegionPack(ModMgr.getGdxFile("dwarventech", "sprites/fixtures/computers.tga"), TILE_SIZE, TILE_SIZE)
} as TextureRegionPack
}
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
super.drawBody(frameDelta, batch)
val sx = hitbox.startX.toFloat()
val sy = hitbox.startY.toFloat()
drawBodyInGoodPosition(sx, sy) { x, y ->
batch.draw(itemImageSheet.get(0, 1), x, y)
batch.draw(itemImageSheet.get(1, 1), x + TILE_SIZEF, y)
batch.draw(itemImageSheet.get(0, 2), x, y + TILE_SIZEF)
batch.draw(itemImageSheet.get(1, 2), x + TILE_SIZEF, y + TILE_SIZEF)
val itemImage = FixtureItemBase.getItemImageFromSingleImage("dwarventech", "sprites/fixtures/computer_cpu.tga")
makeNewSprite(TextureRegionPack(itemImage.texture, 2*TILE_SIZE, 3*TILE_SIZE)).let {
it.setRowsAndFrames(1,1)
}
}
}

View File

@@ -1,7 +1,5 @@
package net.torvald.terrarum.modulecomputers.gameitems
import net.torvald.terrarum.TerrarumAppConfiguration
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
@@ -13,11 +11,29 @@ class ItemComputerConsole(originalID: ItemID) : FixtureItemBase(originalID, "net
override var dynamicID: ItemID = originalID
override var baseMass = 80.0
override val canBeDynamic = false
override val materialId = ""
override val materialId = "STAL"
init {
// itemImage = FixtureItemBase.getItemImageFromSheet("dwarventech", "sprites/fixtures/desktop_computer.tga", TILE_SIZE, TILE_SIZE)
itemImage = FixtureItemBase.getItemImageFromSingleImage("dwarventech", "sprites/fixtures/computer_operator_terminal.tga")
}
override var baseToolSize: Double? = baseMass
override var originalName = "ITEM_COMPUTER_CONSOLE"
}
/**
* Created by minjaesong on 2025-03-30.
*/
class ItemComputerProcessor(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulecomputers.gameactors.FixtureComputerProcessor") {
override var dynamicID: ItemID = originalID
override var baseMass = 200.0
override val canBeDynamic = false
override val materialId = "STAL"
init {
itemImage = FixtureItemBase.getItemImageFromSingleImage("dwarventech", "sprites/fixtures/computer_cpu.tga")
}
override var baseToolSize: Double? = baseMass
override var originalName = "ITEM_COMPUTER_PROCESSOR"
}

View File

@@ -1,4 +1,5 @@
id;classname;tags
#1;net.torvald.terrarum.modulecomputers.gameitems.ItemWearableWorldRadar;
#2;net.torvald.terrarum.modulecomputers.gameitems.ItemHomeComputer;
16;net.torvald.terrarum.modulecomputers.gameitems.ItemComputerConsole;TAGS
256;net.torvald.terrarum.modulecomputers.gameitems.ItemComputerConsole;
257;net.torvald.terrarum.modulecomputers.gameitems.ItemComputerProcessor;
1 id classname tags
2 #1 net.torvald.terrarum.modulecomputers.gameitems.ItemWearableWorldRadar
3 #2 net.torvald.terrarum.modulecomputers.gameitems.ItemHomeComputer
4 16 256 net.torvald.terrarum.modulecomputers.gameitems.ItemComputerConsole TAGS
5 257 net.torvald.terrarum.modulecomputers.gameitems.ItemComputerProcessor

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -27,7 +27,8 @@ typealias BlockBoxIndex = Int
open class FixtureBase : ActorWithBody, CuedByTerrainChange {
@Transient open val spawnNeedsWall: Boolean = false
@Transient open val spawnNeedsFloor: Boolean = true
@Transient open val spawnNeedsFloor: Boolean = true // any floor, including platforms
@Transient open val spawnNeedsStableFloor: Boolean = false // solid tiles only (no platforms)
@Transient open val spawnNeedsCeiling: Boolean = false
// if both spawnNeedsWall and spawnNeedsFloor are true, the condition will be interpreted as OR-condition
@@ -166,6 +167,14 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
return blockprop.isSolid || blockprop.isPlatform
}
/**
* Condition for (if the tile is solid) is always implied regardless of this function. See [canSpawnHere0]
*/
open fun canSpawnOnThisFloorStable(itemID: ItemID): Boolean {
val blockprop = BlockCodex[itemID]
return blockprop.isSolid
}
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
@@ -215,21 +224,24 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
}
// check for floors, if spawnNeedsFloor == true
if (spawnNeedsFloor || spawnNeedsCeiling) {
val yOff = if (spawnNeedsFloor) 1 else -1
if (spawnNeedsStableFloor || spawnNeedsFloor || spawnNeedsCeiling) {
val yOff = if (spawnNeedsStableFloor || spawnNeedsFloor) 1 else -1
cannotSpawnNoFloor = everyBlockboxPos.filter {
if (spawnNeedsFloor)
if (spawnNeedsStableFloor || spawnNeedsFloor)
it.second == posY - oy + blockBox.height - 1
else
it.second == posY - oy
}.any { (x, y) ->
world!!.getTileFromTerrain(x, y + yOff).let {
if (spawnNeedsStableFloor || spawnNeedsCeiling)
!canSpawnOnThisFloorStable(it)
else
!canSpawnOnThisFloor(it)
}
}
}
if (spawnNeedsWall && (spawnNeedsFloor || spawnNeedsCeiling))
if (spawnNeedsWall && (spawnNeedsStableFloor || spawnNeedsFloor || spawnNeedsCeiling))
cannotSpawn = cannotSpawn or (cannotSpawnNoWall && cannotSpawnNoFloor)
else if (spawnNeedsFloor || spawnNeedsCeiling)
cannotSpawn = cannotSpawn or cannotSpawnNoFloor