.findFirst()
.orElseThrow(() -> new InventoryFrameworkException("Missing layout character: " + character));
getLayoutSlots().add(layoutSlot.withFactory(index -> {
final ITEM_BUILDER builder = createBuilder();
factory.accept(index, builder);
return (ComponentFactory) builder;
}));
}
/**
* Defines the item that will represent a character provided in the context layout.
*
* @param character The layout character target.
* @return An item builder to configure the item.
*/
public @NotNull <BUILDER extends ComponentBuilder, COMPONENT extends PlatformComponent<CONTEXT, BUILDER>>
BUILDER layoutComponent(char character, COMPONENT component) {
requireNonReservedLayoutCharacter(character);
// TODO More detailed exception message
final LayoutSlot layoutSlot = getLayoutSlots().stream()
.filter(value -> value.getCharacter() == character)
.findFirst()
.orElseThrow(() -> new InventoryFrameworkException("Missing layout character: " + character));
// FIXME Missing implementation
final BUILDER builder = null;
// final BUILDER builder = component.createBuilder();
getLayoutSlots().add(layoutSlot.withFactory($ -> (ComponentFactory) builder));
return builder;
}
/**
* <p><b><i> This API is experimental and is not subject to the general compatibility guarantees
* such API may be changed or may be removed completely in any further release. </i></b>
*/
@ApiStatus.Experimental
public final @NotNull ITEM_BUILDER resultSlot() {
final ViewType containerType = getContainer().getType();
final int[] resultSlots = containerType.getResultSlots();
if (resultSlots == null) throw new InventoryFrameworkException("No result slots available: " + containerType);
if (resultSlots.length > 1)
throw new InventoryFrameworkException("#resultSlot() do not support types with more than one result slot.");
return slot(resultSlots[0]);
}
/**
* Renders a new component in that context.
* <p>
* <b><i> This API is experimental and is not subject to the general compatibility guarantees
* such API may be changed or may be removed completely in any further release. </i></b>
*
* @param component The component to be rendered.
*/
@ApiStatus.Experimental
public void component(@NotNull Component component) {}
// endregion
@Override
public final @NotNull UUID getId() {
return id;
}
@Override
public final @NotNull ViewContainer getContainer() {
return container;
}
@Override
public final @NotNull ViewConfig getConfig() {
return config;
}
@Override
public final @NotNull Map<String, Viewer> getIndexedViewers() {
return viewers;
}
@Override
public final Object getInitialData() {
return initialData;
}
@Override
public void setInitialData(Object initialData) {
this.initialData = initialData;
}
@Override
public final Viewer getViewer() {
return subject;
}
@Override
public final @NotNull @UnmodifiableView List<ComponentBuilder> getNotRenderedComponents() {
return Collections.unmodifiableList(componentBuilders);
}
@Override
public final @NotNull List<LayoutSlot> getLayoutSlots() {
return layoutSlots;
}
@Override
public final void addLayoutSlot(@NotNull LayoutSlot layoutSlot) {
layoutSlots.add(layoutSlot);
}
@Override
public final List<BiFunction<Integer, Integer, ComponentBuilder>> getAvailableSlotFactories() {
return availableSlotFactories;
}
@Override
public final void closeForPlayer() {
tryThrowDoNotWorkWithSharedContext("closeForEveryone()");
super.closeForPlayer();
}
@Override
public final void openForPlayer(@NotNull Class<? extends RootView> other) {
tryThrowDoNotWorkWithSharedContext("openForEveryone(Class)");
super.openForPlayer(other);
}
@Override
public final void openForPlayer(@NotNull Class<? extends RootView> other, Object initialData) {
tryThrowDoNotWorkWithSharedContext("openForEveryone(Class, Object)");
super.openForPlayer(other, initialData);
}
@Override
public final void updateTitleForPlayer(@NotNull String title) {
tryThrowDoNotWorkWithSharedContext("updateTitleForEveryone(String)");
super.updateTitleForEveryone(title);
}
@Override
public final void resetTitleForPlayer() {
tryThrowDoNotWorkWithSharedContext("resetTitleForEveryone()");
super.resetTitleForPlayer();
}
@Override
public final boolean isRendered() {
return rendered;
}
// region Internals
/**
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*/
@ApiStatus.Internal
public final void setRendered() {
this.rendered = true;
}
@Override
public final void renderComponent(@NotNull Component component) {
if (!component.shouldRender(this)) {
component.setVisible(false);
final Optional<Component> overlapOptional = getOverlappingComponentToRender(this, component);
if (overlapOptional.isPresent()) {
Component overlap = overlapOptional.get();
renderComponent(overlap);
if (overlap.isVisible()) return;
}
component.cleared(this);
clearComponent(component);
return;
}
component.render(createComponentRenderContext(component, false));
}
@Override
public final void updateComponent(Component component, boolean force, UpdateReason reason) {
component.updated(createComponentUpdateContext(component, force, reason));
}
@Override
public final void clearComponent(@NotNull Component component) {}
/**
* Creates a IFComponentRenderContext for the current platform.
*
* @param component The component.
* @param force If the context was created due to usage of forceRender().
* @return A new IFComponentRenderContext instance.
*/
@ApiStatus.Internal
abstract IFComponentRenderContext createComponentRenderContext(Component component, boolean force);
/**
* Creates a IFComponentUpdateContext for the current platform.
*
* @param component The component.
* @param force If the context was created due to usage of forceUpdate().
* @param reason Reason why this component was updated.
* @return A new IFComponentUpdateContext instance.
*/
@ApiStatus.Internal
abstract IFComponentUpdateContext createComponentUpdateContext(
Component component, boolean force, UpdateReason reason);
/**
* Creates a new platform builder instance.
*
* @return A new platform builder instance.
*/
// TODO use ElementFactory's `createBuilder` instead
protected abstract ITEM_BUILDER createBuilder();
/**
* Creates a new platform builder instance and registers it.
*
* @return A new registered platform builder instance.
*/
protected final ITEM_BUILDER createRegisteredBuilder() {
final ITEM_BUILDER builder = createBuilder();
componentBuilders.add(builder);
return builder;
}
/**
* Creates a new platform builder instance and registers it.
*
* @return A new registered platform builder instance.
*/
protected final ITEM_BUILDER createRegisteredBuilderInPosition(int position) {
final ITEM_BUILDER builder = createBuilder();
builder.setPosition(position);
componentBuilders.add(builder);
return builder;
}
https://github.com/DevNatan/inventory-framework/blob/ea9b4baa26e76b7f413bd316b97af2b0b34e6b3b/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/context/PlatformRenderContext.java#L237