Merge pull request #2058 from ludovic111/feat/official-minimap-mod
🤖 Agent: The official Minimap mod (mods/official/minimap): the minimap extra as a mod with its five options. Pixel-identical to the extra in the map region (0.000 to 0.002) with default and other settings, at the same frame cost. Verified: pr_ready (2179 workspace tests, clippy), the settings page in game, and the published mods loading beside it in both modes.
This commit is contained in:
Generated
+7
@@ -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"
|
||||
|
||||
+1
-1
@@ -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]
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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"]
|
||||
@@ -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<String> {
|
||||
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<String> = CORNERS.iter().map(|c| c.1.to_owned()).collect();
|
||||
let sizes: Vec<String> = SIZES.iter().map(|s| s.0.to_string()).collect();
|
||||
let zooms: Vec<String> = 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);
|
||||
Reference in New Issue
Block a user