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
@@ -1,6 +1,12 @@
package me.devnatan.inventoryframework;

import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
Expand All @@ -12,6 +18,7 @@ abstract class IFViewFrame<S extends IFViewFrame<S, V>, V extends PlatformView<S
private boolean registered;
protected final Map<UUID, V> registeredViews = new HashMap<>();
protected final Map<String, Viewer> viewerById = new HashMap<>();
protected Consumer<ViewConfigBuilder> defaultConfig;

protected IFViewFrame() {}

Expand Down Expand Up @@ -140,4 +147,29 @@ void removeViewer(@NotNull Viewer viewer) {
viewerById.remove(viewer.getId());
}
}

/**
* Sets the default configuration that will be used for all views registered from this framework.
* <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 framework instance.
* @see <a href="https://github.com/DevNatan/inventory-framework/wiki/basic-usage#default-configuration">Default Configuration on Wiki</a>
*/
@SuppressWarnings("unchecked")
@ApiStatus.Experimental
public final S defaultConfig(@NotNull Consumer<ViewConfigBuilder> defaultConfig) {
this.defaultConfig = defaultConfig;
return (S) this;
}

/**
* The default configuration applier of this framework.
*
* @return The default configuration applier of this framework.
*/
final Consumer<ViewConfigBuilder> getDefaultConfig() {
return defaultConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,17 @@ public final void navigateTo(
getFramework().getRegisteredViewByType(target).open(Collections.singletonList(viewer), initialData);
}

/**
* Creates a new ViewConfigBuilder instance with the default platform configuration.
* Configuration is inherited from the {@link #getFramework() framework} if available.
*
* @return A new ViewConfigBuilder instance.
*/
public final @NotNull ViewConfigBuilder createConfig() {
return new ViewConfigBuilder().type(ViewType.CHEST);
final ViewConfigBuilder configBuilder = new ViewConfigBuilder().type(ViewType.CHEST);
if (getFramework().getDefaultConfig() != null)
getFramework().getDefaultConfig().accept(configBuilder);
return configBuilder;
}

/**
Expand Down