Archive incari-client (client, 26.3, clean)
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
// The game's own outline skipped, and the block kept for the mod's.
|
||||
fn incari_blockoutline_highlight(game: &crate::game::Game<'_>, pos: [i32; 3], canceled: &mut bool) {
|
||||
use crate::game::{incari_blockoutline as m, incari_client as c};
|
||||
let _ = game;
|
||||
if c::on(m::ID) {
|
||||
m::aim(pos);
|
||||
*canceled = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
# Incari's Block Outline (features/blockoutline) for the Rust build (ADR 0068, 0069). Hooks by name
|
||||
# only (native-hooks.json). Its settings are the client's (rust/mods/incari), shown in the module
|
||||
# menu.
|
||||
[mod]
|
||||
id = "incari_blockoutline"
|
||||
version = "0.1.0"
|
||||
priority = 100
|
||||
|
||||
[[module]]
|
||||
id = "runtime"
|
||||
file = "crates/horizon-client/src/game.rs"
|
||||
name = "incari_blockoutline"
|
||||
source = "runtime.rs"
|
||||
|
||||
[[injection]]
|
||||
id = "highlight"
|
||||
hook = "block_highlight"
|
||||
hook_version = 1
|
||||
kind = "HEAD"
|
||||
helper = "highlight.rs"
|
||||
bindings = [
|
||||
{ name = "game", ty = "&crate::game::Game<'_>", value = "self" },
|
||||
{ name = "pos", ty = "[i32; 3]", value = "pos" },
|
||||
{ name = "canceled", ty = "&mut bool", value = "&mut *canceled" },
|
||||
]
|
||||
|
||||
[[injection]]
|
||||
id = "visuals"
|
||||
hook = "visuals"
|
||||
hook_version = 1
|
||||
kind = "HEAD"
|
||||
helper = "visuals.rs"
|
||||
bindings = [
|
||||
{ name = "game", ty = "&crate::game::Game<'_>", value = "self" },
|
||||
{ name = "rims", ty = "&mut Vec<crate::game::native_hooks::NativeBlockRim>", value = "&mut *rims" },
|
||||
]
|
||||
@@ -0,0 +1,58 @@
|
||||
// Incari's Block Outline for the Rust build (ADR 0068, 0069), as features/blockoutline does it: the
|
||||
// block you look at outlined in your colour, opacity and width, for you only. Its settings are the
|
||||
// module's in `incari_core::modules`. Horizon draws a mod's outline (a "rim") along the block's
|
||||
// selection shape, depth-tested, 0.5 to 4 pixels wide, and has no fill, so widths past 4 draw at 4
|
||||
// and Fill does nothing yet. No game types: rust/lib.rs tests it.
|
||||
|
||||
/// The module's id, as the Java client's profiles name it.
|
||||
pub const ID: &str = "blockoutline";
|
||||
|
||||
/// The widest rim Horizon draws.
|
||||
pub const MAX_WIDTH: f32 = 4.0;
|
||||
|
||||
/// `rgb` (the "color" setting) at `percent` opacity, never fully clear, as the Java module's.
|
||||
pub fn argb(rgb: u32, percent: i32) -> u32 {
|
||||
let alpha = ((percent.clamp(0, 100) as f32 * 255.0 / 100.0).round() as u32).max(1);
|
||||
alpha << 24 | (rgb & 0xFF_FFFF)
|
||||
}
|
||||
|
||||
/// The rim's width in pixels: the "width" setting, as far as Horizon goes.
|
||||
pub fn width(setting: f32) -> f32 {
|
||||
setting.clamp(0.5, MAX_WIDTH)
|
||||
}
|
||||
|
||||
// The block the game would outline, kept from its highlight hook (where the game's own outline is
|
||||
// skipped) for the next frame's visuals hook, which comes first in a frame: a frame late, and
|
||||
// gone a frame after the player looks away.
|
||||
thread_local! {
|
||||
static TARGET: std::cell::Cell<Option<[i32; 3]>> = const { std::cell::Cell::new(None) };
|
||||
}
|
||||
|
||||
pub fn aim(pos: [i32; 3]) {
|
||||
TARGET.with(|t| t.set(Some(pos)));
|
||||
}
|
||||
|
||||
pub fn take() -> Option<[i32; 3]> {
|
||||
TARGET.with(std::cell::Cell::take)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn starts_as_the_java_module_does() {
|
||||
assert_eq!(argb(0xFFA9_DCFF, 90), 0xE6A9_DCFF);
|
||||
assert_eq!(argb(0x00_0000, 100), 0xFF00_0000);
|
||||
assert_eq!(argb(0xFF_FFFF, 0) >> 24, 1);
|
||||
assert_eq!(width(2.5), 2.5);
|
||||
assert_eq!(width(6.0), MAX_WIDTH);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn draws_each_aim_once() {
|
||||
aim([1, 2, 3]);
|
||||
assert_eq!(take(), Some([1, 2, 3]));
|
||||
assert_eq!(take(), None);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// The mod's outline on the block the game would have outlined.
|
||||
fn incari_blockoutline_rim(
|
||||
game: &crate::game::Game<'_>,
|
||||
rims: &mut Vec<crate::game::native_hooks::NativeBlockRim>,
|
||||
) {
|
||||
use crate::game::{incari_blockoutline as m, incari_client as c};
|
||||
let _ = game;
|
||||
let Some(pos) = m::take() else {
|
||||
return;
|
||||
};
|
||||
let Some((argb, width)) = c::settings(m::ID, |s| {
|
||||
(
|
||||
m::argb(s.color("color"), s.int("opacity")),
|
||||
m::width(s.float("width")),
|
||||
)
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
rims.push(crate::game::native_hooks::NativeBlockRim { pos, argb, width });
|
||||
}
|
||||
Reference in New Issue
Block a user