ui: experimental, opted into with experimental = ["ui"] in the manifest

docs/api/stability.md: a new API starts experimental, usable only by
opting in with a manifest field naming it. Capability ui now needs
experimental = ["ui"] beside capabilities; without it the manifest is
refused with that line to add. A capability promoted later stays
accepted in the list, so such manifests keep loading.

The ui test guest opts in; stability.md gets ui's row; docs/mods.md
shows the key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-25 20:57:10 +01:00
parent f2832f83ef
commit 05396b4edf
4 changed files with 45 additions and 2 deletions
+38
View File
@@ -49,6 +49,12 @@ pub struct Manifest {
/// that are on may share one (`content::clash`).
#[serde(default)]
pub namespaces: Vec<String>,
/// The experimental capabilities the mod opts into (`["ui"]`): each one
/// it lists in `capabilities` must be named here too, since it may change
/// in any release (docs/api/stability.md). One no longer experimental is
/// accepted here, so the manifest keeps loading once it is promoted.
#[serde(default)]
pub experimental: Vec<Capability>,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq)]
@@ -99,6 +105,11 @@ impl Capability {
Capability::Ui => "ui",
}
}
/// May change in any release: a mod uses it only with
/// `experimental = ["<name>"]` in its manifest.
pub fn is_experimental(self) -> bool {
matches!(self, Capability::Ui)
}
/// What the player reads before turning the mod on: "May <this>".
pub fn describe(self) -> &'static str {
match self {
@@ -169,6 +180,16 @@ impl Manifest {
"{MANIFEST}: capability registries needs api = \"0.2\""
));
}
if let Some(c) = m
.capabilities
.iter()
.find(|c| c.is_experimental() && !m.experimental.contains(c))
{
return Err(format!(
"{MANIFEST}: capability {c} is experimental and may change in any release: \
add experimental = [\"{c}\"] to use it"
));
}
if !m.namespaces.is_empty() && !m.capabilities.contains(&Capability::Registries) {
return Err(format!(
"{MANIFEST}: namespaces are for content, which needs capability registries"
@@ -421,4 +442,21 @@ capabilities = ["game-read", "hud"]
assert_eq!(p.wasm.as_deref(), Some(&b"\0asm"[..]));
std::fs::remove_dir_all(&dir).unwrap();
}
#[test]
fn experimental_capabilities_need_the_opt_in() {
let base = "id = \"m\"\nname = \"M\"\nversion = \"1\"\napi = \"0.1\"\n";
let err = Manifest::parse(&format!("{base}capabilities = [\"ui\"]\n")).unwrap_err();
assert!(err.contains("experimental = [\"ui\"]"), "{err}");
let m = Manifest::parse(&format!(
"{base}capabilities = [\"ui\"]\nexperimental = [\"ui\"]\n"
))
.unwrap();
assert_eq!(m.experimental, [Capability::Ui]);
// A capability that is (or became) stable is fine in the list.
Manifest::parse(&format!(
"{base}capabilities = [\"hud\"]\nexperimental = [\"hud\"]\n"
))
.unwrap();
}
}
+1
View File
@@ -23,6 +23,7 @@ name = "Test UI Guest"
version = "0.1.0"
api = "0.1"
capabilities = ["chat", "ui"]
experimental = ["ui"]
"#;
/// Builds both mods once and writes their `.hmod` files; returns the folder.
+1
View File
@@ -87,6 +87,7 @@ Deprecations and breaking changes are in bold. The release notes of the game rel
| Part | Level | Version |
| --- | --- | --- |
| Mod API: `log`, `game`, `chat`, `hud`, `storage`, `events` | preview | 0.1.0 |
| Mod API: `ui`, `ui-events` (a mod's screens and settings page) | experimental | manifest `experimental = ["ui"]` |
| Content mods (`registries`: data-driven blocks and items) | preview | manifest `api = "0.2"` |
| Server mods (events, world, server commands) | not started | manifest `api = "0.3"`, experimental first |
| Script mods (Lua run by an interpreter mod, [mods.md](mods.md#ways-in)) | not started | |
+5 -2
View File
@@ -86,7 +86,7 @@ folder, loads no runtime and plays exactly like vanilla 26.3.
| `chat` | `chat` | `show(text)`: a line only the local player sees, after the mod's name (8 per call) |
| `hud` | `hud` | `set-panel(corner, lines)`, `clear()`: up to 16 lines of 256 characters |
| `storage` | `storage` | `get(key)`, `set(key, value)`, `delete(key)`: a per-mod folder of up to 64 files, 4 MiB total, at most 1 MiB written per call |
| `ui` | `ui` | `open-screen`, `close-screen`, `set-settings`: a screen the mod owns and a page in Options > Mods, of text, item and list widgets the game lays out and draws with its own menus' code |
| `ui` | `ui` | `open-screen`, `close-screen`, `set-settings`: a screen the mod owns and a page in Options > Mods, of text, item and list widgets the game lays out and draws with its own menus' code. **Experimental:** the manifest needs `experimental = ["ui"]` |
| Hook (export) | When |
|---|---|
@@ -284,10 +284,13 @@ authors = ["..."]
api = "0.1" # the API the SDK targets
side = "client" # client | server | both
capabilities = ["game-read", "hud", "chat"]
experimental = [] # experimental capabilities it uses, e.g. ["ui"]
```
Unknown keys are refused, so a typo is an error, not a silently ignored
permission.
permission. An experimental capability (today `ui`) may change in any release
([stability](api/stability.md)): a mod uses it only by naming it in
`experimental` as well, so nobody depends on it by accident.
### Content mods (API 0.2)