mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
drawing a held tile to the hand of the sprite
This commit is contained in:
@@ -5,9 +5,11 @@ import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.ItemCodex
|
||||
import net.torvald.terrarum.ReferencingRanges
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.linearSearch
|
||||
import net.torvald.terrarum.linearSearchBy
|
||||
import net.torvald.terrarum.savegame.ByteArray64InputStream
|
||||
import net.torvald.terrarum.savegame.ByteArray64Reader
|
||||
import net.torvald.terrarum.savegame.SimpleFileSystem
|
||||
@@ -177,31 +179,40 @@ object AssembleSheetPixmap {
|
||||
val tmpFrame = Pixmap(props.frameWidth, props.frameHeight, Pixmap.Format.RGBA8888)
|
||||
|
||||
transformList.forEach { (name, bodypartPos) ->
|
||||
if (name == "HELD_ITEM") {
|
||||
injectedItem?.itemImage?.let { textureRegion ->
|
||||
// TODO FIXME tiles are not being drawn
|
||||
if (name == "HELD_ITEM" && injectedItem != null) {
|
||||
// printdbg(this, "ID of the held item: ${injectedItem.originalID}")
|
||||
|
||||
ItemCodex.getItemImage(injectedItem)?.let { textureRegion ->
|
||||
// printdbg(this, "and it did have a textureregion")
|
||||
|
||||
val texdata = textureRegion.texture.textureData
|
||||
texdata.prepare()
|
||||
val imageSheet = texdata.consumePixmap()
|
||||
val textureBackedByPixmap = texdata.isPrepared // texture backed by pixmap is always prepared without ordering it to prepare
|
||||
if (!textureBackedByPixmap) texdata.prepare()
|
||||
|
||||
val imageSheet = if
|
||||
(injectedItem.originalID.startsWith("${ReferencingRanges.PREFIX_DYNAMICITEM}:") ||
|
||||
injectedItem.originalID.startsWith("item@") ||
|
||||
injectedItem.originalID.startsWith("wire@"))
|
||||
texdata.consumePixmap()
|
||||
// super dirty and ugly hack because for some reason it just won't work
|
||||
else if (injectedItem.originalID.startsWith("wall@"))
|
||||
App.tileMaker.itemWallPixmap
|
||||
else
|
||||
App.tileMaker.itemTerrainPixmap
|
||||
|
||||
|
||||
val drawPos = props.origin + bodypartPos
|
||||
|
||||
val pu = (textureRegion.u * texdata.width).toInt()
|
||||
val pv = (textureRegion.v * texdata.height).toInt()
|
||||
val pu2 = (textureRegion.u2 * texdata.width).toInt()
|
||||
val pv2 = (textureRegion.v2 * texdata.height).toInt()
|
||||
val imageWidth = textureRegion.regionWidth
|
||||
val imageHeight = textureRegion.regionHeight
|
||||
|
||||
for (y in pv until pv2) { for (x in pu until pu2) {
|
||||
val pixel = imageSheet.getPixel(x, y)
|
||||
tmpFrame.drawPixel(
|
||||
drawPos.x + x - pu,
|
||||
(props.frameHeight - drawPos.y - 1) + y - pv - imageHeight,
|
||||
pixel
|
||||
)
|
||||
} }
|
||||
// printdbg(this, "uv: ($pu,$pv) uv2: ($pu2,$pv2) dim: ($imageWidth,$imageHeight) atlasdim: (${texdata.width},${texdata.height})")
|
||||
|
||||
imageSheet.dispose()
|
||||
tmpFrame.drawPixmap(imageSheet, drawPos.x, props.frameHeight - drawPos.y - 1 - imageHeight, pu, pv, imageWidth, imageHeight)
|
||||
|
||||
if (!textureBackedByPixmap) imageSheet.dispose()
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -98,8 +98,32 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
abstract val material: Material
|
||||
|
||||
/**
|
||||
* DO NOT READ FROM THIS VALUE: USE `ItemCodex.getItemImage(item)`;
|
||||
* this hack is needed to avoid the unsolvable issue regarding the ItemImage of the tiles, of which they
|
||||
* cannot be assigned because of this old note:
|
||||
*
|
||||
* Don't assign! Create getter -- there's inevitable execution order fuckup on ModMgr,
|
||||
* where it simultaneously wanted to be called before and after the Mod's EntryPoint if you assign value to it on init block.
|
||||
*
|
||||
*
|
||||
* Note to future adventurers:
|
||||
*
|
||||
* the following code did not solved the issue
|
||||
*
|
||||
* file: net.torvald.terrarum.modulebasegame.EntryPoint
|
||||
*
|
||||
* ```
|
||||
* override val itemImage: TextureRegion
|
||||
* get() {
|
||||
* val itemSheetNumber = App.tileMaker.tileIDtoItemSheetNumber(originalID)
|
||||
* val bucket = if (isWall) BlocksDrawer.tileItemWall else BlocksDrawer.tileItemTerrain
|
||||
* return bucket.get(
|
||||
* itemSheetNumber % App.tileMaker.ITEM_ATLAS_TILES_X,
|
||||
* itemSheetNumber / App.tileMaker.ITEM_ATLAS_TILES_X
|
||||
* )
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
@Transient open val itemImage: TextureRegion? = null
|
||||
|
||||
|
||||
@@ -80,6 +80,15 @@ class EntryPoint : ModuleEntryPoint() {
|
||||
override var inventoryCategory = if (isWall) Category.WALL else Category.BLOCK
|
||||
override var isDynamic = false
|
||||
override val material = MaterialCodex.getOrDefault(tile.material)
|
||||
// override val itemImage: TextureRegion
|
||||
// get() {
|
||||
// val itemSheetNumber = App.tileMaker.tileIDtoItemSheetNumber(originalID)
|
||||
// val bucket = if (isWall) BlocksDrawer.tileItemWall else BlocksDrawer.tileItemTerrain
|
||||
// return bucket.get(
|
||||
// itemSheetNumber % App.tileMaker.ITEM_ATLAS_TILES_X,
|
||||
// itemSheetNumber / App.tileMaker.ITEM_ATLAS_TILES_X
|
||||
// )
|
||||
// }
|
||||
|
||||
init {
|
||||
equipPosition = EquipPosition.HAND_GRIP
|
||||
|
||||
@@ -3,13 +3,18 @@ package net.torvald.terrarum.utils
|
||||
import java.awt.Toolkit
|
||||
import java.awt.datatransfer.DataFlavor
|
||||
import java.awt.datatransfer.StringSelection
|
||||
import java.awt.datatransfer.UnsupportedFlavorException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-07-31.
|
||||
*/
|
||||
object Clipboard {
|
||||
fun fetch(): String =
|
||||
Toolkit.getDefaultToolkit().systemClipboard.getData(DataFlavor.stringFlavor) as String
|
||||
fun fetch(): String = try {
|
||||
Toolkit.getDefaultToolkit().systemClipboard.getData(DataFlavor.stringFlavor) as String
|
||||
}
|
||||
catch (e: UnsupportedFlavorException) {
|
||||
""
|
||||
}
|
||||
|
||||
fun copy(s: String) {
|
||||
val selection = StringSelection(s)
|
||||
|
||||
@@ -115,12 +115,19 @@ internal object BlocksDrawer {
|
||||
|
||||
|
||||
// test print
|
||||
//PixmapIO2.writeTGA(Gdx.files.absolute("${AppLoader.defaultDir}/terrainitem.tga"), itemTerrainPixmap, false)
|
||||
|
||||
tileItemTerrain = TextureRegionPack(App.tileMaker.itemTerrainTexture, TILE_SIZE, TILE_SIZE)
|
||||
tileItemWall = TextureRegionPack(App.tileMaker.itemWallTexture, TILE_SIZE, TILE_SIZE)
|
||||
|
||||
|
||||
// val texdata = tileItemTerrain.texture.textureData
|
||||
// val textureBackedByPixmap = texdata.isPrepared
|
||||
// if (!textureBackedByPixmap) texdata.prepare()
|
||||
// val imageSheet = texdata.consumePixmap()
|
||||
// PixmapIO2.writeTGA(Gdx.files.absolute("${App.defaultDir}/terrainitem.tga"), imageSheet, false)
|
||||
// if (!textureBackedByPixmap) imageSheet.dispose()
|
||||
|
||||
|
||||
|
||||
// finally
|
||||
tilesTerrain = weatherTerrains[1]
|
||||
|
||||
@@ -65,6 +65,10 @@ class CreateTileAtlas {
|
||||
private val atlasInit = "./assets/graphics/blocks/init.tga"
|
||||
private var itemSheetCursor = 16
|
||||
|
||||
internal val itemTerrainPixmap = Pixmap(16 * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
internal val itemWallPixmap = Pixmap(16 * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
|
||||
|
||||
/**
|
||||
* Must be called AFTER mods' loading so that all the block props are loaded
|
||||
*/
|
||||
@@ -148,8 +152,8 @@ class CreateTileAtlas {
|
||||
else -> 0
|
||||
}
|
||||
|
||||
val itemTerrainPixmap = Pixmap(16 * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
val itemWallPixmap = Pixmap(16 * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
// val itemTerrainPixmap = Pixmap(16 * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
// val itemWallPixmap = Pixmap(16 * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
|
||||
tags.toMap().forEach { id, tag ->
|
||||
val tilePosFromAtlas = tag.tileNumber + maskTypetoTileIDForItemImage(tag.maskType)
|
||||
@@ -199,8 +203,8 @@ class CreateTileAtlas {
|
||||
|
||||
itemTerrainTexture = Texture(itemTerrainPixmap)
|
||||
itemWallTexture = Texture(itemWallPixmap)
|
||||
itemTerrainPixmap.dispose()
|
||||
itemWallPixmap.dispose()
|
||||
// itemTerrainPixmap.dispose()
|
||||
// itemWallPixmap.dispose()
|
||||
initPixmap.dispose()
|
||||
|
||||
initialised = true
|
||||
@@ -385,6 +389,8 @@ class CreateTileAtlas {
|
||||
atlasGlow.dispose()
|
||||
//itemTerrainTexture.dispose() //BlocksDrawer will dispose of it as it disposes of 'tileItemTerrain (TextureRegionPack)'
|
||||
//itemWallTexture.dispose() //BlocksDrawer will dispose of it as it disposes of 'tileItemWall (TextureRegionPack)'
|
||||
itemTerrainPixmap.dispose()
|
||||
itemWallPixmap.dispose()
|
||||
|
||||
nullTile.dispose()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user