Skip to content

Commit adc243c

Browse files
Document invui-kotlin reactive api functions
1 parent a56afea commit adc243c

File tree

15 files changed

+300
-44
lines changed

15 files changed

+300
-44
lines changed

invui-kotlin/src/main/kotlin/xyz/xenondevs/invui/gui/GuiExtensions.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,27 @@ operator fun Gui.plusAssign(elements: Iterable<SlotElement>) = elements.forEach
4949
@JvmName("plusAssignItems")
5050
operator fun Gui.plusAssign(items: Iterable<Item>) = items.forEach { addItems(it) }
5151

52+
/**
53+
* Sets the provider containing the background [ItemProvider] for the [Gui] built by this builder.
54+
* If [background] is not a [MutableProvider] attempting to change the background through other means will throw an exception.
55+
*/
5256
@ExperimentalReactiveApi
53-
fun <G : Gui, B : Gui.Builder<G, B>> B.setBackground(provider: Provider<ItemProvider?>): B =
54-
setBackground(PropertyAdapter(provider))
57+
fun <G : Gui, B : Gui.Builder<G, B>> B.setBackground(background: Provider<ItemProvider?>): B =
58+
setBackground(PropertyAdapter(background))
5559

60+
/**
61+
* Sets the provider containing the frozen state of the [Gui] built by this builder.
62+
* If [frozen] is not a [MutableProvider] attempting to change the frozen state through other means will throw an exception.
63+
*/
5664
@ExperimentalReactiveApi
57-
fun <G : Gui, B : Gui.Builder<G, B>> B.setFrozen(provider: Provider<Boolean>): B =
58-
setFrozen(PropertyAdapter(provider))
65+
fun <G : Gui, B : Gui.Builder<G, B>> B.setFrozen(frozen: Provider<Boolean>): B =
66+
setFrozen(PropertyAdapter(frozen))
5967

68+
/**
69+
* Sets the provider containing the setting whether slots of partially obscured embedded inventories
70+
* should be ignored or not of the [Gui] built by this builder.
71+
* If the provider is not a [MutableProvider], attempting to change this setting through other means will throw an exception.
72+
*/
6073
@ExperimentalReactiveApi
61-
fun <G : Gui, B : Gui.Builder<G, B>> B.setIgnoreObscuredInventorySlots(provider: Provider<Boolean>): B =
62-
setIgnoreObscuredInventorySlots(PropertyAdapter(provider))
74+
fun <G : Gui, B : Gui.Builder<G, B>> B.setIgnoreObscuredInventorySlots(ignoreObscuredInventorySlots: Provider<Boolean>): B =
75+
setIgnoreObscuredInventorySlots(PropertyAdapter(ignoreObscuredInventorySlots))

invui-kotlin/src/main/kotlin/xyz/xenondevs/invui/gui/PagedGuiExtensions.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@ import xyz.xenondevs.commons.provider.Provider
55
import xyz.xenondevs.invui.ExperimentalReactiveApi
66
import xyz.xenondevs.invui.PropertyAdapter
77

8+
/**
9+
* Sets the provider containing the current page for the [PagedGui] built by this builder.
10+
* If the value of [page] is set to an invalid page, it will be automatically adjusted to the closest valid page.
11+
*/
812
@ExperimentalReactiveApi
9-
fun <C : Any> PagedGui.Builder<C>.setPage(provider: MutableProvider<Int>): PagedGui.Builder<C> =
10-
setPage(PropertyAdapter(provider))
13+
fun <C : Any> PagedGui.Builder<C>.setPage(page: MutableProvider<Int>): PagedGui.Builder<C> =
14+
setPage(PropertyAdapter(page))
1115

16+
/**
17+
* Sets the provider containing the content of the [PagedGui] built by this builder to the result
18+
* of applying [transform] to the value of [provider].
19+
* (Shortcut for `setContent(provider.map(transform))`)
20+
*/
1221
@ExperimentalReactiveApi
1322
fun <C : Any, T> PagedGui.Builder<C>.setContent(provider: Provider<T>, transform: (T) -> List<C>): PagedGui.Builder<C> =
1423
setContent(provider.map(transform))
1524

