Editor Resources
Use GraphResource when a graph should be edited as an LDLib2 Editor resource.
This is the recommended setup for user-authored graph assets. It gives the graph a resource-panel entry, a default NBT resource shape, a GraphEditorView, save handling, subgraph dive, and external subgraph resolution.
Define a Graph Resource
public class TestGraphResource extends GraphResource<TestGraph> {
public static final TestGraphResource INSTANCE = new TestGraphResource();
@Override
public TestGraph createGraph() {
return new TestGraph();
}
}GraphResource stores graph data as CompoundTag. A new resource is created from createGraph().graphModel.serializeNBT(...).
Add It to a Project
Expose the graph resource from your editor project:
private final Resources resources = Resources.of(
TestGraphResource.INSTANCE
);
@Override
public Resources getResources() {
return resources;
}The editor resource panel will use GraphResourceProviderContainer.
Open and Save
GraphResourceProviderContainer opens a GraphEditorView for a graph resource.
The editor flow is:
GraphEditorView tracks dirty state by comparing serialized graph NBT against the saved snapshot.
The save button writes the current graph back through the callback supplied by the resource container.
GraphEditorView also owns subgraph navigation. When a user enters a subgraph, it creates another GraphView through the same factory, updates the breadcrumb, and preserves the root editor save workflow.
Read-only Graphs
Since 2.2.38A graph resource whose provider cannot edit it, such as a built-in resource, still opens. GraphResourceProviderContainer opens it in a read-only GraphEditorView:
- the save button is hidden and the view never becomes dirty,
- subgraphs entered from it are read-only too,
- the resource's context menu shows View instead of Edit.
Users who want to change such a graph pick Copy in the resource's context menu. The Copy Resource To dialog lets them choose a writable provider and a name. The copy is an ordinary resource of that provider and opens for editing. See Resource Providers for the copy dialog.
For a custom editor flow, call GraphEditorView.setReadOnly(true) before loadGraph(...). See GraphView read-only views for what is disabled.
Custom GraphView Factory
Override getGraphViewFactory() to use a custom GraphView subclass.
@Override
public Supplier<? extends GraphView> getGraphViewFactory() {
return MyGraphView::new;
}The factory is used for the root graph view and for subgraph dive views.
External Subgraph Resolution
When a graph is opened from a resource, the container installs an IGraphReferenceResolver on the graph model.
The resolver can:
- resolve a referenced graph resource path into a fresh
Graph, - save an external subgraph when editing through a dive-in view,
- identify the source
GraphResource.
This is required for external subgraph nodes to rebuild their port shape from the referenced graph.
Graph resources can also be dragged from the resource panel onto an open graph canvas. GraphView imports the dropped resource as an external subgraph node that stores the resource path. See Subgraphs.