From 6c3473c6e0b1eb69f05072c22a93ef33d22962bf Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 26 Oct 2026 08:40:03 +0100 Subject: [PATCH] Official mod: Minimap The minimap extra as a mod (mods/official/minimap): the extra's five options on its settings page, kept in its storage with the extra's values (corner, size, shape, zoom, rotate), and the map drawn by the game through render.set-minimap, so it looks and costs the same. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 7 ++ Cargo.toml | 2 +- docs/mods.md | 3 +- mods/official/minimap/Cargo.toml | 16 +++ mods/official/minimap/horizon-mod.toml | 9 ++ mods/official/minimap/src/lib.rs | 135 +++++++++++++++++++++++++ 6 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 mods/official/minimap/Cargo.toml create mode 100644 mods/official/minimap/horizon-mod.toml create mode 100644 mods/official/minimap/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 1a2aad855..ae1738593 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2082,6 +2082,13 @@ dependencies = [ "libc", ] +[[package]] +name = "minimap" +version = "1.0.0" +dependencies = [ + "horizon-mod-sdk", +] + [[package]] name = "minisign-verify" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index 259734b98..4d463654b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] exclude = ["launcher", "crates/horizon-telemetry-server", "crates/horizon-mod-registry", "third_party/wgpu-hal"] -members = ["crates/horizon-core", "crates/horizon-dualsense", "crates/horizon-threads", "crates/horizon-world", "crates/horizon-client", "crates/horizon-server-files", "crates/horizon-server", "crates/horizon-bots", "crates/horizon-assets", "crates/horizon-protocol", "crates/horizon-theme", "crates/horizon-prepare", "crates/horizon-telemetry", "crates/horizon-bench", "crates/horizon-friends", "crates/horizon-relay", "crates/horizon-mod-sdk", "crates/horizon-mods", "crates/horizon-mods/tests/guest", "crates/horizon-mods/tests/ui_guest", "crates/cargo-horizon-mod", "crates/horizon-port-pack", "crates/horizon-shaders", "crates/horizon-shader-api", "crates/horizon-release-sign", "crates/horizon-mod-sdk/examples/coords-hud", "crates/horizon-mod-sdk/examples/predator-missile", "mods/official/fps-overlay", "mods/official/keystrokes", "mods/official/zoom", "xtask"] +members = ["crates/horizon-core", "crates/horizon-dualsense", "crates/horizon-threads", "crates/horizon-world", "crates/horizon-client", "crates/horizon-server-files", "crates/horizon-server", "crates/horizon-bots", "crates/horizon-assets", "crates/horizon-protocol", "crates/horizon-theme", "crates/horizon-prepare", "crates/horizon-telemetry", "crates/horizon-bench", "crates/horizon-friends", "crates/horizon-relay", "crates/horizon-mod-sdk", "crates/horizon-mods", "crates/horizon-mods/tests/guest", "crates/horizon-mods/tests/ui_guest", "crates/cargo-horizon-mod", "crates/horizon-port-pack", "crates/horizon-shaders", "crates/horizon-shader-api", "crates/horizon-release-sign", "crates/horizon-mod-sdk/examples/coords-hud", "crates/horizon-mod-sdk/examples/predator-missile", "mods/official/fps-overlay", "mods/official/keystrokes", "mods/official/minimap", "mods/official/zoom", "xtask"] resolver = "2" [workspace.package] diff --git a/docs/mods.md b/docs/mods.md index b94aac089..e13e362e5 100644 --- a/docs/mods.md +++ b/docs/mods.md @@ -15,7 +15,7 @@ folder, loads no runtime and plays exactly like vanilla 26.3. | The contract (WIT) | `crates/horizon-mod-sdk/wit/horizon.wit` | 0.1: log, game-read, chat, hud, storage, command, ui; tick, frame, chat and command hooks | | SDK for mod authors | `crates/horizon-mod-sdk` | 0.1 | | Example mods | `crates/horizon-mod-sdk/examples/coords-hud`, `examples/predator-missile` | coordinates, facing and time HUD, `/where`, `/coords`; `/missile`, a guided missile from vanilla commands | -| Horizon's official mods | `mods/official/` | the extras moving to the registry: FPS Counter (`fps-overlay`), Keystrokes, Zoom | +| Horizon's official mods | `mods/official/` | the extras moving to the registry: FPS Counter (`fps-overlay`), Keystrokes, Zoom, Minimap | | Runtime | `crates/horizon-mods` | wasmtime 48 LTS, component model | | Authoring tool | `crates/cargo-horizon-mod` | `cargo horizon-mod new [--template code\|content] / build / run / test / check`, and the registry's CI (`registry build / review / list`) | | In the game | `crates/horizon-client/src/game/mods.rs`, Options > Mods | client mods | @@ -490,6 +490,7 @@ so the same rustc and `Cargo.lock` give the same file. | FPS Counter | `fps_overlay` | Extras > FPS counter | `corner`: `top_left` (default), `top_right`, `bottom_left`, `bottom_right`; `lows`: `false` (default), `true` | | Keystrokes | `keystrokes` | Extras > Keystrokes | `corner`: as above, default `top_left`; `cps`: `true` (default), `false` | | Zoom | `zoom` | Extras > Zoom | `level`: `2`, `3`, `4` (default), `6`, `8`, `10`; `smooth`: `true` (default), `false`; `sensitivity` (slower turning): `true` (default), `false`. The key is the game's: `key.zoom.zoom` in `horizon-mods.txt`, default `key.keyboard.z` | +| Minimap | `minimap` | Extras > Minimap | `corner`: as above, default `top_right`; `size`: `64`, `96` (default), `128`; `shape`: `square` (default), `round`; `zoom` (blocks per pixel): `0.5`, `1` (default), `2`, `4`; `rotate`: `false` (default), `true`. The game draws the map (`render.set-minimap`) | ## Versions and compatibility diff --git a/mods/official/minimap/Cargo.toml b/mods/official/minimap/Cargo.toml new file mode 100644 index 000000000..e6aafb7c4 --- /dev/null +++ b/mods/official/minimap/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "minimap" +version = "1.0.0" +edition.workspace = true +license.workspace = true +publish = false +description = "Horizon's official minimap: a map of the terrain around you in a corner." + +[lib] +crate-type = ["cdylib"] + +[dependencies] +horizon-mod-sdk = { path = "../../../crates/horizon-mod-sdk" } + +[lints] +workspace = true diff --git a/mods/official/minimap/horizon-mod.toml b/mods/official/minimap/horizon-mod.toml new file mode 100644 index 000000000..51bd7ef94 --- /dev/null +++ b/mods/official/minimap/horizon-mod.toml @@ -0,0 +1,9 @@ +id = "minimap" +name = "Minimap" +version = "1.0.0" +description = "A map of the terrain around you in a corner, in map colours, square or round, north up or turning with you. Horizon's own, formerly an extra." +authors = ["Horizon"] +api = "0.1" +side = "client" +capabilities = ["render", "ui", "storage"] +experimental = ["render", "ui"] diff --git a/mods/official/minimap/src/lib.rs b/mods/official/minimap/src/lib.rs new file mode 100644 index 000000000..ea8c45b72 --- /dev/null +++ b/mods/official/minimap/src/lib.rs @@ -0,0 +1,135 @@ +//! Horizon's official minimap, formerly the built-in extra: a map of the +//! terrain around the player in a corner (`render.set-minimap`; the game +//! keeps its tiles). Its settings page has the extra's five options, kept in +//! the mod's storage (`corner`, `size`, `shape`, `zoom`, `rotate`) with the +//! extra's values, where the game writes a player's old extra settings when +//! it installs the mod for them. +use horizon_mod_sdk::{ + Mod, Registration, + render::{self, Corner, Minimap as MapView}, + storage, + ui::{self, ButtonWidget, Widget}, +}; + +/// (corner, stored value, label), in the extra's order. +const CORNERS: [(Corner, &str, &str); 4] = [ + (Corner::TopLeft, "top_left", "Top left"), + (Corner::TopRight, "top_right", "Top right"), + (Corner::BottomLeft, "bottom_left", "Bottom left"), + (Corner::BottomRight, "bottom_right", "Bottom right"), +]; +/// (side in GUI pixels, label). +const SIZES: [(u8, &str); 3] = [(64, "Small"), (96, "Medium"), (128, "Large")]; +/// Blocks per map pixel. +const ZOOMS: [f32; 4] = [0.5, 1.0, 2.0, 4.0]; +/// Settings page buttons. +const CORNER_BUTTON: u32 = 1; +const SIZE_BUTTON: u32 = 2; +const SHAPE_BUTTON: u32 = 3; +const ZOOM_BUTTON: u32 = 4; +const ROTATE_BUTTON: u32 = 5; + +/// Indexes into the tables above, and the two switches. +struct Minimap { + corner: usize, + size: usize, + round: bool, + zoom: usize, + rotate: bool, +} + +impl Minimap { + fn show(&self) { + render::set_minimap(Some(MapView { + corner: CORNERS[self.corner].0, + size: f32::from(SIZES[self.size].0), + blocks_per_pixel: ZOOMS[self.zoom], + rotate: self.rotate, + round: self.round, + })); + } + fn page(&self) { + let button = |id, label: String| Widget::Button(ButtonWidget { id, label }); + let n = ZOOMS[self.zoom]; + let blocks = if n < 1.0 { + "½ block".to_owned() + } else if n == 1.0 { + "1 block".to_owned() + } else { + format!("{n} blocks") + }; + ui::set_settings(&[ + button(CORNER_BUTTON, format!("Corner: {}", CORNERS[self.corner].2)), + button(SIZE_BUTTON, format!("Size: {}", SIZES[self.size].1)), + button( + SHAPE_BUTTON, + format!("Shape: {}", if self.round { "Round" } else { "Square" }), + ), + button(ZOOM_BUTTON, format!("Zoom: {blocks} per pixel")), + button( + ROTATE_BUTTON, + format!( + "Turn with the player: {}", + if self.rotate { "ON" } else { "OFF" } + ), + ), + ]); + } + fn save(&self) { + let _ = storage::set("corner", CORNERS[self.corner].1.as_bytes()); + let _ = storage::set("size", SIZES[self.size].0.to_string().as_bytes()); + let _ = storage::set("shape", if self.round { b"round" } else { b"square" }); + let _ = storage::set("zoom", ZOOMS[self.zoom].to_string().as_bytes()); + let _ = storage::set("rotate", if self.rotate { b"true" } else { b"false" }); + } +} + +fn stored(key: &str) -> Option { + storage::get(key) + .and_then(|v| String::from_utf8(v).ok()) + .map(|v| v.trim().to_owned()) +} + +impl Mod for Minimap { + fn init() -> Result<(Self, Registration), String> { + // The extra's defaults: top right, medium, square, 1 block per + // pixel, north up. An unknown value keeps the default. + let find = |key: &str, values: &[String], default: usize| { + stored(key) + .and_then(|v| values.iter().position(|s| *s == v)) + .unwrap_or(default) + }; + let corners: Vec = CORNERS.iter().map(|c| c.1.to_owned()).collect(); + let sizes: Vec = SIZES.iter().map(|s| s.0.to_string()).collect(); + let zooms: Vec = ZOOMS.iter().map(f32::to_string).collect(); + let map = Minimap { + corner: find("corner", &corners, 1), + size: find("size", &sizes, 1), + round: stored("shape").as_deref() == Some("round"), + zoom: find("zoom", &zooms, 1), + rotate: stored("rotate").as_deref() == Some("true"), + }; + map.show(); + map.page(); + Ok((map, Registration::new())) + } + fn ui_select(&mut self, id: u32, _row: u32) { + let next = |i: usize, n: usize| (i + 1) % n; + match id { + CORNER_BUTTON => self.corner = next(self.corner, CORNERS.len()), + SIZE_BUTTON => self.size = next(self.size, SIZES.len()), + SHAPE_BUTTON => self.round = !self.round, + ZOOM_BUTTON => self.zoom = next(self.zoom, ZOOMS.len()), + ROTATE_BUTTON => self.rotate = !self.rotate, + _ => return, + } + self.save(); + self.show(); + self.page(); + } + fn ui_settings_opened(&mut self) { + self.page(); + } +} + +horizon_mod_sdk::export_mod!(Minimap);