mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Document the command api of com.volmit.tooling
This commit is contained in:
1 parent
fc81e54b0c
commit
c61865b9f2
3 files changed
+69
No files matched your search
@@ -46,6 +46,7 @@ types that carry them and lists what the Iris adapter still owes.
|
||||
| Positions, boxes and faces | `com.volmit.geometry`: `BlockPosition`, `BlockBox`, `BlockFace` |
|
||||
| Sparse geometry | `GeneratedObject` |
|
||||
| Studio views of what a module builds | `com.volmit.tooling`: `ModuleSetup.tooling()` (`ToolingRegistry.registerView`), sealed `StudioView` (`SceneView` with `SceneEntry`, `PatternView` with `PatternEntry`, `PatternArea`, `BlockPattern`), `EditableSceneView` (`SceneFile`, `NodeGraph`, `GraphNode` with `Link`, `NodeSettings`, `Edits`, `Addition`), `JsonText`, `JsonPath` (`Key`, `Index`), host `StudioViewRegistration` |
|
||||
| Commands of a module | `com.volmit.tooling`: `ToolingRegistry.registerCommand`, immutable `Command` (`named`, `alias`, `describe`, `child`, `argument`, `runs`, `openToEveryone`), typed `Argument` (`word`, `text`, `integer`, `decimal`, `flag`, `choice`, `resource`, `registered`, `orElse`, `suggesting`), `CommandAction`, `CommandContext` (`get`, `sender`, `pack`, `world`, `platform`), plain-text `Sender`, `ToolPack` (`edit` with `PackEdit`, `outputFolder`, `objects` with `ObjectCodec`), host `CommandRegistration` in `FeatureCatalog.commands()` |
|
||||
| Buffered placement writes | `PlacementRequest`, `PlacementAccess`, host-owned `PlacementEdit` |
|
||||
| Typed generation and persistent storage | `mantle` package |
|
||||
|
||||
|
||||
@@ -1367,6 +1367,31 @@ API now: `world.running()`, `world.seed(purpose)`, `TerrainSampler`, `FeatureSet
|
||||
- **The wire is the host's.** The studio protocol may encode an absent part or block as it likes (Iris sends `-1`);
|
||||
the API types say absent with `Optional`/`OptionalInt`.
|
||||
|
||||
## Commands
|
||||
|
||||
`ToolingRegistry.registerCommand` mounts a module's `Command` below the host's command root. The api holds the tree and
|
||||
the typed arguments; parsing, completion, permission and threads are the host's.
|
||||
|
||||
- **A tree, not a platform's commands.** The same `Command` runs on Bukkit and on modded hosts. Nothing in it names a
|
||||
player, a position or a colour; a platform part reaches the platform's own sender through `Sender.extension`. Argument
|
||||
values are the neutral types of the api (`ResourceId`, an enum, a number), so a module's action never parses text.
|
||||
- **The host resolves the pack, not the module.** Commands, completions and classes belong to one pack's module set, so
|
||||
the host picks the pack first (`pack=<name>`, the sender's world, the sender's open studio) and only then walks the
|
||||
tree. One rule serves every module; a module never declares a pack argument.
|
||||
- **Workers, not the main thread.** An action may read and write files and wait, so the host runs it off the server's
|
||||
threads. To touch the world it asks the platform for the right thread through a part.
|
||||
- **One door for writes.** `ToolPack.edit` holds the pack against other edits and against a hotload, then reloads the
|
||||
resources once. The host gives that guarantee; the module keeps the atomicity of its own multi-file writes, as a
|
||||
journal over a `Path`. `outputFolder()` keeps exports out of the pack. A `Path` is honest here because tools are file
|
||||
tools; generation still never sees one.
|
||||
- **The object format is the host's.** `ObjectCodec` lets a tool stage object files inside its own transaction instead of
|
||||
asking the host to write at once.
|
||||
- **Plain messages.** Info, success and error are three lines the host styles; a module that ships translations needs an
|
||||
api for them, which does not exist yet.
|
||||
- **Names are checked early.** `Command` rejects bad names, duplicate children and aliases, an optional argument before a
|
||||
required one, and anything after a rest-of-line argument when the tree is built. Two modules claiming one root name or
|
||||
alias fail the pack load, naming both.
|
||||
|
||||
## Not implemented
|
||||
|
||||
- Host wiring, which lives in Iris: JSON decoding and validation, rendering `PackSchema` into Iris's schema and
|
||||
|
||||
@@ -505,6 +505,49 @@ final class RuinScenes implements SceneView {
|
||||
- Absent values are empty, never blank or `-1`: an entry without a group, a node that draws no part of the scene
|
||||
(`GraphNode.part()`), a column a pattern places nothing at (`BlockPattern.pickAt`).
|
||||
|
||||
## Commands
|
||||
|
||||
A module adds commands to the host's command root, such as `/iris structure list`, with `registerCommand`. The same
|
||||
`Command` runs on every platform; the host parses it, completes it and runs it.
|
||||
|
||||
```java
|
||||
private static final Argument<ResourceId> STRUCTURE = Argument.resource("structure", RuinResources.STRUCTURES);
|
||||
private static final Argument<Long> RADIUS = Argument.integer("radius", 1, 1000).orElse(48L);
|
||||
|
||||
public void setup(ModuleSetup setup) {
|
||||
setup.tooling().registerCommand(Command.named("ruins").alias("rn")
|
||||
.describe("Ruin tools")
|
||||
.child(Command.named("info").argument(STRUCTURE).runs(this::info))
|
||||
.child(Command.named("scan").argument(RADIUS).runs(this::scan)));
|
||||
}
|
||||
|
||||
private void info(CommandContext context) {
|
||||
context.sender().info("Ruin " + context.get(STRUCTURE));
|
||||
}
|
||||
```
|
||||
|
||||
- `Command` is immutable: `named`, `alias`, `describe`, `child`, `argument`, `runs` and `openToEveryone` each return a
|
||||
changed copy. A word that names a sub-command always selects it. A command with no action only lists its children.
|
||||
- Arguments are typed: `word`, `text` (the rest of the line, last only), `integer`, `decimal`, `flag`, `choice` (an enum
|
||||
constant written in lower case with `-`), `resource` (an id of a `ResourceKind` in the pack) and `registered` (an id in
|
||||
one of the platform's registries, by `Reference`). `orElse` makes an argument optional; an optional argument may not
|
||||
come before a required one. `suggesting` adds completions. Read a value with `context.get(argument)`.
|
||||
- The host resolves the pack before it parses the line: `pack=<name>` taken out of the arguments, else the pack of the
|
||||
sender's world, else the pack of the sender's open studio, else it fails with `Name a pack: pack=<name>`. A command
|
||||
exists only for packs whose jars contain its module. `context.pack()` is that pack, `context.world()` the sender's
|
||||
world when it generates with it, and `context.platform()` the platform's registries.
|
||||
- An action runs on a worker thread, never the server's main thread or a region thread, so it may block. What it throws
|
||||
reaches the sender as an error and the module's log. `Sender` messages are plain text; the host styles them as
|
||||
information, success or error, and delivers them on the thread the platform needs. There is no colour and no
|
||||
translation.
|
||||
- By default only operators run a command (Bukkit `iris.all`, game master on modded); `openToEveryone()` lifts that.
|
||||
- `ToolPack` is the pack as a tool sees it. `edit` is the only way to change its files: one edit runs at a time per pack,
|
||||
the host does not hotload during it, and it reloads the resources once after the edit returns normally. Atomicity across
|
||||
files is the edit's own job. `outputFolder()` is a folder outside the pack for what tools produce, and `objects()` reads
|
||||
and writes pack objects in the host's object format (`ObjectCodec`).
|
||||
- A root command's name and each alias are root names. One that another module of the pack took fails the pack load,
|
||||
naming both modules. A host without commands, such as a build check, accepts the registration and ignores it.
|
||||
|
||||
## Module jars
|
||||
|
||||
A pack loads its modules from `<pack>/modules/*.jar`. A jar holds one or more modules. Each module's
|
||||
|
||||
Reference in new issue
Block a user