2025-04-05 12:03:11 -04:00
|
|
|
use polariton_server::operations::{Operation, OperationCode};
|
|
|
|
|
use polariton::{operation::{Dict, Typed}, serdes::TypePrefix};
|
2025-06-03 21:09:03 -04:00
|
|
|
use oj_rc_core::ConfigProvider;
|
2025-02-23 16:10:21 -05:00
|
|
|
|
|
|
|
|
const PARAM_KEY: u8 = 16;
|
|
|
|
|
|
2025-04-05 12:03:11 -04:00
|
|
|
pub struct CubeInventoryProvider {
|
|
|
|
|
cube_ids: Vec<u32>,
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-06 11:00:37 -04:00
|
|
|
impl <C: Send + 'static> Operation<C> for CubeInventoryProvider {
|
2025-04-05 12:03:11 -04:00
|
|
|
type User = crate::UserTy;
|
|
|
|
|
|
2025-04-06 11:00:37 -04:00
|
|
|
fn handle(&self, params: polariton::operation::ParameterTable<C>, _user: &Self::User) -> polariton::operation::OperationResponse<C> {
|
2025-02-23 16:10:21 -05:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-03 21:09:03 -04:00
|
|
|
pub(super) fn cube_inv_provider<'a>(cubes: &'a oj_rc_core::ConfigImpl) -> CubeInventoryProvider {
|
|
|
|
|
let cube_ids = <oj_rc_core::ConfigImpl as ConfigProvider<()>>::ids(cubes);
|
2025-04-05 12:03:11 -04:00
|
|
|
CubeInventoryProvider { cube_ids }
|
2025-02-23 16:10:21 -05:00
|
|
|
}
|