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,42 @@
// A chat line (ADR 0062; `Cosmetics.chatMessage`, `Badges.badgedInChat`): Incari's badge before
// the first mention of each Incari player in it who shows it. Players are found by their names,
// since most servers send chat as plain text with no sender. Once a line.
fn incari_cosmetics_chat_message(game: &crate::game::Game<'_>, message: &mut horizon_client::text::Text) {
use horizon_client::text::{Style, Text};
use incari_core::cosmetics::badges::{self, Piece};
use incari_core::online::Status;
let own = game.native_player_name();
let show_badges = crate::game::incari_cosmetics::with(|s| s.show_badges);
let positions = incari_core::online::with(|o| {
if o.status() != Status::SignedIn {
return Vec::new();
}
let text: String = message.spans.iter().map(|s| s.text.as_str()).collect();
badges::chat_positions(&text, |name| {
if name == own {
o.shows_badge()
} else {
show_badges && o.world_players().get(name).is_some_and(|p| p.badge)
}
})
});
if positions.is_empty() {
return;
}
let texts: Vec<&str> = message.spans.iter().map(|s| s.text.as_str()).collect();
let pieces = badges::badged_pieces(&texts, &positions);
let mut out = Text::empty();
for piece in pieces {
match piece {
Piece::Text(i, text) => out.push(Text::styled(text, message.spans[i].style.clone())),
Piece::Badge => {
out.push(Text::styled(
badges::GLYPH,
Style { font: Some(badges::FONT.into()), color: Some(badges::COLOR), ..Style::default() },
));
out.push(Text::literal(" "));
}
}
}
*message = out;
}
@@ -0,0 +1,62 @@
// Once a frame: the wardrobe read the first time and saved when it changed, kept in step with the
// online service, and the cosmetics' pictures painted into the entity canvas: the still ones once
// (again after a new atlas), moving capes ten times a second while one was drawn lately.
fn incari_cosmetics_frame(game: &mut crate::game::Game<'_>) {
use crate::game::incari_cosmetics as m;
use incari_core::cosmetics::{Slot, art, catalog, models, wardrobe};
thread_local! {
static START: std::cell::Cell<Option<horizon_os::time::Instant>> = const { std::cell::Cell::new(None) };
}
let now = START.with(|s| {
let start = s.get().unwrap_or_else(|| {
let now = horizon_os::time::Instant::now();
s.set(Some(now));
now
});
start.elapsed().as_secs_f64() * 1000.0
});
m::with(|s| s.now_ms = now);
let folder = horizon_os::env::current_dir().unwrap_or_default().join("incari");
wardrobe::ensure_loaded(|| horizon_os::fs::read(folder.join(wardrobe::FILE)).ok());
wardrobe::with(|w| incari_core::online::with(|o| w.sync(o, now)));
if let Some(text) = wardrobe::with(|w| w.take_unsaved()) {
let path = folder.join(wardrobe::FILE);
if let Some(dir) = path.parent() {
let _ = horizon_os::fs::create_dir_all(dir);
}
if let Err(e) = horizon_os::fs::write(&path, text.as_bytes()) {
log::warn!("Incari: couldn't save the wardrobe: {e}");
}
}
let (still, moving) = m::with(|s| (!s.painted, s.capes_due()));
if !still && !moving {
return;
}
let t = (now / 1000.0) as f32;
let mut pixels = vec![0u32; art::CAPE_WIDTH * art::CAPE_HEIGHT];
let mut all = true;
for (n, cape) in catalog::in_slot(Slot::Cape).enumerate().take(m::CAPES) {
let due = still || (art::animated(cape.id) && m::with(|s| s.cape_moving(n)));
if !due {
continue;
}
art::cape(cape.id, t, &mut pixels);
all &= game.native_entity_canvas_upload(m::cape_slot(n), m::CAPE, art::rgba(&pixels));
}
if still {
let mut texture = vec![0u32; models::TEXTURE * models::TEXTURE];
for cosmetic in catalog::all() {
let (Some(n), Some(spec)) = (models::number(cosmetic), models::spec(cosmetic.id)) else {
continue;
};
if n >= m::MODELS {
continue;
}
models::texture(cosmetic.id, &spec, &mut texture);
all &= game.native_entity_canvas_upload(m::model_slot(n), [m::MODEL, m::MODEL], art::rgba(&texture));
}
// No canvas yet (the boot screen's atlas): again next frame.
m::with(|s| s.painted = all);
}
}
@@ -0,0 +1,128 @@
# Incari's cosmetics in the world for the Rust build (ADR 0061, 0069): worn capes, hats, wings and
# back items on players, name tag styles and Incari's badge (name tags, the tab list, chat),
# trails, and emotes with the emote wheel (G). What's worn and how it looks is the client's
# (`incari_core::cosmetics`, rust/mods/incari); the Wardrobe is its screen. Hooks by name where
# Horizon has stamped the hook point (native-hooks.json), by function where it's still pending:
# the fork's `incari_shell_hooks.json` (player_look, name_tag, tab_list_name, chat_message).
[mod]
id = "incari_cosmetics"
version = "0.1.0"
priority = 100
[[module]]
id = "runtime"
file = "crates/horizon-client/src/game.rs"
name = "incari_cosmetics"
source = "runtime.rs"
[[injection]]
id = "listened"
hook = "player_render_listened"
hook_version = 1
kind = "HEAD"
helper = "listened.rs"
bindings = [
{ name = "listened", ty = "&mut bool", value = "&mut *listened" },
]
[[injection]]
id = "look"
# Pending in the fork's incari_shell_hooks.json: make it `hook = "player_look"` and
# `hook_version = 1` once Horizon stamps it.
target = "horizon_client::game::native_hooks::Game<'_>::native_player_look"
kind = "HEAD"
helper = "look.rs"
bindings = [
{ name = "game", ty = "&crate::game::Game<'_>", value = "self" },
{ name = "player", ty = "&crate::game::native_mob_draw::NativeMobRender<'_>", value = "player" },
{ name = "look", ty = "&mut crate::game::native_mob_draw::NativePlayerLook<'_>", value = "&mut *look" },
]
[[injection]]
id = "layer"
hook = "mob_layer"
hook_version = 1
kind = "HEAD"
helper = "layer.rs"
bindings = [
{ name = "game", ty = "&crate::game::Game<'_>", value = "self" },
{ name = "mob", ty = "&crate::game::native_mob_draw::NativeMobRender<'_>", value = "mob" },
{ name = "who", ty = "Option<&crate::game::native_mob_draw::NativePlayerRender<'_>>", value = "who" },
{ name = "draw", ty = "&mut crate::game::native_block_entity_draw::BlockEntityDraw", value = "&mut *draw" },
]
[[injection]]
id = "name_tag"
# Pending (incari_shell_hooks.json): `hook = "name_tag"`, `hook_version = 1` once stamped.
target = "horizon_client::game::native_hooks::Game<'_>::native_name_tag"
kind = "HEAD"
helper = "name_tag.rs"
bindings = [
{ name = "game", ty = "&crate::game::Game<'_>", value = "self" },
{ name = "who", ty = "&crate::game::native_mob_draw::NativeNameTag<'_>", value = "who" },
{ name = "tag", ty = "&mut horizon_client::text::Text", value = "&mut *tag" },
]
[[injection]]
id = "tab_list_name"
# Pending (incari_shell_hooks.json): `hook = "tab_list_name"`, `hook_version = 1` once stamped.
target = "horizon_client::game::native_hooks::Game<'_>::native_tab_list_name"
kind = "HEAD"
helper = "tab_list_name.rs"
bindings = [
{ name = "game", ty = "&crate::game::Game<'_>", value = "self" },
{ name = "uuid", ty = "u128", value = "uuid" },
{ name = "local", ty = "bool", value = "local" },
{ name = "name", ty = "&mut horizon_client::text::Text", value = "&mut *name" },
]
[[injection]]
id = "chat_message"
# Pending (incari_shell_hooks.json): `hook = "chat_message"`, `hook_version = 1` once stamped.
target = "horizon_client::game::native_hooks::Game<'_>::native_chat_message"
kind = "HEAD"
helper = "chat_message.rs"
bindings = [
{ name = "game", ty = "&crate::game::Game<'_>", value = "self" },
{ name = "message", ty = "&mut horizon_client::text::Text", value = "&mut *message" },
]
[[injection]]
id = "frame"
hook = "frame"
hook_version = 1
kind = "HEAD"
helper = "frame.rs"
bindings = [
{ name = "game", ty = "&mut crate::game::Game<'_>", value = "&mut *self" },
]
[[injection]]
id = "tick"
hook = "tick"
hook_version = 1
kind = "HEAD"
helper = "tick.rs"
bindings = [
{ name = "game", ty = "&mut crate::game::Game<'_>", value = "&mut *self" },
]
[[injection]]
id = "key"
hook = "key"
hook_version = 1
kind = "HEAD"
helper = "key.rs"
bindings = [
{ name = "game", ty = "&mut crate::game::Game<'_>", value = "&mut *self" },
{ name = "key", ty = "&str", value = "key" },
{ name = "pressed", ty = "bool", value = "pressed" },
]
[[injection]]
id = "reloaded"
hook = "client_resources_reloaded"
hook_version = 1
kind = "HEAD"
helper = "reloaded.rs"
bindings = []
@@ -0,0 +1,13 @@
// The emote wheel's key (G): held, the wheel shows over the game; let go, the emote pointed at
// plays (`incari_core::screens::emote_wheel`).
fn incari_cosmetics_key(game: &mut crate::game::Game<'_>, key: &str, pressed: bool) {
use incari_core::screens::emote_wheel as wheel;
if key != wheel::KEY_NAME {
return;
}
wheel::key_held(pressed);
// The wheel opens with its key over the game, not over another screen.
if pressed && game.native_playing() && game.native_player().is_some() {
crate::game::incari_client::open(game, Box::new(wheel::EmoteWheel::new()));
}
}
@@ -0,0 +1,52 @@
// After a player's model: their hat on the head and their back cosmetic on the body (ADR 0061,
// `CosmeticsLayer`), as `look` found them this frame, from the entity canvas.
fn incari_cosmetics_layer(
game: &crate::game::Game<'_>,
mob: &crate::game::native_mob_draw::NativeMobRender<'_>,
who: Option<&crate::game::native_mob_draw::NativePlayerRender<'_>>,
draw: &mut crate::game::native_block_entity_draw::BlockEntityDraw,
) {
use crate::game::incari_cosmetics as m;
use crate::game::native_block_entity_draw::HumanoidPart;
use incari_core::cosmetics::{catalog, models};
if who.is_none() {
return;
}
let Some(job) = m::with(|s| s.job(mob.id)) else {
return;
};
let state = models::State {
age: job.age,
crouching: job.crouching,
fall_flying: job.fall_flying,
chest_armor: job.chest_armor,
cape_swing: job.cape_swing,
};
for (index, part) in [(job.hat, HumanoidPart::Head), (job.back, HumanoidPart::Body)] {
let Some(cosmetic) = index.and_then(|i| catalog::all().get(i)) else {
continue;
};
let Some(slot) = models::number(cosmetic).map(m::model_slot) else {
continue;
};
draw.push();
if !draw.attach(part) {
draw.pop();
return;
}
let light = draw.light;
models::with_mesh(cosmetic, &state, |spec, quads| {
if spec.look == models::Look::Glow {
// Lit by itself, at full brightness.
draw.light = 0xF0 | 0xF0 << 8;
}
for q in quads {
let (corners, uv) = models::quad_for_rect(q);
let corners = corners.map(|c| c.map(|v| v / 16.0));
game.native_draw_quad(draw, horizon_client::hud::MOD_ENTITY_CANVAS_SPRITE, corners, m::uv16(slot, uv), 0xFF_FFFF);
}
});
draw.light = light;
draw.pop();
}
}
@@ -0,0 +1,12 @@
// Players are posed for the mods only while there's something to show: the player wears
// something, others' cosmetics show and Incari players are about, or an emote plays.
fn incari_cosmetics_listened(listened: &mut bool) {
use incari_core::cosmetics::{wardrobe, world};
let (own, others) = wardrobe::with(|w| (!w.worn().is_empty(), w.show_others()));
if own
|| world::with(|w| w.any_playing())
|| (others && incari_core::online::with(|o| !o.world_players().is_empty()))
{
*listened = true;
}
}
@@ -0,0 +1,82 @@
// Before a player is drawn: what they wear and the emote they play (ADR 0061, `Cosmetics.extract`
// and `dress`): the cape as the player's own, a backpack hiding it, the emote's pose, and the
// hat and back cosmetic for `layer` right after. Per player per frame: nothing is made.
fn incari_cosmetics_look(
game: &crate::game::Game<'_>,
player: &crate::game::native_mob_draw::NativeMobRender<'_>,
look: &mut crate::game::native_mob_draw::NativePlayerLook<'_>,
) {
use crate::game::incari_cosmetics as m;
use crate::game::native_mob_draw::NativeCape;
use horizon_client::mobs::anim::{PartBlend, PoseBlend};
use incari_core::cosmetics::{Slot, catalog, wardrobe, world};
let _ = game;
// The player's own is kept under 0: a world without a server has no UUIDs.
let key = if look.local { 0 } else { match look.uuid { Some(u) => u, None => return } };
let (own, show_others) = wardrobe::with(|w| (w.worn(), w.show_others()));
let (worn, now) = incari_core::online::with(|o| {
let ids = if look.local { None } else { o.player(key).map(|p| p.cosmetics.as_slice()) };
world::with(|w| {
if !look.local {
w.walking(key, player.walk_speed);
}
(w.worn_by(key, look.local, own, ids, show_others), w.now(player.partial))
})
});
if worn.is_empty() {
return;
}
// The emote's pose over the model's: the legs still walk.
if let Some(p) = worn.pose(now) {
let part = |r: Option<[f32; 3]>| r.map_or(PartBlend::default(), |rotation| PartBlend { weight: p.weight, rotation });
look.pose = PoseBlend { head: part(p.head), right_arm: part(p.right_arm), left_arm: part(p.left_arm), ..PoseBlend::default() };
}
let backpack = worn.loadout.in_slot(Slot::Back).is_some_and(|b| b.id == "back.backpack");
let cape = worn.loadout.in_slot(Slot::Cape);
if backpack {
// A backpack and a cape would go through each other.
look.hide_cape = true;
} else if let Some(c) = cape {
let n = catalog::index(c);
let [x, y] = m::cape_slot(n);
look.cape = Some(NativeCape {
sprite: horizon_client::hud::MOD_ENTITY_CANVAS_SPRITE,
rect: [x as f32, y as f32, m::CAPE[0] as f32, m::CAPE[1] as f32],
});
m::with(|s| s.cape_drawn(n));
}
// Others' trails go by where they're drawn; the player's own by where they are (`tick`).
let mob = player.id;
if !look.local {
let trail = worn.loadout.in_slot(Slot::Trail).map(catalog::index);
let position = look.position;
m::with(|s| s.saw(mob, trail, position));
}
if look.invisible || look.distance_sq > world::MAX_DISTANCE * world::MAX_DISTANCE {
return;
}
// A hat hides under a helmet (the halo floats above one); a back cosmetic under an elytra.
let hat = worn
.loadout
.in_slot(Slot::Hat)
.filter(|h| look.head_item.is_none() || h.id == "hat.halo")
.map(catalog::index);
let back = worn.loadout.in_slot(Slot::Back).filter(|_| !look.chest_wings).map(catalog::index);
if hat.is_none() && back.is_none() {
return;
}
let cape_shown = !backpack && !look.chest_wings && (cape.is_some() || look.has_cape);
let [flap, lean, _] = look.cape_angles;
let job = m::Job {
mob,
hat,
back,
age: player.age,
crouching: look.crouching,
fall_flying: look.fall_flying,
chest_armor: look.chest_armor,
cape_swing: cape_shown.then(|| (6.0 + lean / 2.0 + flap).to_radians()),
};
m::with(|s| s.set_job(job));
look.parts = true;
}
@@ -0,0 +1,41 @@
// A player's name tag (ADR 0061, 0062; `NameTags.style`, `Badges.badged`): in their name tag
// cosmetic's colours unless the server coloured it (a team's colour means something), with
// Incari's badge before an Incari player's name while they show it and the player wants badges.
fn incari_cosmetics_name_tag(
game: &crate::game::Game<'_>,
who: &crate::game::native_mob_draw::NativeNameTag<'_>,
tag: &mut horizon_client::text::Text,
) {
use crate::game::incari_cosmetics as m;
use horizon_client::text::{Style, Text};
use incari_core::cosmetics::{Slot, badges, nametags, wardrobe, world};
let _ = game;
let key = if who.local { 0 } else { match who.uuid { Some(u) => u, None => return } };
let (own, show_others) = wardrobe::with(|w| (w.worn(), w.show_others()));
let show_badges = m::with(|s| s.show_badges);
let (style, badge) = incari_core::online::with(|o| {
let incari = if who.local { None } else { o.player(key) };
let ids = incari.map(|p| p.cosmetics.as_slice());
let worn = world::with(|w| w.worn_by(key, who.local, own, ids, show_others));
(worn.loadout.in_slot(Slot::Nametag), incari.is_some_and(|p| p.badge) && show_badges)
});
if let Some(style) = style
&& !tag.spans.iter().any(|s| s.style.color.is_some() && !s.text.is_empty())
{
let plain = tag.plain();
let mut styled = Text::empty();
for (piece, rgb) in nametags::styled(&plain, style) {
styled.push(Text::colored(piece, rgb));
}
*tag = styled;
}
if badge {
let mut badged = Text::styled(
badges::GLYPH,
Style { font: Some(badges::FONT.into()), color: Some(badges::COLOR), ..Style::default() },
);
badged.push(Text::literal(" "));
badged.push(std::mem::take(tag));
*tag = badged;
}
}
@@ -0,0 +1,4 @@
// A new atlas: the entity canvas is blank again.
fn incari_cosmetics_reloaded() {
crate::game::incari_cosmetics::with(|s| s.painted = false);
}
@@ -0,0 +1,244 @@
// Incari's cosmetics in the world for the Rust build (ADR 0061, 0069): worn capes, hats, wings and
// back items, name tag styles, Incari's badge, trails and emotes on the players Horizon draws. What
// they are and how they look is `incari_core::cosmetics` (the client's, no game types); this is
// the game side's own bookkeeping between its hooks: where each picture is on the fork's entity
// canvas, what each player drawn this frame wears, and the frame's timing. No game types either:
// rust/lib.rs tests it.
/// The entity canvas's size (the fork's `MOD_ENTITY_CANVAS_SIZE`).
pub const CANVAS: [u32; 2] = [512, 256];
/// A cape's picture: the game's 64x32 cape layout.
pub const CAPE: [u32; 2] = [64, 32];
/// A model's texture (`incari_core::cosmetics::models::TEXTURE`).
pub const MODEL: u32 = 64;
/// How many capes and models the canvas holds.
pub const CAPES: usize = 8;
pub const MODELS: usize = 12;
/// A moving cape's frames a second, and how long it goes on moving after it was last drawn.
pub const CAPE_FPS: f64 = 10.0;
pub const CAPE_IDLE_MS: f64 = 2_000.0;
/// How often the client's `show-badges` setting is read again, in ticks.
pub const SETTINGS_TICKS: u64 = 100;
/// Where cape `n` (its place among the capes) is on the canvas: the top row.
pub fn cape_slot(n: usize) -> [u32; 2] {
[n as u32 * CAPE[0], 0]
}
/// Where model `n` (its place among the hats and back cosmetics) is: rows of eight under the capes.
pub fn model_slot(n: usize) -> [u32; 2] {
[(n % 8) as u32 * MODEL, CAPE[1] + (n / 8) as u32 * MODEL]
}
/// A texture rectangle `[u0, v0, u1, v1]` in pixels of a picture at `slot`, as `native_draw_quad`
/// takes it: texels of 16 per side of the whole canvas.
pub fn uv16(slot: [u32; 2], uv: [f32; 4]) -> [f32; 4] {
let (x, y) = (slot[0] as f32, slot[1] as f32);
let (w, h) = (CANVAS[0] as f32, CANVAS[1] as f32);
[
(x + uv[0]) * 16.0 / w,
(y + uv[1]) * 16.0 / h,
(x + uv[2]) * 16.0 / w,
(y + uv[3]) * 16.0 / h,
]
}
/// What `look` found a player drawn this frame wears on their model, for `layer` right after.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct Job {
pub mob: u32,
/// The hat's and back cosmetic's places in the catalog, when they're drawn.
pub hat: Option<usize>,
pub back: Option<usize>,
pub age: f32,
pub crouching: bool,
pub fall_flying: bool,
pub chest_armor: bool,
/// The cape's turn back (radians), when one hangs.
pub cape_swing: Option<f32>,
}
/// A player seen this frame, for the trails left once a tick.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct Seen {
pub mob: u32,
/// The trail's place in the catalog.
pub trail: Option<usize>,
pub position: [f64; 3],
/// Where they were at the last tick's trail.
pub ticked: Option<[f64; 3]>,
/// The tick they were last seen.
pub tick: u64,
}
#[derive(Default)]
pub struct State {
pub jobs: Vec<Job>,
pub seen: Vec<Seen>,
/// The canvas holds the still pictures (a new atlas starts blank).
pub painted: bool,
/// When each cape was last drawn, and when moving ones were last painted (ms).
pub cape_drawn: [f64; CAPES],
pub capes_painted: f64,
/// The player's own feet at the last tick.
pub own: Option<[f64; 3]>,
pub ticks: u64,
/// The client's "Show Incari badges" (`settings.txt`'s `show-badges`).
pub show_badges: bool,
/// Milliseconds since the game started, as the last frame said.
pub now_ms: f64,
}
impl State {
/// `look`'s job for `job.mob`, in place of last frame's.
pub fn set_job(&mut self, job: Job) {
match self.jobs.iter_mut().find(|j| j.mob == job.mob) {
Some(j) => *j = job,
None => {
if self.jobs.len() >= 256 {
self.jobs.clear();
}
self.jobs.push(job);
}
}
}
pub fn job(&self, mob: u32) -> Option<Job> {
self.jobs.iter().find(|j| j.mob == mob).copied()
}
/// Player `mob` was drawn at `position`, wearing `trail`.
pub fn saw(&mut self, mob: u32, trail: Option<usize>, position: [f64; 3]) {
let tick = self.ticks;
match self.seen.iter_mut().find(|s| s.mob == mob) {
Some(s) => {
s.trail = trail;
s.position = position;
s.tick = tick;
}
None => self.seen.push(Seen {
mob,
trail,
position,
ticked: None,
tick,
}),
}
}
/// Once a tick: players not drawn for two seconds forgotten.
pub fn tick(&mut self) {
self.ticks += 1;
let ticks = self.ticks;
self.seen.retain(|s| ticks - s.tick < 40);
}
/// Cape `n` was drawn now.
pub fn cape_drawn(&mut self, n: usize) {
if n < CAPES {
self.cape_drawn[n] = self.now_ms;
}
}
/// Whether moving capes are due another frame; marks them painted.
pub fn capes_due(&mut self) -> bool {
if self.now_ms - self.capes_painted < 1000.0 / CAPE_FPS {
return false;
}
self.capes_painted = self.now_ms;
true
}
/// Whether cape `n` was drawn lately enough to move.
pub fn cape_moving(&self, n: usize) -> bool {
n < CAPES && self.cape_drawn[n] > 0.0 && self.now_ms - self.cape_drawn[n] < CAPE_IDLE_MS
}
}
thread_local! {
// The window's thread only.
static STATE: std::cell::RefCell<State> = std::cell::RefCell::new(State { show_badges: true, ..State::default() });
}
pub fn with<R>(f: impl FnOnce(&mut State) -> R) -> R {
STATE.with(|s| f(&mut s.borrow_mut()))
}
/// `settings.txt`'s `show-badges` (on unless it says false).
pub fn show_badges(settings: &str) -> bool {
!settings
.lines()
.filter_map(|l| l.split_once('='))
.any(|(k, v)| k.trim() == "show-badges" && v.trim() == "false")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn pictures_fit_the_canvas_apart() {
let mut rects = Vec::new();
for n in 0..CAPES {
let [x, y] = cape_slot(n);
rects.push([x, y, CAPE[0], CAPE[1]]);
}
for n in 0..MODELS {
let [x, y] = model_slot(n);
rects.push([x, y, MODEL, MODEL]);
}
for (i, a) in rects.iter().enumerate() {
assert!(
a[0] + a[2] <= CANVAS[0] && a[1] + a[3] <= CANVAS[1],
"{a:?}"
);
for b in &rects[..i] {
let apart = a[0] + a[2] <= b[0]
|| b[0] + b[2] <= a[0]
|| a[1] + a[3] <= b[1]
|| b[1] + b[3] <= a[1];
assert!(apart, "{a:?} {b:?}");
}
}
assert_eq!(
uv16([0, 0], [0.0, 0.0, 512.0, 256.0]),
[0.0, 0.0, 16.0, 16.0]
);
}
#[test]
fn jobs_and_sightings_are_kept_per_player() {
let mut s = State::default();
s.set_job(Job {
mob: 3,
hat: Some(8),
..Job::default()
});
s.set_job(Job {
mob: 3,
hat: None,
..Job::default()
});
assert_eq!(s.jobs.len(), 1);
assert_eq!(s.job(3).unwrap().hat, None);
s.saw(5, Some(26), [1.0, 2.0, 3.0]);
for _ in 0..40 {
s.tick();
}
assert!(s.seen.is_empty(), "not drawn for two seconds: forgotten");
assert!(show_badges("copy-screenshots=true\n") && !show_badges("show-badges=false\n"));
}
#[test]
fn moving_capes_paint_ten_times_a_second_while_seen() {
let mut s = State {
now_ms: 1_000.0,
..State::default()
};
s.cape_drawn(1);
assert!(s.capes_due() && !s.capes_due());
assert!(s.cape_moving(1) && !s.cape_moving(2));
s.now_ms = 3_500.0;
assert!(!s.cape_moving(1));
}
}
@@ -0,0 +1,29 @@
// A name in the tab list (ADR 0062; `Cosmetics.tabListName`): Incari's badge before it, as the
// player's name tag has it. The player's own has it too while they show others they use Incari.
fn incari_cosmetics_tab_list_name(
game: &crate::game::Game<'_>,
uuid: u128,
local: bool,
name: &mut horizon_client::text::Text,
) {
use horizon_client::text::{Style, Text};
use incari_core::cosmetics::badges;
use incari_core::online::Status;
let _ = game;
let show_badges = crate::game::incari_cosmetics::with(|s| s.show_badges);
let shows = incari_core::online::with(|o| {
if o.status() != Status::SignedIn {
return false;
}
if local { o.shows_badge() } else { o.player(uuid).is_some_and(|p| p.badge) && show_badges }
});
if shows {
let mut badged = Text::styled(
badges::GLYPH,
Style { font: Some(badges::FONT.into()), color: Some(badges::COLOR), ..Style::default() },
);
badged.push(Text::literal(" "));
badged.push(std::mem::take(name));
*name = badged;
}
}
@@ -0,0 +1,68 @@
// Once a tick (ADR 0061, `Cosmetics.tick`): emotes start and end (the wheel's own turning the
// camera to face the player while it plays), and trails are left behind moving players.
fn incari_cosmetics_tick(game: &mut crate::game::Game<'_>) {
use crate::game::incari_cosmetics as m;
use incari_core::cosmetics::{Slot, catalog, wardrobe, world};
let ticks = m::with(|s| {
s.tick();
s.ticks
});
if ticks % m::SETTINGS_TICKS == 1 {
let path = horizon_os::env::current_dir().unwrap_or_default().join("incari").join("settings.txt");
let text = horizon_os::fs::read(path).ok().and_then(|b| String::from_utf8(b).ok()).unwrap_or_default();
m::with(|s| s.show_badges = m::show_badges(&text));
}
let played: Vec<(u128, String)> =
incari_core::online::with(|o| o.take_emotes()).into_iter().map(|e| (e.player, e.emote)).collect();
let feet = game.native_player().map(|p| [p.x, p.y, p.z]);
let distance_sq = |a: [f64; 3], b: [f64; 3]| (0..3).map(|i| (a[i] - b[i]) * (a[i] - b[i])).sum::<f64>();
let moved_sq = match (feet, m::with(|s| s.own)) {
(Some(a), Some(b)) => distance_sq(a, b),
_ => 0.0,
};
m::with(|s| s.own = feet);
let camera = game.native_camera_type();
let (show_others, own_trail) = wardrobe::with(|w| (w.show_others(), w.worn().in_slot(Slot::Trail)));
let mut view = None;
let mut spawn = Vec::new();
world::with(|w| {
// The wheel's emote, now the player and the camera are known. The player's own is kept
// under 0, as `look` keeps it.
if let Some(emote) = w.take_own()
&& feet.is_some()
{
view = w.play_own(0, emote, camera);
}
// Moving (the player's keys, a jump, being pushed) cuts the player's own emote short.
if let Some(v) = w.tick(feet.is_some(), show_others, &played, moved_sq > 0.0004, camera) {
view = Some(v);
}
let Some(me) = feet else { return };
if let Some(trail) = own_trail
&& let Some(p) = w.trail(trail, 0, 0.0, moved_sq)
{
spawn.push((me, p));
}
m::with(|s| {
let ticks = s.ticks;
for seen in &mut s.seen {
let moved = seen.ticked.map_or(0.0, |b| distance_sq(seen.position, b));
seen.ticked = Some(seen.position);
let Some(trail) = seen.trail.and_then(|i| catalog::all().get(i)) else { continue };
if seen.tick + 1 < ticks {
continue;
}
if let Some(p) = w.trail(trail, seen.mob, distance_sq(seen.position, me), moved) {
spawn.push((seen.position, p));
}
}
});
});
if let Some(v) = view {
game.native_set_camera_type(v);
}
for (at, p) in spawn {
let at = [at[0] + p.offset[0], at[1] + p.offset[1], at[2] + p.offset[2]];
game.native_spawn_particle(p.kind, at, p.velocity);
}
}