use super::*;
#[allow(clippy::too_many_arguments)]
pub(super) fn paint_character_at(
buf: &mut RgbBuffer,
anim_name: &'static str,
frame_idx: usize,
anchor: Point,
agent: &AgentSlot,
pack: &Pack,
flip_x: bool,
glow_tint: Option<Rgb>,
cache: &mut FrameCache,
) {
let Some(anim) = pack.animation(anim_name) else {
return;
};
let Some(frame) = anim.frames.get(frame_idx).or_else(|| anim.frames.first()) else {
return;
};
let cached = cache.get_or_make(
crate::tui::frame_cache::FrameKey {
agent_id: agent.agent_id,
anim_name,
frame_idx,
flip_x,
glow_tint,
},
|| {
let pal = agent_palette(&pack.palette, agent, glow_tint);
let recolored = recolor_frame(frame, &pal, &pack.palette);
if flip_x {
recolored.mirror_horizontal()
} else {
recolored
}
},
);
blit_frame(cached, anchor.x, anchor.y, buf);
}
pub(super) fn seat_sprite(
kind: crate::tui::layout::WaypointKind,
facing: crate::tui::layout::Facing,
) -> (&'static str, bool) {
SeatView::of(kind, facing).seated_sprite()
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(super) enum SeatView {
Front,
Back,
Side { flip: bool },
}
impl SeatView {
pub(super) fn of(
kind: crate::tui::layout::WaypointKind,
facing: crate::tui::layout::Facing,
) -> Self {
use crate::tui::layout::{Facing, WaypointKind};
match kind {
WaypointKind::Couch | WaypointKind::MeetingSofa => match facing {
Facing::North => SeatView::Back,
_ => SeatView::Front,
},
WaypointKind::MeetingStand => SeatView::Side {
flip: matches!(facing, Facing::East),
},
WaypointKind::Pantry
| WaypointKind::PhoneBooth
| WaypointKind::StandingDesk
| WaypointKind::VendingMachine
| WaypointKind::Printer => SeatView::Side { flip: false },
}
}
pub(super) fn seated_sprite(self) -> (&'static str, bool) {
match self {
SeatView::Front => ("seated", false),
SeatView::Back => ("back_couch", false),
SeatView::Side { flip } => ("standing", flip),
}
}
pub(super) fn settle_walk(self) -> (bool, bool) {
match self {
SeatView::Front => (false, false),
SeatView::Back => (true, false),
SeatView::Side { flip } => (false, flip),
}
}
pub(super) fn z_key_for_seat(self, wp_pos: Point) -> u16 {
match self {
SeatView::Front | SeatView::Back => wp_pos.y + 2,
SeatView::Side { .. } => wp_pos.y + 3,
}
}
}
pub(super) fn settle_seat_view(cell: Point, layout: &Layout) -> Option<(SeatView, u16)> {
use pixtuoid_core::layout::{seated_foot_cell, Furniture};
layout
.waypoints
.iter()
.find_map(|w| {
(seated_foot_cell(w.kind.furniture(), w.pos) == Some(cell)).then(|| {
let view = SeatView::of(w.kind, w.facing);
(view, view.z_key_for_seat(w.pos))
})
})
.or_else(|| {
layout.home_desks.iter().find_map(|&desk| {
(seated_foot_cell(Furniture::Desk, desk) == Some(cell))
.then_some((SeatView::Front, desk.y + DESK_SEAT_Z_OFF))
})
})
}
pub(super) const DESK_SEAT_Z_OFF: u16 = 4;