@@ -6,6 +6,7 @@ import com.noxcrew.interfaces.InterfacesListeners
6
6
import com.noxcrew.interfaces.event.DrawPaneEvent
7
7
import com.noxcrew.interfaces.grid.GridPoint
8
8
import com.noxcrew.interfaces.interfaces.Interface
9
+ import com.noxcrew.interfaces.interfaces.InterfaceBuilder
9
10
import com.noxcrew.interfaces.inventory.InterfacesInventory
10
11
import com.noxcrew.interfaces.pane.CompletedPane
11
12
import com.noxcrew.interfaces.pane.Pane
@@ -34,10 +35,10 @@ import kotlin.time.Duration
34
35
import kotlin.time.Duration.Companion.seconds
35
36
36
37
/* * The basis for the implementation of an interface view. */
37
- public abstract class AbstractInterfaceView <I : InterfacesInventory , P : Pane >(
38
+ public abstract class AbstractInterfaceView <I : InterfacesInventory , T : Interface < T , P >, P : Pane >(
38
39
override val player : Player ,
39
40
/* * The interface backing this view. */
40
- public val backing : Interface < P > ,
41
+ public val backing : T ,
41
42
private val parent : InterfaceView ?
42
43
) : InterfaceView {
43
44
@@ -50,7 +51,11 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
50
51
private val semaphore = Semaphore (1 )
51
52
private val queue = AtomicInteger (0 )
52
53
53
- private val children = WeakHashMap <AbstractInterfaceView <* , * >, Unit > ()
54
+ private val children = WeakHashMap <AbstractInterfaceView <* , * , * >, Unit > ()
55
+
56
+ /* * The builder used by this interface. */
57
+ public val builder: InterfaceBuilder <P , T >
58
+ get() = backing.builder
54
59
55
60
/* * Added persistent items added when this interface was last closed. */
56
61
public val addedItems: MutableMap <GridPoint , ItemStack > = mutableMapOf ()
@@ -96,8 +101,8 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
96
101
openIfClosed.set(false )
97
102
98
103
// Run a generic close handler if it's still opened
99
- if (shouldBeOpened.compareAndSet(true , false ) && (! changingView || backing.properties .callCloseHandlerOnViewSwitch)) {
100
- backing.properties .closeHandlers[reason]?.invoke(reason, this )
104
+ if (shouldBeOpened.compareAndSet(true , false ) && (! changingView || builder .callCloseHandlerOnViewSwitch)) {
105
+ builder .closeHandlers[reason]?.invoke(reason, this )
101
106
}
102
107
103
108
// Don't close children when changing views!
@@ -118,7 +123,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
118
123
private fun setup () {
119
124
// Determine for each trigger what transforms it updates
120
125
val triggers = HashMultimap .create<Trigger , AppliedTransform <P >>()
121
- for (transform in backing.properties .transforms) {
126
+ for (transform in builder .transforms) {
122
127
for (trigger in transform.triggers) {
123
128
triggers.put(trigger, transform)
124
129
}
@@ -138,7 +143,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
138
143
}
139
144
140
145
override fun redrawComplete () {
141
- applyTransforms(backing.properties .transforms)
146
+ applyTransforms(builder .transforms)
142
147
}
143
148
144
149
override suspend fun open () {
@@ -148,7 +153,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
148
153
shouldBeOpened.set(true )
149
154
150
155
// Indicate to the parent that this child exists
151
- if (parent is AbstractInterfaceView <* , * >) {
156
+ if (parent is AbstractInterfaceView <* , * , * >) {
152
157
parent.children[this ] = Unit
153
158
}
154
159
@@ -293,14 +298,14 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
293
298
currentInventory.set(
294
299
row,
295
300
column,
296
- element.itemStack.apply { this ?.let { backing.properties .itemPostProcessor?.invoke(it) } }
301
+ element.itemStack.apply { this ?.let { builder .itemPostProcessor?.invoke(it) } }
297
302
)
298
303
leftovers - = row to column
299
304
madeChanges = true
300
305
}
301
306
302
307
// Apply the overlay of persistent items on top
303
- if (backing.properties .persistAddedItems) {
308
+ if (builder .persistAddedItems) {
304
309
for ((point, item) in addedItems) {
305
310
val row = point.x
306
311
val column = point.y
@@ -318,7 +323,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
318
323
}
319
324
320
325
// If we inherit existing items we don't clear here!
321
- if (! backing.properties .inheritExistingItems) {
326
+ if (! builder .inheritExistingItems) {
322
327
// Empty any slots that are not otherwise edited
323
328
for ((row, column) in leftovers) {
324
329
val isPlayerInventory = currentInventory.isPlayerInventory(row, column)
@@ -335,7 +340,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
335
340
336
341
/* * Saves any persistent items based on [inventory]. */
337
342
public fun savePersistentItems (inventory : Inventory ) {
338
- if (! backing.properties .persistAddedItems) return
343
+ if (! builder .persistAddedItems) return
339
344
340
345
addedItems.clear()
341
346
val contents = inventory.contents
0 commit comments