25+
/**
26+
* Sets the provider containing the content of the [PagedGui] built by this builder.
27+
* If [content] is not a [MutableProvider], attempting to change the content through other means will throw an exception.
28+
*/
1629
@ExperimentalReactiveApi
17-
fun <C : Any> PagedGui.Builder<C>.setContent(provider: Provider<List<C>>): PagedGui.Builder<C> =
18-
setContent(PropertyAdapter(provider))
30+
fun <C : Any> PagedGui.Builder<C>.setContent(content: Provider<List<C>>): PagedGui.Builder<C> =
31+
setContent(PropertyAdapter(content))

invui-kotlin/src/main/kotlin/xyz/xenondevs/invui/gui/ScrollGuiExtensions.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@ import xyz.xenondevs.commons.provider.Provider
55
import xyz.xenondevs.invui.ExperimentalReactiveApi
66
import xyz.xenondevs.invui.PropertyAdapter
77

8+
/**
9+
* Sets the provider containing the current line for the [ScrollGui] built by this builder.
10+
* If the value of [line] is set to an invalid line, it will be automatically adjusted to the closest valid line.
11+
*/
812
@ExperimentalReactiveApi
9-
fun <C : Any> ScrollGui.Builder<C>.setLine(provider: MutableProvider<Int>): ScrollGui.Builder<C> =
10-
setLine(PropertyAdapter(provider))
13+
fun <C : Any> ScrollGui.Builder<C>.setLine(line: MutableProvider<Int>): ScrollGui.Builder<C> =
14+
setLine(PropertyAdapter(line))
1115

16+
/**
17+
* Sets the provider containing the content of the [ScrollGui] built by this builder to the result
18+
* of applying [transform] to the value of [provider].
19+
* (Shortcut for `setContent(provider.map(transform))`)
20+
*/
1221
@ExperimentalReactiveApi
1322
fun <C : Any, T> ScrollGui.Builder<C>.setContent(provider: Provider<T>, transform: (T) -> List<C>): ScrollGui.Builder<C> =
1423
setContent(provider.map(transform))
1524

25+
/**
26+
* Sets the provider containing the content of the [ScrollGui] built by this builder.
27+
* If [content] is not a [MutableProvider], attempting to change the content through other means will throw an exception.
28+
*/
1629
@ExperimentalReactiveApi
17-
fun <C : Any> ScrollGui.Builder<C>.setContent(provider: Provider<List<C>>): ScrollGui.Builder<C> =
18-
setContent(PropertyAdapter(provider))
30+
fun <C : Any> ScrollGui.Builder<C>.setContent(content: Provider<List<C>>): ScrollGui.Builder<C> =
31+
setContent(PropertyAdapter(content))

invui-kotlin/src/main/kotlin/xyz/xenondevs/invui/gui/TabGuiExtensions.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@ import xyz.xenondevs.commons.provider.Provider
55
import xyz.xenondevs.invui.ExperimentalReactiveApi
66
import xyz.xenondevs.invui.PropertyAdapter
77

8+
/**
9+
* Sets the provider containing the current tab for the [TabGui] built by this builder.
10+
* If the value of [tab] is set to an invalid tab, it will be automatically adjusted to the closest valid tab.
11+
*/
812
@ExperimentalReactiveApi
9-
fun TabGui.Builder.setTab(provider: MutableProvider<Int>): TabGui.Builder =
10-
setTab(PropertyAdapter(provider))
13+
fun TabGui.Builder.setTab(tab: MutableProvider<Int>): TabGui.Builder =
14+
setTab(PropertyAdapter(tab))
1115

16+
/**
17+
* Sets the provider containing the tabs of the [TabGui] built by this builder to the result
18+
* of applying [transform] to the value of [provider].
19+
* (Shortcut for `setTabs(provider.map(transform))`)
20+
*/
1221
@ExperimentalReactiveApi
1322
fun <T> TabGui.Builder.setTabs(provider: Provider<T>, transform: (T) -> List<Gui?>): TabGui.Builder =
1423
setTabs(provider.map(transform))
1524

25+
/**
26+
* Sets the tabs containing the tabs of the [TabGui] built by this builder.
27+
* If [tabs] is not a [MutableProvider], attempting to change the tabs through other means will throw an exception.
28+
*/
1629
@ExperimentalReactiveApi
17-
fun TabGui.Builder.setTabs(provider: Provider<List<Gui?>>): TabGui.Builder =
18-
setTabs(PropertyAdapter(provider))
30+
fun TabGui.Builder.setTabs(tabs: Provider<List<Gui?>>): TabGui.Builder =
31+
setTabs(PropertyAdapter(tabs))

