Skip to content

Commit

Permalink
Clean up when firstPaint is set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeltumn committed Oct 28, 2023
1 parent 2880ec5 commit 297bfbd
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
// Add listeners to all triggers and update its transforms
for ((trigger, transforms) in triggers.asMap()) {
trigger.addListener(this) {
// If the first paint has not completed we do not perform any updates
if (firstPaint) return@addListener

// Apply the transforms for the new ones
applyTransforms(transforms)
}
Expand All @@ -90,7 +87,6 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
if (firstPaint || this !is ChestInterfaceView) {
firstPaint = true
setup()
firstPaint = false
} else {
renderAndOpen()
}
Expand Down Expand Up @@ -251,7 +247,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
protected open suspend fun renderToInventory(callback: (Boolean) -> Unit) {
// If a new inventory is required we create one
// and mark that the current one is not to be used!
val createdInventory = if (firstPaint || requiresNewInventory()) {
val createdInventory = if (requiresNewInventory()) {
currentInventory = createInventory()
true
} else {
Expand All @@ -273,6 +269,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
if ((openIfClosed && !isOpen) || createdInventory) {
openInventory()
openIfClosed = false
firstPaint = false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ChestInterfaceView internal constructor(

override fun requiresPlayerUpdate(): Boolean = false

override fun requiresNewInventory(): Boolean = titleState.hasChanged
override fun requiresNewInventory(): Boolean = super.requiresNewInventory() || titleState.hasChanged

override fun getInventory(): Inventory = currentInventory.chestInventory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CombinedInterfaceView internal constructor(

override fun requiresPlayerUpdate(): Boolean = false

override fun requiresNewInventory(): Boolean = titleState.hasChanged
override fun requiresNewInventory(): Boolean = super.requiresNewInventory() || titleState.hasChanged

override fun getInventory(): Inventory = currentInventory.chestInventory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class PlayerInterfaceView internal constructor(
error("PlayerInventoryView's cannot have a title")
}

override fun requiresNewInventory(): Boolean = false

override fun createInventory(): PlayerInterfacesInventory = PlayerInterfacesInventory(player)

override fun openInventory() {
Expand Down

0 comments on commit 297bfbd

Please sign in to comment.