SomeSourceCode / SomeGuiApi

A Paper API to create interactable GUIs using Minecraft Inventories, ...
MIT License
1 stars 0 forks source link

Implement node ids #15

Closed SomeSourceCode closed 3 months ago

SomeSourceCode commented 3 months ago

Description

Introduces node ids as requested in #2. Every Node can now be assigned a String id. This id can be unique, although this uniqueness is not enforced. To find a node, Node#lookup(String selector) can be used, which looks for the first node matching the selector. Note that in order to find a node by its id, the id has to be prefixed with a hashtag (#). To retrieve a set of all Nodes matching the selector Node#lookupAll(String selector) can be used. For convenience, these methods also exist in the Scene class, where they are identical to calling them on the scene root.

The prefix is technically not needed, but was still implemented so that selectors can be expanded in the future to not just be limited to ids.

Code Example

// Assign an id:
node.setId("my-id");
// Lookup by an id:
Node result = scene.lookup("#my-id");
// Lookup all nodes with the id:
Set<Node> results = scene.lookupAll("#my-id");