Archive incari-client (client, 26.3, clean)

This commit is contained in:
2026-11-28 00:54:38 -06:00
parent 7a6174687f
commit 12838e838c
2383 changed files with 280266 additions and 0 deletions
@@ -0,0 +1,41 @@
# Incari's Custom Scoreboard (features/customscoreboard) for the Rust build (ADR 0068, 0069). Hooks by name where Horizon
# has stamped the hook point (native-hooks.json), by function where it's still pending. Its
# settings and HUD element are the client's (rust/mods/incari): the module menu shows them and the HUD editor places it.
[mod]
id = "incari_customscoreboard"
version = "0.1.0"
priority = 100
[[module]]
id = "runtime"
file = "crates/horizon-client/src/game.rs"
name = "incari_customscoreboard"
source = "runtime.rs"
[[injection]]
id = "place"
# Horizon's sidebar_place hook point is still a pending fragment
# (tools/native-hook-fragments/incari_client_hooks.json), so this targets its function. Make it
# `hook = "sidebar_place"` and `hook_version = 1` once Horizon stamps it.
target = "horizon_client::game::native_hooks::Game<'_>::native_sidebar_place"
kind = "HEAD"
helper = "place.rs"
bindings = [
{ name = "game", ty = "&crate::game::Game<'_>", value = "self" },
{ name = "screen", ty = "[f32; 2]", value = "screen" },
{ name = "bounds", ty = "[f32; 4]", value = "bounds" },
{ name = "offset", ty = "&mut [f32; 2]", value = "&mut *offset" },
{ name = "scale", ty = "&mut f32", value = "&mut *scale" },
]
[[injection]]
id = "hud"
hook = "hud"
hook_version = 1
kind = "HEAD"
helper = "hud.rs"
bindings = [
{ name = "game", ty = "&mut crate::game::Game<'_>", value = "&mut *self" },
{ name = "batch", ty = "&mut horizon_client::hud::HudBatch", value = "&mut *batch" },
{ name = "corners", ty = "&mut horizon_client::extras_hud::Corners", value = "&mut *corners" },
]
@@ -0,0 +1,41 @@
// The sidebar's element: placed by the sidebar's size, which Horizon then draws there
// (`place.rs`). In the HUD editor with no sidebar, a sample (GameParts.sample).
fn incari_customscoreboard_hud(
game: &mut crate::game::Game<'_>,
batch: &mut horizon_client::hud::HudBatch,
corners: &mut horizon_client::extras_hud::Corners,
) {
use crate::game::{incari_client as c, incari_customscoreboard as m};
use incari_core::framework::hud::Anchor;
use incari_core::theme::Tone;
let _ = corners;
let drawn = m::frame();
c::element(game, batch, m::ID, m::ELEMENT, |canvas| {
let size = match drawn {
Some(size) => size,
None if canvas.editing => {
let [w, h] = m::SAMPLE;
canvas.fill(0.0, 0.0, w, h, Tone::Background);
let tw = canvas.text_width(m::SAMPLE_TITLE);
canvas.text(m::SAMPLE_TITLE, ((w - tw) / 2.0).floor(), 1.0, Tone::Text);
for (i, (name, score)) in m::SAMPLE_LINES.iter().enumerate() {
let y = 10.0 + 9.0 * i as f32;
canvas.text(name, 2.0, y, Tone::Muted);
let sw = canvas.text_width(score);
canvas.text_argb(score, w - 2.0 - sw, y, 0xFFFF_5555);
}
return Some(m::SAMPLE);
}
None => return None,
};
// Where the client puts it (HudElement::bounds), for the game to draw it there.
let e = canvas.element;
let s = e.float("scale");
let anchor = Anchor::from_index(e.get("anchor").map_or(0, |a| a.as_choice()));
let (w, h) = ((size[0] * s).round() as i32, (size[1] * s).round() as i32);
let (sw, sh) = (canvas.screen[0] as i32, canvas.screen[1] as i32);
let at = [anchor.x(e.int("x"), w, sw) as f32, anchor.y(e.int("y"), h, sh) as f32];
m::place(at, s);
Some(size)
});
}
@@ -0,0 +1,15 @@
// The sidebar moved and scaled to the element.
fn incari_customscoreboard_place(
game: &crate::game::Game<'_>,
screen: [f32; 2],
bounds: [f32; 4],
offset: &mut [f32; 2],
scale: &mut f32,
) {
use crate::game::incari_customscoreboard as m;
let _ = (game, screen);
if let Some((o, s)) = m::drawing(bounds) {
*offset = o;
*scale = s;
}
}
@@ -0,0 +1,115 @@
// Incari's Custom Scoreboard for the Rust build (ADR 0068, 0069), as features/customscoreboard does
// it: the server's scoreboard sidebar wherever the player puts it in the HUD editor, at the scale
// they choose. Horizon still draws the sidebar; its `sidebar_place` hook moves and scales it to
// the module's `sidebar` element, which the `hud` hook places by the sidebar's size. No game
// types: rust/lib.rs tests it.
use std::cell::Cell;
/// The module's id, as the Java client's profiles name it.
pub const ID: &str = "customscoreboard";
/// Its HUD element, named after the part of the game's HUD it takes over.
pub const ELEMENT: &str = "sidebar";
/// The editor's sample while the server sends no sidebar: its size (Java's `GameParts.measure`),
/// title and lines.
pub const SAMPLE: [f32; 2] = [80.0, 36.0];
pub const SAMPLE_TITLE: &str = "Scoreboard";
pub const SAMPLE_LINES: [(&str, &str); 3] = [("Kills", "12"), ("Deaths", "3"), ("Coins", "250")];
/// The offset that puts a sidebar the game would draw at `bounds` (`[x, y, w, h]`), scaled `s`
/// about its top right as Horizon scales it, with its top left at `at`.
pub fn offset(bounds: [f32; 4], at: [f32; 2], s: f32) -> [f32; 2] {
let [x, y, w, _] = bounds;
[at[0] - (x + w - w * s), at[1] - y]
}
/// The sidebar as Horizon last placed it, and where the element wants it.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
struct Sidebar {
/// The game's own place for it, as last drawn.
bounds: Option<[f32; 4]>,
/// Drawn since the HUD last asked.
drawn: bool,
/// The element's top left and scale, this frame; none while the module is off.
target: Option<([f32; 2], f32)>,
}
// The window's thread only: the HUD and the sidebar are drawn there.
thread_local! {
static SIDEBAR: Cell<Sidebar> = const {
Cell::new(Sidebar { bounds: None, drawn: false, target: None })
};
}
fn with<R>(f: impl FnOnce(&mut Sidebar) -> R) -> R {
SIDEBAR.with(|c| {
let mut s = c.get();
let r = f(&mut s);
c.set(s);
r
})
}
/// The game is drawing a sidebar at `bounds`: the offset and scale that move it to the element,
/// or none to leave it be.
pub fn drawing(bounds: [f32; 4]) -> Option<([f32; 2], f32)> {
with(|s| {
s.bounds = Some(bounds);
s.drawn = true;
s.target
.map(|(at, scale)| (offset(bounds, at, scale), scale))
})
}
/// Once a HUD frame, before the element draws: the sidebar's unscaled size when one was drawn
/// since the last frame. Forgets the last target, so the sidebar goes back to the game's place if
/// the element doesn't draw.
pub fn frame() -> Option<[f32; 2]> {
with(|s| {
s.target = None;
let drawn = std::mem::take(&mut s.drawn);
s.bounds.filter(|_| drawn).map(|b| [b[2], b[3]])
})
}
/// Where the element is this frame: its top left and scale.
pub fn place(at: [f32; 2], scale: f32) {
with(|s| s.target = Some((at, scale)));
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn moves_the_scaled_box_to_the_element() {
let b = [250.0, 100.0, 69.0, 40.0];
assert_eq!(offset(b, [250.0, 100.0], 1.0), [0.0, 0.0]);
assert_eq!(offset(b, [2.0, 2.0], 1.0), [-248.0, -98.0]);
// Twice the size about its top right: its left edge is 69 further left.
assert_eq!(offset(b, [181.0, 100.0], 2.0), [0.0, 0.0]);
}
#[test]
fn follows_the_element_only_while_it_draws() {
assert_eq!(frame(), None);
assert_eq!(
drawing([250.0, 100.0, 69.0, 40.0]),
None,
"nothing placed yet"
);
assert_eq!(frame(), Some([69.0, 40.0]));
place([2.0, 2.0], 1.0);
assert_eq!(
drawing([250.0, 100.0, 69.0, 40.0]),
Some(([-248.0, -98.0], 1.0))
);
assert_eq!(frame(), Some([69.0, 40.0]));
assert_eq!(frame(), None, "no sidebar since");
assert_eq!(
drawing([250.0, 100.0, 69.0, 40.0]),
None,
"the element didn't draw"
);
}
}