1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00
Files
ojrc/rc_services_room/src/operations/garage_slot_select.rs
2025-05-10 13:19:35 -04:00

36 lines
1.0 KiB
Rust

use polariton::operation::{ParameterTable, Typed, OperationResponse};
const CODE: u8 = 44;
const SLOT_PARAM_KEY: u8 = 48; // uint; in
pub(super) fn garage_slot_selector() -> SlotSelector {
SlotSelector
}
async fn do_select(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
let mut params = params.to_dict();
let user_info = user.user()?;
if let Some(Typed::Int(to_select)) = params.remove(&SLOT_PARAM_KEY) {
user_info.select_garage(to_select).await?;
}
Ok(params.into())
}
pub struct SlotSelector;
#[async_trait::async_trait]
impl polariton_server::operations::Operation<()> for SlotSelector {
type User = crate::UserTy;
async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> {
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_select(params, user).await)
}
}
impl polariton_server::operations::OperationCode for SlotSelector {
fn op_code() -> u8 {
CODE
}
}