This commit is contained in:
minjaesong
2021-02-11 20:45:38 +09:00
parent 8fdc11288c
commit 9eb757b7b9
29 changed files with 199 additions and 281 deletions

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
@@ -7,6 +8,7 @@ import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.utils.RasterWriter
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
import net.torvald.terrarum.worlddrawer.toRGBA
import java.io.File
import java.io.IOException
@@ -31,7 +33,8 @@ internal object ExportMap : ConsoleCommand {
var mapDataPointer = 0
for (tile in world.terrainIterator()) {
val colArray = CreateTileAtlas.terrainTileColourMap.getRaw(tile % 16, tile / 16).toByteArray()
val tileNumber = CreateTileAtlas.tileIDtoItemSheetNumber(tile)
val colArray = CreateTileAtlas.terrainTileColourMap.get(tileNumber)!!.toByteArray()
for (i in 0..2) {
mapData[mapDataPointer + i] = colArray[i]
@@ -71,11 +74,13 @@ internal object ExportMap : ConsoleCommand {
/***
* R-G-B-A order for RGBA input value
*/
private fun Cvec.toByteArray() = this.toRGBA().toByteArray()
private fun Int.toByteArray() = byteArrayOf(
this.shr(24).and(0xff).toByte(),
this.shr(16).and(0xff).toByte(),
this.shr(8).and(0xff).toByte(),
this.and(0xff).toByte()
this.ushr(24).and(255).toByte(),
this.ushr(16).and(255).toByte(),
this.ushr(8).and(255).toByte(),
this.and(255).toByte()
)
override fun printUsage() {

View File

@@ -4,6 +4,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
@@ -22,10 +23,10 @@ internal object Inventory : ConsoleCommand {
else {
when (args[1]) {
"list" -> listInventory()
"add" -> if (args.size > 3) addItem(args[2].toInt(), args[3].toInt())
else addItem(args[2].toInt())
"add" -> if (args.size > 3) addItem(args[2], args[3].toInt())
else addItem(args[2])
"target" -> setTarget(args[2].toInt())
"equip" -> equipItem(args[2].toInt())
"equip" -> equipItem(args[2])
else -> printUsage()
}
}
@@ -57,13 +58,13 @@ internal object Inventory : ConsoleCommand {
}
}
private fun addItem(refId: Int, amount: Int = 1) {
private fun addItem(refId: ItemID, amount: Int = 1) {
if (target != null) {
target!!.addItem(ItemCodex[refId]!!, amount)
}
}
private fun equipItem(refId: Int) {
private fun equipItem(refId: ItemID) {
if (target != null) {
val item = ItemCodex[refId]!!
target!!.equipItem(item)