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/cube_inventory.rs

40 lines
1.3 KiB
Rust
Raw Normal View History

2025-04-05 12:03:11 -04:00
use polariton_server::operations::{Operation, OperationCode};
use polariton::{operation::{Dict, Typed}, serdes::TypePrefix};
2025-03-30 16:22:25 -04:00
use rc_core::ConfigProvider;
const PARAM_KEY: u8 = 16;
2025-04-05 12:03:11 -04:00
pub struct CubeInventoryProvider {
cube_ids: Vec<u32>,
}
impl <C> Operation<C> for CubeInventoryProvider {
type State = ();
type User = crate::UserTy;
fn handle(&self, params: polariton::operation::ParameterTable<C>, _: &mut Self::State, _user: &Self::User) -> polariton::operation::OperationResponse<C> {
let mut params = params.to_dict();
params.insert(PARAM_KEY, Typed::Dict(Dict {
2025-03-08 17:16:02 -05:00
key_ty: TypePrefix::Int, // int
val_ty: TypePrefix::Int, // int
2025-04-05 12:03:11 -04:00
items: self.cube_ids.iter().map(|id| (Typed::Int(*id as _), Typed::Int(1))).collect()}));
polariton::operation::OperationResponse {
code: Self::op_code(),
return_code: 0,
message: polariton::operation::Typed::Null,
params: params.into(),
}
}
}
impl OperationCode for CubeInventoryProvider {
fn op_code() -> u8 {
16
}
}
pub(super) fn cube_inv_provider<'a>(cubes: &'a rc_core::ConfigImpl) -> CubeInventoryProvider {
let cube_ids = <rc_core::ConfigImpl as ConfigProvider<()>>::ids(cubes);
CubeInventoryProvider { cube_ids }
}