mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
fix: workbench failes to load because uiInventoryPlayer is uninit'd at the load time
This commit is contained in:
@@ -189,6 +189,9 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
lateinit var uiPieMenu: UIQuickslotPie
|
lateinit var uiPieMenu: UIQuickslotPie
|
||||||
lateinit var uiQuickBar: UIQuickslotBar
|
lateinit var uiQuickBar: UIQuickslotBar
|
||||||
lateinit var uiInventoryPlayer: UIInventoryFull
|
lateinit var uiInventoryPlayer: UIInventoryFull
|
||||||
|
|
||||||
|
internal val uiInventoryPlayerReady: Boolean get() = ::uiInventoryPlayer.isInitialized // this is some ugly hack but I didn't want to make uiInventoryPlayer nullable so bite me
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a dedicated property for the fixtures' UI.
|
* This is a dedicated property for the fixtures' UI.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ class FixtureWorkbench : FixtureBase, CraftingStation {
|
|||||||
|
|
||||||
constructor() : super(
|
constructor() : super(
|
||||||
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 2, 1),
|
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 2, 1),
|
||||||
nameFun = { Lang["ITEM_WORKBENCH"] },
|
nameFun = { Lang["ITEM_WORKBENCH"] }
|
||||||
mainUI = (INGAME as? TerrarumIngame)?.uiInventoryPlayer
|
|
||||||
) {
|
) {
|
||||||
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/workbench.tga")
|
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/workbench.tga")
|
||||||
|
|
||||||
@@ -40,4 +39,17 @@ class FixtureWorkbench : FixtureBase, CraftingStation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var mainUIhookHackInstalled = false
|
||||||
|
override fun update(delta: Float) {
|
||||||
|
// adding UI to the fixture as players may right-click on the workbenches instead of pressing a keyboard key
|
||||||
|
(INGAME as? TerrarumIngame)?.let { ingame ->
|
||||||
|
if (!mainUIhookHackInstalled && ingame.uiInventoryPlayerReady) {
|
||||||
|
mainUIhookHackInstalled = true
|
||||||
|
this.mainUI = ingame.uiInventoryPlayer // this field is initialised only after a full load so this hack is necessary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.update(delta)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user