Files
ojrc/rc_services_room/src/operations/machine_colour.rs
T

22 lines
972 B
Rust
Raw Normal View History

2025-03-01 16:22:57 -05:00
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed};
// const USERNAME_PARAM_KEY: u8 = 30; // str
const SLOT_PARAM_KEY: u8 = 31; // int
const DATA_PARAM_KEY: u8 = 33; // byte arr
pub(super) fn garage_machine_colour_provider() -> SimpleFunc<33, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
2025-03-15 11:03:35 -04:00
SimpleFunc::new(|params, user: &crate::UserTy| {
2025-03-01 16:22:57 -05:00
let mut params = params.to_dict();
2025-03-30 16:22:25 -04:00
let user_info = user.user()?;
2025-03-15 11:03:35 -04:00
if let Some(Typed::Int(garage_slot)) = params.get(&SLOT_PARAM_KEY) {
2025-03-01 16:22:57 -05:00
log::debug!("Got machine colour request for slot {:?}", garage_slot);
2025-03-15 11:03:35 -04:00
let machine = user_info.slot_by_id(*garage_slot)?;
params.insert(DATA_PARAM_KEY, machine.colour_data);
2025-03-01 16:22:57 -05:00
} else {
2025-03-15 11:03:35 -04:00
params.insert(SLOT_PARAM_KEY, Typed::Int(user_info.selected_garage_slot() as _));
2025-03-01 16:22:57 -05:00
}
2025-03-15 11:03:35 -04:00
2025-03-01 16:22:57 -05:00
Ok(params.into())
})
}