mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 04:24:05 +09:00
signs persisting through load/save
This commit is contained in:
@@ -1693,7 +1693,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
// pickup a fixture
|
||||
if (fixture != null) {
|
||||
val fixtureItem = ItemCodex.fixtureToItemID(fixture)
|
||||
val fixtureItem = fixture.itemise()
|
||||
printdbg(this, "Fixture pickup at F${WORLD_UPDATE_TIMER}: ${fixture.javaClass.canonicalName} -> $fixtureItem")
|
||||
// 0. hide tooltips
|
||||
setTooltipMessage(null)
|
||||
|
||||
41
src/net/torvald/terrarum/modulebasegame/console/MakeSign.kt
Normal file
41
src/net/torvald/terrarum/modulebasegame/console/MakeSign.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.itemproperties.Item
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.ItemTextSignCopper
|
||||
import net.torvald.unicode.TIMES
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-03-21.
|
||||
*/
|
||||
class MakeSign : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size !in 2..3) {
|
||||
printUsage(); return
|
||||
}
|
||||
|
||||
val text = args[1]
|
||||
val textLen = App.fontGame.getWidth(text)
|
||||
val panelCount = (args.getOrNull(2)?.toInt() ?: (textLen / TILE_SIZEF).ceilToInt()).coerceAtLeast(2)
|
||||
|
||||
val actorInventory = INGAME.actorNowPlaying!!.inventory
|
||||
|
||||
val item = ItemTextSignCopper(Item.COPPER_SIGN).makeDynamic(actorInventory).also {
|
||||
it.extra["signContent"] = text
|
||||
it.extra["signPanelCount"] = panelCount
|
||||
it.nameSecondary = "[$panelCount${TIMES}2] $text"
|
||||
}
|
||||
|
||||
actorInventory.add(item)
|
||||
Echo("Sign added: ${item.nameSecondary}")
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Usage: makesign <text>")
|
||||
Echo("Usage: makesign <text> <panelcount>")
|
||||
Echo("If panel count is not given, smallest possible panel count will be used.")
|
||||
}
|
||||
}
|
||||
@@ -115,10 +115,8 @@ class ActorInventory() : FixtureInventory() {
|
||||
remove(item, 1)
|
||||
|
||||
|
||||
newItem = item.clone()
|
||||
newItem.generateUniqueDynamicID(this)
|
||||
newItem = item.makeDynamic(this)
|
||||
|
||||
newItem.stackable = false
|
||||
add(newItem)
|
||||
itemEquipped[newItem.equipPosition] = newItem.dynamicID //invSearchByDynamicID(newItem.dynamicID)!!.item // will test if some sketchy code is written. Test fail: kotlinNullpointerException
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore
|
||||
@@ -462,6 +463,14 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
} as TextureRegionPack)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For some customisable fixtures, they must create new dynamicItem out of their static "template",
|
||||
* register the new dynamicID to the ItemCodex, then return the dynamicID.
|
||||
*/
|
||||
open fun itemise(): ItemID {
|
||||
return ItemCodex.fixtureToItemID(this)
|
||||
}
|
||||
}
|
||||
|
||||
interface CuedByTerrainChange {
|
||||
|
||||
@@ -66,10 +66,10 @@ internal class FixtureTapestry : FixtureBase {
|
||||
|
||||
// draw canvas and frame texture over the pixmap
|
||||
val tileFilename = "${frameBlock.replace(':','-')}"
|
||||
val frame = CommonResourcePool.getOrPut("tapestries-common-frame_$tileFilename.tga") {
|
||||
val frame = CommonResourcePool.getOrPut("pixmap:tapestries-common-frame_$tileFilename.tga") {
|
||||
Pixmap(ModMgr.getGdxFilesFromEveryMod("tapestries/common/frame_$tileFilename.tga").last().second)
|
||||
} as Pixmap
|
||||
val canvas = CommonResourcePool.getOrPut("tapestries-common-canvas.tga") {
|
||||
val canvas = CommonResourcePool.getOrPut("pixmap:tapestries-common-canvas.tga") {
|
||||
Pixmap(ModMgr.getGdxFilesFromEveryMod("tapestries/common/canvas.tga").last().second)
|
||||
} as Pixmap
|
||||
|
||||
|
||||
@@ -12,10 +12,15 @@ import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.itemproperties.Item
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.ItemTextSignCopper
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.tooltipShowing
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import net.torvald.unicode.TIMES
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import java.util.*
|
||||
|
||||
@@ -53,6 +58,19 @@ class FixtureTextSignCopper : Electric {
|
||||
reload()
|
||||
}
|
||||
|
||||
fun _itemise(actor: ActorHumanoid): GameItem {
|
||||
return ItemTextSignCopper(Item.COPPER_SIGN).makeDynamic(actor.inventory).also {
|
||||
it.extra["signContent"] = text
|
||||
it.extra["signPanelCount"] = panelCount
|
||||
it.nameSecondary = "[$panelCount${TIMES}2] $text"
|
||||
}
|
||||
}
|
||||
|
||||
override fun itemise(): ItemID {
|
||||
val item = _itemise(INGAME.actorNowPlaying!!)
|
||||
return item.dynamicID
|
||||
}
|
||||
|
||||
override fun spawn(posX: Int, posY: Int, installersUUID: UUID?): Boolean = spawn(posX, posY, installersUUID, panelCount.coerceAtLeast(2), 2)
|
||||
|
||||
override fun reload() {
|
||||
|
||||
@@ -14,6 +14,8 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureTapestry
|
||||
*/
|
||||
class ItemTapestry(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureTapestry") {
|
||||
|
||||
constructor() : this("") // item that can be dynamic needs no-arg constructor, as the class gets serialised into the savegame under dynamicItemInventory.[dynamicID]
|
||||
|
||||
override var dynamicID: ItemID = originalID
|
||||
override var baseMass = 6.0
|
||||
override val canBeDynamic = false
|
||||
@@ -25,8 +27,9 @@ class ItemTapestry(originalID: ItemID) : FixtureItemBase(originalID, "net.torval
|
||||
|
||||
@Transient override val makeFixture: () -> FixtureBase = {
|
||||
FixtureTapestry(
|
||||
Gdx.files.internal("assets/monkey_island").readBytes(),
|
||||
Block.PLANK_NORMAL
|
||||
// TODO use extra["fileRef"] (string) and extra["framingMaterial"] (string)
|
||||
Gdx.files.internal("assets/monkey_island").readBytes(),
|
||||
Block.PLANK_NORMAL
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,19 @@ import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.itemproperties.Item
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalEmitter
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTextSignCopper
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-03-20.
|
||||
*/
|
||||
class ItemTextSignCopper(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureTextSignCopper") {
|
||||
|
||||
constructor() : this("") // item that can be dynamic needs no-arg constructor, as the class gets serialised into the savegame under dynamicItemInventory.[dynamicID]
|
||||
|
||||
override var dynamicID: ItemID = originalID
|
||||
override var baseMass = 10.0
|
||||
override val canBeDynamic = false
|
||||
@@ -25,4 +30,10 @@ class ItemTextSignCopper(originalID: ItemID) : FixtureItemBase(originalID, "net.
|
||||
override var baseToolSize: Double? = baseMass
|
||||
override var originalName = "ITEM_COPPER_SIGN"
|
||||
|
||||
@Transient override val makeFixture: () -> FixtureBase = {
|
||||
FixtureTextSignCopper(
|
||||
extra.getAsString("signContent") ?: "",
|
||||
extra.getAsInt("signPanelCount") ?: 2
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user