[PR #1963] [MERGED] Mod API: what the extras need as mods: corner panels, frame stats, key state, buttons #3890

Closed
opened 2026-11-03 04:13:03 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1963
Author: @ludovic111
Created: 10/25/2026
Status: ✅ Merged
Merged: 10/26/2026
Merged by: @ludovic111

Base: main ← Head: feat/mod-api-extras


📝 Commits (3)

  • e3bd626 Mod API: what the extras need as mods: corner panels, frame stats, mappings, buttons
  • c28bea8 Mod API: input's permission line says it sees keys and clicks
  • 50c5409 Merge feat/mod-input (with main) into feat/mod-api-extras

📊 Changes

12 files changed (+451 additions, -62 deletions)

View changed files

📝 crates/cargo-horizon-mod/src/check.rs (+1 -1)
📝 crates/horizon-client/src/game/extras.rs (+18 -2)
📝 crates/horizon-client/src/game/mod_render.rs (+18 -10)
📝 crates/horizon-client/src/game/mods.rs (+97 -5)
📝 crates/horizon-mod-sdk/wit/horizon.wit (+52 -0)
📝 crates/horizon-mods/src/manifest.rs (+3 -1)
📝 crates/horizon-mods/src/runtime.rs (+111 -28)
📝 crates/horizon-mods/tests/sandbox.rs (+43 -3)
📝 crates/horizon-mods/tests/ui_guest/src/lib.rs (+58 -6)
📝 docs/api/mods-reference.md (+45 -3)
📝 docs/api/mods.md (+2 -0)
📝 docs/mods.md (+3 -3)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Stacked on #1944 (input), itself on #1929 (render) and #1864 (ui). Review the last two commits, e3bd62668 and c28bea8e9. Until the others merge, the diff also shows their commits.

The extras are becoming official mods in the registry. This PR adds the calls the FPS counter and the keystrokes overlay need to look and behave exactly as the built-in extras do. The mods themselves come in the next PR, stacked on this one.

What a modder can do now

All of it is experimental, under the existing render, input and ui opt-ins.

// A box in a corner, placed by the game like its own overlays.
let text = format!("{} fps", render::frame_stats().fps);
let w = render::text_width(&text) + 4.0;
// shapes: a Fill of the whole box and a Text at (2, 2), relative to the box.
render::set_corner(Corner::TopLeft, w, 12.0, &shapes);

// Live key state, by mapping, with the player's own bindings.
if let Some(m) = input::mapping("key.forward") { /* m.label = "W", m.down */ }
let (left, right) = input::clicks_per_second();

// A button on the settings page.
ui::set_settings(&[Widget::Button(ButtonWidget { id: 1, label: "Corner: Top left".into() })]);
  • render.set-corner(corner, width, height, shapes) / clear-corner(). The mod sends one box, in GUI pixels, and the game places it in that corner with its own stacking: under the status effects at the top right, beside the extras and other mods' panels, never on top of them.
  • render.text-width(text). The text's width in the HUD font, so a mod can size boxes and centre text the way the game does.
  • render.frame-stats(). The game's frame counter: frames in the last second, the slowest frame and the 1% low.
  • input.mapping(name). For the movement, jump, sneak, sprint, attack and use mappings: the bound key's label and whether it is held.
  • input.clicks-per-second(). Attack and use clicks in the last second.
  • ui button widget. 200 × 20, vanilla's button; a click is select(id, 0).

How it works

  • The game keeps its FPS and click counters running while a mod runs, even with the extras off. For mods with a frame hook, it refreshes the snapshot every frame, so key state is never a tick late.
  • Corner panels go through extras_hud::Corners, the same placement the built-in overlays use.
  • No mod running, no cost: every new path sits behind mods.running() / wants_frames(). Without the mods feature it isn't compiled.
  • The input permission line now reads "see the keys you hold and your clicks, take over the use button on its own items, and add keys". The keystrokes mod uses input only to read, and players should be told that.

How tested

  • cargo test -p horizon-mods --features runtime,pack: new corner_panels_text_width_and_readings (the panel, its clipping, text width, frame stats, mappings and CPS from the snapshot); the ui test covers the button.
  • In game (--features mods, fresh HORIZON_HOME and XDG folders, HORIZON_NO_AUDIO=1), in-frame and on the server thread, 5/5 each:
    • The test guest's corner panel is drawn.
    • /readings answers live FPS, forward W true while W is held, and CPS.
    • The settings page shows the button, and a click on it is select(3, 0).
    • No panic.
  • The official FPS and keystrokes mods built on this (next PR) match the built-in extras pixel for pixel; that PR has the screenshots and the frame-time A/B.
  • python3 tools/parity.py --changed fada66031: 27 passed, 0 failed (33 min, the Mac mini).

Self-check (against #1944's head):

pr_ready (tools/pr_ready.py --quick --base fada66031 on ludovics-mac-mini, against fada66031 at fada66031, 12 min 20 s)

Check Result
Scope ✅ 11 files, +447 −60
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (18 s)
clippy ✅ (1 min 28 s)
tests: cargo-horizon-mod, horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest ✅ 1284 passed (9 min 17 s)
doc tests ✅ 1 passed (8 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (2 s)
launcher clippy ✅ (1 s)
launcher tests ✅ 126 passed (5 s)
Parity ✅ 24 affected (27 harnesses): 27 passed locally

(c28bea8e9, the permission-line wording, came after this run. It changes one string and the generated reference; api_reference and manifest tests pass.)

Label skip-release: experimental and opt-in. Players see no change until a mod uses it.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/1963 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/mod-api-extras` --- ### 📝 Commits (3) - [`e3bd626`](https://github.com/horizon-rust/horizon/commit/e3bd6266884838537ed7579f3a9b58c7adbc1127) Mod API: what the extras need as mods: corner panels, frame stats, mappings, buttons - [`c28bea8`](https://github.com/horizon-rust/horizon/commit/c28bea8e96cdf9ec7db298295664626926cb63f1) Mod API: input's permission line says it sees keys and clicks - [`50c5409`](https://github.com/horizon-rust/horizon/commit/50c54098ef6a8fce39f096a71ab571509360cb3d) Merge feat/mod-input (with main) into feat/mod-api-extras ### 📊 Changes **12 files changed** (+451 additions, -62 deletions) <details> <summary>View changed files</summary> 📝 `crates/cargo-horizon-mod/src/check.rs` (+1 -1) 📝 `crates/horizon-client/src/game/extras.rs` (+18 -2) 📝 `crates/horizon-client/src/game/mod_render.rs` (+18 -10) 📝 `crates/horizon-client/src/game/mods.rs` (+97 -5) 📝 `crates/horizon-mod-sdk/wit/horizon.wit` (+52 -0) 📝 `crates/horizon-mods/src/manifest.rs` (+3 -1) 📝 `crates/horizon-mods/src/runtime.rs` (+111 -28) 📝 `crates/horizon-mods/tests/sandbox.rs` (+43 -3) 📝 `crates/horizon-mods/tests/ui_guest/src/lib.rs` (+58 -6) 📝 `docs/api/mods-reference.md` (+45 -3) 📝 `docs/api/mods.md` (+2 -0) 📝 `docs/mods.md` (+3 -3) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **Stacked on #1944** (`input`), itself on #1929 (`render`) and #1864 (`ui`). Review the last two commits, e3bd62668 and c28bea8e9. Until the others merge, the diff also shows their commits. The extras are becoming official mods in the registry. This PR adds the calls the FPS counter and the keystrokes overlay need to look and behave exactly as the built-in extras do. The mods themselves come in the next PR, stacked on this one. ## What a modder can do now All of it is experimental, under the existing `render`, `input` and `ui` opt-ins. ```rust // A box in a corner, placed by the game like its own overlays. let text = format!("{} fps", render::frame_stats().fps); let w = render::text_width(&text) + 4.0; // shapes: a Fill of the whole box and a Text at (2, 2), relative to the box. render::set_corner(Corner::TopLeft, w, 12.0, &shapes); // Live key state, by mapping, with the player's own bindings. if let Some(m) = input::mapping("key.forward") { /* m.label = "W", m.down */ } let (left, right) = input::clicks_per_second(); // A button on the settings page. ui::set_settings(&[Widget::Button(ButtonWidget { id: 1, label: "Corner: Top left".into() })]); ``` - **`render.set-corner(corner, width, height, shapes)` / `clear-corner()`.** The mod sends one box, in GUI pixels, and the game places it in that corner with its own stacking: under the status effects at the top right, beside the extras and other mods' panels, never on top of them. - **`render.text-width(text)`.** The text's width in the HUD font, so a mod can size boxes and centre text the way the game does. - **`render.frame-stats()`.** The game's frame counter: frames in the last second, the slowest frame and the 1% low. - **`input.mapping(name)`.** For the movement, jump, sneak, sprint, attack and use mappings: the bound key's label and whether it is held. - **`input.clicks-per-second()`.** Attack and use clicks in the last second. - **`ui` button widget.** 200 × 20, vanilla's button; a click is `select(id, 0)`. ## How it works - The game keeps its FPS and click counters running while a mod runs, even with the extras off. For mods with a `frame` hook, it refreshes the snapshot every frame, so key state is never a tick late. - Corner panels go through `extras_hud::Corners`, the same placement the built-in overlays use. - No mod running, no cost: every new path sits behind `mods.running()` / `wants_frames()`. Without the `mods` feature it isn't compiled. - The `input` permission line now reads "see the keys you hold and your clicks, take over the use button on its own items, and add keys". The keystrokes mod uses `input` only to read, and players should be told that. ## How tested - `cargo test -p horizon-mods --features runtime,pack`: new `corner_panels_text_width_and_readings` (the panel, its clipping, text width, frame stats, mappings and CPS from the snapshot); the `ui` test covers the button. - In game (`--features mods`, fresh `HORIZON_HOME` and XDG folders, `HORIZON_NO_AUDIO=1`), in-frame and on the server thread, 5/5 each: - The test guest's corner panel is drawn. - `/readings` answers live FPS, `forward W true` while W is held, and CPS. - The settings page shows the button, and a click on it is `select(3, 0)`. - No panic. - The official FPS and keystrokes mods built on this (next PR) match the built-in extras pixel for pixel; that PR has the screenshots and the frame-time A/B. - `python3 tools/parity.py --changed fada66031`: **27 passed, 0 failed** (33 min, the Mac mini). **Self-check** (against #1944's head): **pr_ready** (`tools/pr_ready.py --quick --base fada66031` on ludovics-mac-mini, against fada66031 at fada66031, 12 min 20 s) | Check | Result | | --- | --- | | Scope | ✅ 11 files, +447 −60 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (18 s) | | clippy | ✅ (1 min 28 s) | | tests: cargo-horizon-mod, horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest | ✅ 1284 passed (9 min 17 s) | | doc tests | ✅ 1 passed (8 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (2 s) | | launcher clippy | ✅ (1 s) | | launcher tests | ✅ 126 passed (5 s) | | Parity | ✅ 24 affected (27 harnesses): 27 passed locally | (c28bea8e9, the permission-line wording, came after this run. It changes one string and the generated reference; `api_reference` and `manifest` tests pass.) Label `skip-release`: experimental and opt-in. Players see no change until a mod uses it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:13:03 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#3890
No description provided.