Skip to content
Closed
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 @@ -107,7 +107,7 @@ public static AnvilInput createAnvilInput(
@ApiStatus.Experimental
public static AnvilInput createAnvilInput(@NotNull AnvilInputConfig config) {
final long id = State.next();
final StateValueFactory factory = (host, state) -> new AnvilInputStateValue(state, config);
final StateValueFactory factory = (host, state) -> new AnvilInputStateValue(id, config);

return new AnvilInput(id, factory);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package me.devnatan.inventoryframework;

import me.devnatan.inventoryframework.state.MutableValue;
import me.devnatan.inventoryframework.state.State;

class AnvilInputStateValue extends MutableValue {

private final AnvilInputConfig config;

public AnvilInputStateValue(State<?> state, AnvilInputConfig config) {
super(state, config.initialInput);
public AnvilInputStateValue(long internalId, AnvilInputConfig config) {
super(internalId, config.initialInput);
this.config = config;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package me.devnatan.inventoryframework;

public interface UpdateReason {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import java.util.Set;
import me.devnatan.inventoryframework.Ref;
import me.devnatan.inventoryframework.ViewContainer;
import me.devnatan.inventoryframework.VirtualView;
import me.devnatan.inventoryframework.context.IFComponentRenderContext;
import me.devnatan.inventoryframework.context.IFComponentUpdateContext;
import me.devnatan.inventoryframework.context.IFContext;
import me.devnatan.inventoryframework.context.IFSlotRenderContext;
import me.devnatan.inventoryframework.context.IFRenderContext;
import me.devnatan.inventoryframework.context.IFSlotClickContext;
import me.devnatan.inventoryframework.state.State;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand All @@ -30,12 +34,7 @@ public interface Component extends VirtualView {
@NotNull
VirtualView getRoot();

/**
* The current position of this component relative to its root view.
*
* @return The current position of this component.
*/
int getPosition();
ViewContainer getContainer();

/**
* Checks if this component is in a specific position.
Expand All @@ -53,34 +52,6 @@ public interface Component extends VirtualView {
*/
boolean intersects(@NotNull Component other);

/**
* The interaction handler for this component.
*
* @return The interaction handler for this component.
*/
InteractionHandler getInteractionHandler();

/**
* Renders this component to the given context.
*
* @param context The context that this component will be rendered on.
*/
void render(@NotNull IFSlotRenderContext context);

/**
* Called when this component is updated in the given context.
*
* @param context The update context.
*/
void updated(@NotNull IFSlotRenderContext context);

/**
* Clears this component from the given context.
*
* @param context The context that this component will be cleared from.
*/
void clear(@NotNull IFContext context);

/**
* An unmodifiable set of all states that this component is watching.
*
Expand Down Expand Up @@ -123,25 +94,6 @@ public interface Component extends VirtualView {
*/
void update();

/**
* Checks if two components area intersects with each other.
*
* @param component The component A.
* @param other The component B.
* @return If component B area conflicts with area of component A.
*/
static boolean intersects(@NotNull Component component, @NotNull Component other) {
if (component instanceof ComponentComposition) return intersects(other, component);

if (other instanceof ComponentComposition) {
for (final Component otherChildren : (ComponentComposition) other) {
if (otherChildren.intersects(component)) return true;
}
}

return other.isContainedWithin(component.getPosition());
}

/**
* Returns the reference assigned to this component.
* <p>
Expand Down Expand Up @@ -177,4 +129,32 @@ static boolean intersects(@NotNull Component component, @NotNull Component other
*/
@ApiStatus.Experimental
void hide();

/**
* Renders this component to the given context.
*
* @param context The context that this component will be rendered on.
*/
void render(@NotNull IFComponentRenderContext context);

/**
* Called when this component is updated in the given context.
*
* @param context The update context.
*/
void updated(@NotNull IFComponentUpdateContext context);

/**
* Clears this component from the given context.
*
* @param context The context that this component will be cleared from.
*/
void cleared(@NotNull IFRenderContext context);

/**
* Called when a viewer clicks in that component.
*
* @param context The click context.
*/
void clicked(@NotNull IFSlotClickContext context);
}
Original file line number Diff line number Diff line change
@@ -1,168 +1,18 @@
package me.devnatan.inventoryframework.component;

import java.util.function.BooleanSupplier;
import java.util.function.Predicate;
import me.devnatan.inventoryframework.Ref;
import me.devnatan.inventoryframework.context.IFContext;
import me.devnatan.inventoryframework.state.State;
import me.devnatan.inventoryframework.VirtualView;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

/**
* Builder base for any {@link Component} implementation.
*
* @param <S> The reference of the component builder itself used as return type for method chaining.
*/
public interface ComponentBuilder<S extends ComponentBuilder<S, C>, C extends IFContext> {
public interface ComponentBuilder {

/**
* Assigns {@link Ref a reference} to this component.
*
* @param reference Component reference key.
* @return This component builder.
* @see <a href="https://github.com/DevNatan/inventory-framework/wiki/refs-api">Refs API on Wiki</a>
*/
S referencedBy(@NotNull Ref<Component> reference);

/**
* Adds a new user-defined property to this component.
* <p>
* User-defined properties can be used to persist data that can be retrieved later even after
* several actions applied to that component.
* <p>
* An example of user-defined data persistence is for post-moving identification of a component
* inside the container, you can define a data in this item and as soon as the actor moves it
* the data will remain there, and you can use it any way you want.
*
* @param key The property key.
* @param value The property value.
* @return This component builder.
*/
S withData(@NotNull String key, Object value);

/**
* Determines whether an actor's click interaction event under this component should be canceled.
* <p>
* This method is a shortcut to:
* <pre>{@code
* onClick(click -> click.setCancelled(!click.isCancelled());
* }</pre>
*
* @return This component builder.
*/
S cancelOnClick();

/**
* Closes the current container when an actor interacts with this component.
* Builds a component from this component builder.
* <p>
* This function was created to support actions during closing to simplify code readability,
* it executes something and then closes or vice versa.
* <pre>{@code
* closeOnClick().onClick(click -> ...)
* }</pre>
* <p>
* This method is a shortcut to:
* <pre>{@code
* onClick(IFContext::close);
* }</pre>
*
* @return This component builder.
*/
S closeOnClick();

/**
* Watches one or more states.
* <p>
* When any of the states provided as parameters are modified, the item generated from this
* builder will be updated.
* <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>
*
* @param states The state to watch.
* @return This component builder.
* @deprecated Use {@link #updateOnStateChange(State)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "3.2.0")
S watch(State<?>... states);

/**
* Listens for value updates in the specified state.
* <p>
* Everytime the value of the given state updates, this component will be updated as well.
*
* @param state The state to listen changes to.
* @return This component builder.
*/
S updateOnStateChange(@NotNull State<?> state);

/**
* Listens for value updates in any of the specified states.
* <p>
* Everytime the value ANY of the given state updates, this component will be updated as well.
*
* @param state The state to listen changes to.
* @param states Other states to listen changes to.
* @return This component builder.
*/
S updateOnStateChange(@NotNull State<?> state, State<?>... states);

/**
* Returns a copy of this component builder.
*
* @return A copy of this component builder.
*/
S copy();

/**
* <p><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>
* @return A new component instance built from this component builder.
*/
@ApiStatus.Internal
S withExternallyManaged(boolean isExternallyManaged);

/**
* Updates the current context when a player clicks on this component.
*
* <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>
*
* @return This component builder.
*/
@ApiStatus.Experimental
S updateOnClick();

/**
* Only shows the component if a given condition is satisfied.
*
* @param displayCondition Component display condition.
* @return This component builder.
* @see #hideIf(BooleanSupplier)
*/
S displayIf(BooleanSupplier displayCondition);

/**
* Only shows the component if a given condition is satisfied.
*
* @param displayCondition Component display condition.
* @return This component builder.
* @see #hideIf(Predicate)
*/
S displayIf(Predicate<C> displayCondition);

/**
* Hides the component if a given condition is satisfied.
*
* @param condition Condition to hide the component.
* @return This component builder.
* @see #displayIf(BooleanSupplier)
*/
S hideIf(BooleanSupplier condition);

/**
* Hides the component if a given condition is satisfied.
*
* @param condition Condition to hide the component.
* @return This component builder.
* @see #displayIf(Predicate)
*/
S hideIf(Predicate<C> condition);
Component build(VirtualView root);
}

This file was deleted.

Loading