mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
more on itemfileref
This commit is contained in:
@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
||||
import com.badlogic.gdx.Gdx
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import java.io.File
|
||||
@@ -60,6 +61,19 @@ open class ItemFileRef(originalID: ItemID) : GameItem(originalID) {
|
||||
*/
|
||||
open var mediumIdentifier = ""
|
||||
|
||||
/**
|
||||
* How this item should look like on inventory/in world. Used when creation of subclass is not possible.
|
||||
*/
|
||||
open var morphItem = ""
|
||||
|
||||
/**
|
||||
* Fully-qualified classname. Class to be called when this item is used by hitting "interaction" key.
|
||||
* Used when creation of subclass is not possible.
|
||||
*
|
||||
* If specified, the class must implement FileRefItemPrimaryUseHandler
|
||||
*/
|
||||
open var useItemHandler = ""
|
||||
|
||||
|
||||
override var baseMass = 1.0
|
||||
override var baseToolSize: Double? = null
|
||||
@@ -77,4 +91,31 @@ open class ItemFileRef(originalID: ItemID) : GameItem(originalID) {
|
||||
File(App.saveSharedDir + "/$refPath")
|
||||
else
|
||||
ModMgr.getFile(refModuleName, refPath)
|
||||
|
||||
@Transient private var classCache: FileRefItemPrimaryUseHandler? = null
|
||||
|
||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long {
|
||||
return if (useItemHandler.isNotBlank()) {
|
||||
try {
|
||||
if (classCache == null) {
|
||||
val newClass = Class.forName(useItemHandler)
|
||||
val newClassConstructor = newClass.getConstructor(/* no args defined */)
|
||||
val newClassInstance = newClassConstructor.newInstance(/* no args defined */)
|
||||
classCache = (newClassInstance as FileRefItemPrimaryUseHandler)
|
||||
}
|
||||
classCache!!.use(this)
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
e.printStackTrace()
|
||||
super.startPrimaryUse(actor, delta)
|
||||
}
|
||||
}
|
||||
else super.startPrimaryUse(actor, delta)
|
||||
}
|
||||
}
|
||||
|
||||
interface FileRefItemPrimaryUseHandler {
|
||||
/** If this item must be consumed, return 1; if this item must not be consumed, return 0; if this item
|
||||
* was failed to be used (for some reason), return -1. */
|
||||
fun use(item: ItemFileRef): Long
|
||||
}
|
||||
@@ -317,6 +317,8 @@ object VDFileID {
|
||||
const val BODYPART_TO_ENTRY_MAP = -1025L
|
||||
const val BODYPARTGLOW_TO_ENTRY_MAP = -1026L
|
||||
const val BODYPARTEMISSIVE_TO_ENTRY_MAP = -1027L
|
||||
|
||||
const val BLOB_REDEEMED_CODES = -2147483648L
|
||||
}
|
||||
|
||||
fun diskIDtoReadableFilename(id: EntryID, saveKind: Int?): String = when (id) {
|
||||
@@ -354,6 +356,7 @@ fun diskIDtoReadableFilename(id: EntryID, saveKind: Int?): String = when (id) {
|
||||
VDFileID.BODYPART_TO_ENTRY_MAP -> "bodypart-to-entry.map"
|
||||
VDFileID.BODYPARTGLOW_TO_ENTRY_MAP -> "bodypartglow-to-entry.map"
|
||||
VDFileID.BODYPARTEMISSIVE_TO_ENTRY_MAP -> "bodypartemsv-to-entry.map"
|
||||
VDFileID.BLOB_REDEEMED_CODES -> "blob: redeemed codes"
|
||||
in 1..65535 ->
|
||||
if (saveKind == PLAYER_DATA)
|
||||
"bodypart #$id.tga.gz"
|
||||
|
||||
Reference in New Issue
Block a user