Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import me.devnatan.inventoryframework.ViewConfigBuilder;
import me.devnatan.inventoryframework.context.RenderContext;
import me.devnatan.inventoryframework.state.MutableIntState;
import me.devnatan.inventoryframework.state.MutableState;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

public class RowColumnSample extends View {

private final MutableIntState intState = mutableState(0);
private final MutableIntState intState = mutableState(0);

@Override
public void onInit(@NotNull ViewConfigBuilder config) {
Expand All @@ -20,16 +19,15 @@ public void onInit(@NotNull ViewConfigBuilder config) {

@Override
public void onFirstRender(@NotNull RenderContext render) {
render.slot(13)
.withItem(intState.get(render) == 3 ? new ItemStack(Material.GOLD_INGOT) : new ItemStack(Material.IRON_INGOT));
render.slot(13)
.withItem(
intState.get(render) == 3
? new ItemStack(Material.GOLD_INGOT)
: new ItemStack(Material.IRON_INGOT));

render.firstRow((pos, slot) ->
slot.withItem(new ItemStack(Material.BLUE_STAINED_GLASS_PANE))
.onClick(click -> intState.increment(click))
);
render.firstRow((pos, slot) -> slot.withItem(new ItemStack(Material.BLUE_STAINED_GLASS_PANE))
.onClick(click -> intState.increment(click)));

render.lastColumn((pos, slot) ->
slot.withItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE))
);
render.lastColumn((pos, slot) -> slot.withItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public <T> boolean isOptionSet(@NotNull Option<T> option) {
return false;
}

// TODO docs
@SuppressWarnings("unused")
@VisibleForTesting
public <T> boolean isOptionSet(@NotNull Option<T> option, T value) {
Expand All @@ -145,7 +144,6 @@ public static <T> Option<T> createOption(@NotNull String name, @NotNull T defaul
public ViewConfig merge(ViewConfig other) {
if (other == null) return this;

// TODO merge "options" and "modifiers" from both, distinctly
return new ViewConfig(
merge(other, ViewConfig::getTitle, Objects::nonNull),
merge(other, ViewConfig::getSize, value -> value != 0),
Expand All @@ -169,7 +167,6 @@ private <T> T merge(ViewConfig other, Function<ViewConfig, T> retriever, Functio
return value;
}

// TODO docs
@SuppressWarnings("unused")
@FunctionalInterface
public interface Modifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,14 @@ public ViewConfigBuilder size(int size) {
return this;
}

// TODO needs documentation
/**
* Expands the size of the inventory to the max permitted by {@link #getType() its type}.
*
* @return This configuration builder.
* @see ViewType#getMaxSize()
*/
public ViewConfigBuilder maxSize() {
throw new UnsupportedOperationException("TODO");
return size(Integer.MAX_VALUE);
}

/**
Expand Down Expand Up @@ -278,9 +283,11 @@ public ViewConfig build() {
option, option.defaultValue()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

final int size = getSize() == Integer.MAX_VALUE ? getType().getMaxSize() : getSize();

return new ViewConfig(
getTitle(),
getSize(),
size,
getType(),
optionsMap,
getLayout(),
Expand Down
Loading