invui-kotlin/src/main/kotlin/xyz/xenondevs/invui/item/ItemExtensions.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ import kotlin.experimental.ExperimentalTypeInference
1212
*/
1313
fun Iterable<Item>.notifyWindows() = forEach { it.notifyWindows() }
1414

15+
/**
16+
* Sets the [Provider] containing the [ItemProvider] for the [Item] built by this builder to the result
17+
* of applying [transform] to the value of [provider].
18+
* (Shortcut for `setItemProvider(provider.map(transform))`)
19+
*/
1520
@OverloadResolutionByLambdaReturnType
1621
@ExperimentalReactiveApi
1722
fun <S : Item.Builder<*>, T> S.setItemProvider(provider: Provider<T>, transform: (T) -> ItemProvider) =
1823
setItemProvider(provider.map(transform))
1924

25+
/**
26+
* Sets the [provider] containing the [ItemProvider] for the [Item] built by this builder.
27+
*/
2028
@ExperimentalReactiveApi
2129
fun <S : Item.Builder<*>> S.setItemProvider(
2230
provider: Provider<ItemProvider>
@@ -26,11 +34,20 @@ fun <S : Item.Builder<*>> S.setItemProvider(
2634
return this
2735
}
2836

37+
/**
38+
* Sets the [Provider] containing the [ItemStack] for the [Item] built by this builder to the result
39+
* of applying [transform] to the value of [provider].
40+
* (Shortcut for `setItemProvider(provider.map(transform))`)
41+
*/
2942
@JvmName("setItemProvider1")
3043
@ExperimentalReactiveApi
3144
fun <S : Item.Builder<*>, T> S.setItemProvider(provider: Provider<T>, transform: (T) -> ItemStack) =
3245
setItemProvider(provider.map(transform))
3346

47+
/**
48+
* Sets the [provider] containing the [ItemStack] for the [Item] built by this builder.
49+
* (Shortcut for `setItemProvider(provider.map(::ItemWrapper))`)
50+
*/
3451
@JvmName("setItemProvider1")
3552
@ExperimentalReactiveApi
3653
fun <S : Item.Builder<*>> S.setItemProvider(

invui-kotlin/src/main/kotlin/xyz/xenondevs/invui/window/AnvilWindowExtensions.kt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,44 @@ import xyz.xenondevs.commons.provider.Provider
55
import xyz.xenondevs.invui.ExperimentalReactiveApi
66
import xyz.xenondevs.invui.PropertyAdapter
77

8-
@Suppress("UNCHECKED_CAST")
8+
/**
9+
* Adds [handler] as a rename handler for the [AnvilWindow] built by this builder,
10+
* meaning the anvil text field will be written into [handler].
11+
*/
912
@ExperimentalReactiveApi
1013
fun AnvilWindow.Builder.addRenameHandler(handler: MutableProvider<String>): AnvilWindow.Builder =
1114
addRenameHandler(handler::set)
1215

16+
/**
17+
* Sets the provider containing the setting whether the text field of the [AnvilWindow] built by this builder is always enabled
18+
* to the result of applying [transform] to the value of [provider].
19+
* (Shortcut for `setTextFieldAlwaysEnabled(provider.map(transform))`)
20+
*/
1321
@ExperimentalReactiveApi
1422
fun <T> AnvilWindow.Builder.setTextFieldAlwaysEnabled(provider: Provider<T>, transform: (T) -> Boolean): AnvilWindow.Builder =
1523
setTextFieldAlwaysEnabled(provider.map(transform))
1624

25+
/**
26+
* Sets the provider containing the setting whether the text field of the [AnvilWindow] built by this builder is always enabled.
27+
* If [textFieldAlwaysEnabled] is not a [MutableProvider], attempting to change the setting through other means will throw an exception.
28+
*/
1729
@ExperimentalReactiveApi
18-
fun AnvilWindow.Builder.setTextFieldAlwaysEnabled(enabled: Provider<Boolean>): AnvilWindow.Builder =
19-
setTextFieldAlwaysEnabled(PropertyAdapter(enabled))
30+
fun AnvilWindow.Builder.setTextFieldAlwaysEnabled(textFieldAlwaysEnabled: Provider<Boolean>): AnvilWindow.Builder =
31+
setTextFieldAlwaysEnabled(PropertyAdapter(textFieldAlwaysEnabled))
2032

33+
/**
34+
* Sets the provider containing the setting whether the result of the [AnvilWindow] built by this builder is always valid
35+
* to the result of applying [transform] to the value of [provider].
36+
* (Shortcut for `setResultAlwaysValid(provider.map(transform))`)
37+
*/
2138
@ExperimentalReactiveApi
2239
fun <T> AnvilWindow.Builder.setResultAlwaysValid(provider: Provider<T>, transform: (T) -> Boolean): AnvilWindow.Builder =
2340
setResultAlwaysValid(provider.map(transform))
2441

42+
/**
43+
* Sets the provider containing the setting whether the result of the [AnvilWindow] built by this builder is always valid.
44+
* If [resultAlwaysValid] is not a [MutableProvider], attempting to change the setting through other means will throw an exception.
45+
*/
2546
@ExperimentalReactiveApi
26-
fun AnvilWindow.Builder.setResultAlwaysValid(enabled: Provider<Boolean>): AnvilWindow.Builder =
27-
setResultAlwaysValid(PropertyAdapter(enabled))
47+
fun AnvilWindow.Builder.setResultAlwaysValid(resultAlwaysValid: Provider<Boolean>): AnvilWindow.Builder =
48+
setResultAlwaysValid(PropertyAdapter(resultAlwaysValid))
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
package xyz.xenondevs.invui.window
22

3+
import xyz.xenondevs.commons.provider.MutableProvider
34
import xyz.xenondevs.commons.provider.Provider
45
import xyz.xenondevs.invui.ExperimentalReactiveApi
56
import xyz.xenondevs.invui.PropertyAdapter
67

8+
/**
9+
* Sets the provider containing the [brew progress][BrewingWindow.Builder.setBrewProgress] of the [BrewingWindow] built by this builder
10+
* to the result of applying [transform] to the value of [provider].
11+
* (Shortcut for `setBrewProgress(provider.map(transform))`)
12+
*/
713
@ExperimentalReactiveApi
814
fun <T> BrewingWindow.Builder.setBrewProgress(provider: Provider<T>, transform: (T) -> Double): BrewingWindow.Builder =
915
setBrewProgress(provider.map(transform))
1016

17+
/**
18+
* Sets the provider containing the [brew progress][BrewingWindow.Builder.setBrewProgress] of the [BrewingWindow] built by this builder.
19+
* If [brewProgress] is not a [MutableProvider], attempting to change the brew progress through other means will throw an exception.
20+
*/
1121
@ExperimentalReactiveApi
12-
fun BrewingWindow.Builder.setBrewProgress(progress: Provider<Double>): BrewingWindow.Builder =
13-
setBrewProgress(PropertyAdapter(progress))
22+
fun BrewingWindow.Builder.setBrewProgress(brewProgress: Provider<Double>): BrewingWindow.Builder =
23+
setBrewProgress(PropertyAdapter(brewProgress))
1424

25+
/**
26+
* Sets the provider containing the [fuel progress][BrewingWindow.Builder.setFuelProgress] of the [BrewingWindow] built by this builder
27+
* to the result of applying [transform] to the value of [provider].
28+
* (Shortcut for `setFuelProgress(provider.map(transform))`)
29+
*/
1530
@ExperimentalReactiveApi
1631
fun <T> BrewingWindow.Builder.setFuelProgress(provider: Provider<T>, transform: (T) -> Double): BrewingWindow.Builder =
1732
setFuelProgress(provider.map(transform))
1833

34+
/**
35+
* Sets the provider containing the [fuel progress][BrewingWindow.Builder.setFuelProgress] of the [BrewingWindow] built by this builder.
36+
* If [fuelProgress] is not a [MutableProvider], attempting to change the fuel progress through other means will throw an exception.
37+
*/
1938
@ExperimentalReactiveApi
20-
fun BrewingWindow.Builder.setFuelProgress(progress: Provider<Double>): BrewingWindow.Builder =
21-
setFuelProgress(PropertyAdapter(progress))
39+
fun BrewingWindow.Builder.setFuelProgress(fuelProgress: Provider<Double>): BrewingWindow.Builder =
40+
setFuelProgress(PropertyAdapter(fuelProgress))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
package xyz.xenondevs.invui.window
22

3+
import xyz.xenondevs.commons.provider.MutableProvider
34
import xyz.xenondevs.commons.provider.Provider
45
import xyz.xenondevs.invui.ExperimentalReactiveApi
56
import xyz.xenondevs.invui.PropertyAdapter
67

8+
/**
9+
* Sets the provider containing the icons on the map of the [CartographyWindow] built by this builder to the result
10+
* of applying [transform] to the value of [provider].
11+
* (Shortcut for `setIcons(provider.map(transform))`)
12+
*/
713
@ExperimentalReactiveApi
814
fun <T> CartographyWindow.Builder.setIcons(provider: Provider<T>, transform: (T) -> Set<CartographyWindow.MapIcon>): CartographyWindow.Builder =
915
setIcons(provider.map(transform))
1016

17+
/**
18+
* Sets the provider containing the icons on the map of the [CartographyWindow] built by this builder.
19+
* If [icons] is not a [MutableProvider], attempting to change the icons through other means will throw an exception.
20+
*/
1121
@ExperimentalReactiveApi
1222
fun CartographyWindow.Builder.setIcons(icons: Provider<Set<CartographyWindow.MapIcon>>): CartographyWindow.Builder =
1323
setIcons(PropertyAdapter(icons))
1424

25+
/**
26+
* Sets the provider containing the view of the [CartographyWindow] built by this builder to the result
27+
* of applying [transform] to the value of [provider].
28+
* (Shortcut for `setView(provider.map(transform))`)
29+
*/
1530
@ExperimentalReactiveApi
1631
fun <T> CartographyWindow.Builder.setView(provider: Provider<T>, transform: (T) -> CartographyWindow.View): CartographyWindow.Builder =
1732
setView(provider.map(transform))
1833

34+
/**
35+
* Sets the provider containing the view of the [CartographyWindow] built by this builder.
36+
* If [view] is not a [MutableProvider], attempting to change the view through other means will throw an exception.
37+
*/
1938
@ExperimentalReactiveApi
2039
fun CartographyWindow.Builder.setView(view: Provider<CartographyWindow.View>): CartographyWindow.Builder =
2140
setView(PropertyAdapter(view))

invui-kotlin/src/main/kotlin/xyz/xenondevs/invui/window/CrafterWindowExtensions.kt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,30 @@ import xyz.xenondevs.invui.ExperimentalReactiveApi
55
import xyz.xenondevs.invui.PropertyAdapter
66
import xyz.xenondevs.invui.gui.Slot
77

8+
/**
9+
* Sets the provider containing the disabled state of [slot] in the [CrafterWindow] built by this builder.
10+
*/
811
@ExperimentalReactiveApi
9-
fun CrafterWindow.Builder.setSlot(slot: Int, provider: MutableProvider<Boolean>): CrafterWindow.Builder =
10-
setSlot(slot, PropertyAdapter(provider))
12+
fun CrafterWindow.Builder.setSlot(slot: Int, state: MutableProvider<Boolean>): CrafterWindow.Builder =
13+
setSlot(slot, PropertyAdapter(state))
1114

15+
/**
16+
* Sets the provider containing the disabled state of the slot at [x], [y] in the [CrafterWindow] built by this builder.
17+
*/
1218
@ExperimentalReactiveApi
13-
fun CrafterWindow.Builder.setSlot(x: Int, y: Int, provider: MutableProvider<Boolean>): CrafterWindow.Builder =
14-
setSlot(x, y, PropertyAdapter(provider))
19+
fun CrafterWindow.Builder.setSlot(x: Int, y: Int, state: MutableProvider<Boolean>): CrafterWindow.Builder =
20+
setSlot(x, y, PropertyAdapter(state))
1521

22+
/**
23+
* Sets the provider containing the disabled state of [slot] in the [CrafterWindow] built by this builder.
24+
*/
1625
@ExperimentalReactiveApi
17-
fun CrafterWindow.Builder.setSlot(slot: Slot, provider: MutableProvider<Boolean>): CrafterWindow.Builder =
18-
setSlot(slot, PropertyAdapter(provider))
26+
fun CrafterWindow.Builder.setSlot(slot: Slot, state: MutableProvider<Boolean>): CrafterWindow.Builder =
27+
setSlot(slot, PropertyAdapter(state))
1928

29+
/**
30+
* Sets the providers containing the disabled states of all nine slots in the [CrafterWindow] built by this builder.
31+
*/
2032
@ExperimentalReactiveApi
21-
fun CrafterWindow.Builder.setSlots(slots: List<MutableProvider<Boolean>>): CrafterWindow.Builder =
22-
setSlots(slots.map { PropertyAdapter(it) })
33+
fun CrafterWindow.Builder.setSlots(states: List<MutableProvider<Boolean>>): CrafterWindow.Builder =
34+
setSlots(states.map { PropertyAdapter(it) })

0 commit comments

Comments
 (0)