mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
workign on the modloader in progress
This commit is contained in:
17
ModuleComputers/ModuleComputers.iml
Normal file
17
ModuleComputers/ModuleComputers.iml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="ModuleComputersLib" level="project" />
|
||||
<orderEntry type="module" module-name="terrarum.terrarum" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
<orderEntry type="library" name="com.badlogicgames.gdx:gdx-backend-lwjgl3:1.10.0" level="project" />
|
||||
<orderEntry type="library" name="com.badlogicgames.gdx:gdx:1.10.0" level="project" />
|
||||
<orderEntry type="library" name="graalvm-js-21.1.0 and graalvm-js-scriptengine-21.1.0" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
BIN
ModuleComputers/lib/TerranVirtualDisk.jar
Normal file
BIN
ModuleComputers/lib/TerranVirtualDisk.jar
Normal file
Binary file not shown.
BIN
ModuleComputers/lib/TerrarumTSVM.jar
Normal file
BIN
ModuleComputers/lib/TerrarumTSVM.jar
Normal file
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
package net.torvald.terrarum.modulecomputers
|
||||
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.ModuleEntryPoint
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-12-03.
|
||||
*/
|
||||
class EntryPoint : ModuleEntryPoint() {
|
||||
|
||||
private val moduleName = "dwarventech"
|
||||
|
||||
override fun invoke() {
|
||||
ModMgr.GameItemLoader.invoke(moduleName)
|
||||
println("[${moduleName[0].uppercase()}${moduleName.substring(1)}] Dirtboard(tm) go drrrrr")
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package net.torvald.terrarum.modulecomputers.gameitems
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulecomputers.tsvmperipheral.WorldRadar
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.tsvm.PeripheralEntry
|
||||
import net.torvald.tsvm.TheRealWorld
|
||||
import net.torvald.tsvm.VM
|
||||
import net.torvald.tsvm.peripheral.ExtDisp
|
||||
import net.torvald.tsvm.peripheral.VMProgramRom
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-12-03.
|
||||
*/
|
||||
class ItemWearableWorldRadar(originalID: String) : GameItem(originalID) {
|
||||
|
||||
override var dynamicID: ItemID = originalID
|
||||
override val originalName = "ITEM_COMPUTER_DIRTBOARD_FAKETM"
|
||||
override var baseMass = 2.0
|
||||
override var stackable = true
|
||||
override var inventoryCategory = Category.TOOL
|
||||
override val isUnique = false
|
||||
override val isDynamic = true
|
||||
override val material = Material()
|
||||
override val itemImage: TextureRegion
|
||||
get() = CommonResourcePool.getAsTextureRegion("basegame-sprites-fixtures-signal_source.tga")
|
||||
override var baseToolSize: Double? = baseMass
|
||||
|
||||
|
||||
val vm = VM(32768, TheRealWorld(), arrayOf(
|
||||
VMProgramRom(ModMgr.getPath("dwarventech", "bios/pipboot.rom")),
|
||||
VMProgramRom(ModMgr.getPath("dwarventech", "bios/pipcode.bas"))
|
||||
))
|
||||
val ui = WearableWorldRadarUI(vm)
|
||||
|
||||
init {
|
||||
vm.getIO().blockTransferPorts[1].attachDevice(WorldRadar())
|
||||
vm.peripheralTable[1] = PeripheralEntry(
|
||||
ExtDisp(vm, 160, 140), 32768, 1, 0
|
||||
)
|
||||
|
||||
App.disposables.add(Disposable { vm.dispose() })
|
||||
App.disposables.add(ui)
|
||||
}
|
||||
|
||||
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||
(Terrarum.ingame!! as TerrarumIngame).wearableDeviceUI = ui
|
||||
}
|
||||
|
||||
override fun effectOnUnequip(actor: ActorWithBody, delta: Float) {
|
||||
(Terrarum.ingame!! as TerrarumIngame).wearableDeviceUI = null
|
||||
}
|
||||
}
|
||||
|
||||
class WearableWorldRadarUI(val device: VM) : UICanvas() {
|
||||
|
||||
override var width = 160
|
||||
override var height = 140
|
||||
override var openCloseTime = 0f
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
device.update(delta)
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
batch.color = Color.WHITE
|
||||
(device.peripheralTable[1].peripheral as? ExtDisp)?.render(batch, posX.toFloat(), posY.toFloat())
|
||||
|
||||
batch.color = Toolkit.Theme.COL_INACTIVE
|
||||
Toolkit.drawBoxBorder(batch, posX-1, posY-1, width+2, height+2)
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package net.torvald.terrarum.modulecomputers.tsvmperipheral
|
||||
|
||||
import net.torvald.terrarum.IngameInstance
|
||||
import net.torvald.terrarum.Point2i
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.tsvm.VM
|
||||
import net.torvald.tsvm.peripheral.BlockTransferInterface
|
||||
import net.torvald.tsvm.peripheral.TestDiskDrive
|
||||
import net.torvald.tsvm.peripheral.trimNull
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-12-02.
|
||||
*/
|
||||
class WorldRadar : BlockTransferInterface(false, true) {
|
||||
|
||||
private val W = 162
|
||||
private val H = 142
|
||||
|
||||
private val AIR_OUT = 0.toByte()
|
||||
private val GRASS_OUT = 2.toByte()
|
||||
private val DIRT_OUT = 4.toByte()
|
||||
private val STONE_OUT = 7.toByte()
|
||||
|
||||
init {
|
||||
statusCode = TestDiskDrive.STATE_CODE_STANDBY
|
||||
}
|
||||
|
||||
private val messageComposeBuffer = ByteArrayOutputStream(BLOCK_SIZE) // always use this and don't alter blockSendBuffer please
|
||||
private var blockSendBuffer = ByteArray(1)
|
||||
private var blockSendCount = 0
|
||||
|
||||
private fun resetBuf() {
|
||||
blockSendCount = 0
|
||||
messageComposeBuffer.reset()
|
||||
}
|
||||
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
return (blockSendCount * BLOCK_SIZE < blockSendBuffer.size)
|
||||
}
|
||||
|
||||
override fun startSendImpl(recipient: BlockTransferInterface): Int {
|
||||
if (blockSendCount == 0) {
|
||||
blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||
}
|
||||
|
||||
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
|
||||
blockSendBuffer.size % BLOCK_SIZE
|
||||
else BLOCK_SIZE
|
||||
|
||||
recipient.writeout(ByteArray(sendSize) {
|
||||
blockSendBuffer[blockSendCount * BLOCK_SIZE + it]
|
||||
})
|
||||
|
||||
blockSendCount += 1
|
||||
|
||||
return sendSize
|
||||
}
|
||||
|
||||
private var oldCmdbuf = HashMap<Int,Byte>(1024)
|
||||
|
||||
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 writeoutImpl(inputData: ByteArray) {
|
||||
val inputString = inputData.trimNull().toString(VM.CHARSET)
|
||||
|
||||
// prepare draw commands
|
||||
/*
|
||||
* draw command format:
|
||||
*
|
||||
* <Y> <X> <COL>
|
||||
*
|
||||
* marking rules:
|
||||
*
|
||||
* : exposed = has at least 1 nonsolid on 4 sides
|
||||
*
|
||||
* 1. exposed grass -> 2
|
||||
* 2. exposed dirt -> 4
|
||||
* 3. exposed stone -> 7
|
||||
* 4. stone exposed to dirt/grass -> 7
|
||||
*/
|
||||
if (inputString.startsWith("POLL")) {
|
||||
resetBuf()
|
||||
val cmdbuf = HashMap<Int,Byte>(1024)
|
||||
|
||||
Terrarum.ingame?.let { ingame -> ingame.actorNowPlaying?.let {
|
||||
|
||||
val px = it.intTilewiseHitbox.canonicalX.toInt()
|
||||
val py = it.intTilewiseHitbox.canonicalY.toInt()
|
||||
|
||||
for (y in 1..H - 2) {
|
||||
for (x in 1..W - 2) {
|
||||
val yx = (y - 1).shl(8) or x
|
||||
val nearby = getNearbyTilesPos(px, py).map { ingame.world.getTileFromTerrain(it.x, it.y) } // up, left, right, down
|
||||
val block = ingame.world.getTileFromTerrain(px, py)
|
||||
val blockprop = Terrarum.blockCodex[block]
|
||||
|
||||
if (blockprop.isSolid) {
|
||||
// TODO create extension function nearby.contains { predicate :: ItemID -> Boolean }
|
||||
if (blockprop.material == "GRSS" && nearby.contains(Block.AIR)) {
|
||||
cmdbuf[yx] = GRASS_OUT
|
||||
}
|
||||
else if (blockprop.material == "DIRT" && nearby.contains(Block.AIR)) {
|
||||
cmdbuf[yx] = DIRT_OUT
|
||||
}
|
||||
else if (blockprop.material == "ROCK" && (nearby.contains(Block.AIR) || nearby.contains(Block.GRASS) || nearby.contains(Block.DIRT))) {
|
||||
cmdbuf[yx] = STONE_OUT
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(oldCmdbuf.keys union cmdbuf.keys).sorted().forEach { key ->
|
||||
val value = (cmdbuf[key] ?: AIR_OUT).toInt()
|
||||
val x = key % 256
|
||||
val y = key / 256
|
||||
messageComposeBuffer.write(y)
|
||||
messageComposeBuffer.write(x)
|
||||
messageComposeBuffer.write(value)
|
||||
}
|
||||
|
||||
oldCmdbuf = cmdbuf
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user