mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Make edit mode usable; complete #11
This commit is contained in:
1 parent
47eb32056c
commit
6fd4d673ca
40 files changed
+5313
-2162
No files matched your search
@@ -1,9 +1,6 @@
|
||||
use polariton_server::operations::SimpleFunc;
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
|
||||
use crate::data::weapon_list::ItemCategory;
|
||||
use crate::data::garage_bay::*;
|
||||
|
||||
const SLOT_PARAM_KEY: u8 = 45; // uint
|
||||
const DATA_PARAM_KEY: u8 = 49; // byte arr
|
||||
const CUBES_COUNT_PARAM_KEY: u8 = 51; // int
|
||||
@@ -14,20 +11,68 @@ const CONTROL_OPTIONS_PARAM_KEY: u8 = 60; // bool arr
|
||||
const MASTERY_LEVEL_PARAM_KEY: u8 = 18; // int
|
||||
|
||||
pub(super) fn garage_machine_provider() -> SimpleFunc<43, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
|
||||
SimpleFunc::new(|params, _| {
|
||||
SimpleFunc::new(|params, user: &crate::UserTy| {
|
||||
let mut params = params.to_dict();
|
||||
if let Some(garage_slot) = params.get(&SLOT_PARAM_KEY) {
|
||||
let lock = user.read().unwrap();
|
||||
let user_info = lock.user()?;
|
||||
if let Some(Typed::Int(garage_slot)) = params.get(&SLOT_PARAM_KEY) {
|
||||
log::debug!("Got machine request for slot {:?}", garage_slot);
|
||||
let machine = user_info.slot_by_id(*garage_slot)?;
|
||||
params.insert(DATA_PARAM_KEY, machine.data);
|
||||
params.insert(CUBES_COUNT_PARAM_KEY, machine.cube_count);
|
||||
params.insert(WEAPON_ORDER_PARAM_KEY, machine.weapon_order);
|
||||
params.insert(MOVEMENT_CATEGORIES_PARAM_KEY, machine.movement_categories);
|
||||
params.insert(CONTROL_TYPE_PARAM_KEY, machine.control_type);
|
||||
params.insert(CONTROL_OPTIONS_PARAM_KEY, machine.control_options);
|
||||
params.insert(MASTERY_LEVEL_PARAM_KEY, machine.mastery_level);
|
||||
} else {
|
||||
params.insert(SLOT_PARAM_KEY, Typed::Int(0));
|
||||
params.insert(SLOT_PARAM_KEY, Typed::Int(user_info.selected_garage_slot() as _));
|
||||
}
|
||||
params.insert(DATA_PARAM_KEY, Typed::Bytes(vec![0u8, 0u8, 0u8, 0u8].into())); // first 4 bytes are i32 for length of rest of data
|
||||
params.insert(CUBES_COUNT_PARAM_KEY, Typed::Int(1));
|
||||
params.insert(WEAPON_ORDER_PARAM_KEY, Typed::IntArr(vec![0].into()));
|
||||
params.insert(MOVEMENT_CATEGORIES_PARAM_KEY, Typed::IntArr(vec![ItemCategory::Wheel.but_bigger()].into()));
|
||||
params.insert(CONTROL_TYPE_PARAM_KEY, Typed::Int(ControlType::Camera as _));
|
||||
params.insert(CONTROL_OPTIONS_PARAM_KEY, ControlOptions { vertical_strafing: false, sideways_driving: false, tracks_turn_on_spot: false, }.as_transmissible());
|
||||
params.insert(MASTERY_LEVEL_PARAM_KEY, Typed::Int(0));
|
||||
Ok(params.into())
|
||||
})
|
||||
}
|
||||
|
||||
const ERROR_PARAM_KEY: u8 = 47; // int
|
||||
//const UUID_PARAM_KEY: u8 = 54; // str
|
||||
const COMPRESSED_ROBOT_DATA_PARAM_KEY: u8 = 46; // byte arr
|
||||
const COMPRESSED_COLOUR_DATA_PARAM_KEY: u8 = 33; // byte arr
|
||||
|
||||
const INVALID_ROBOT_ERR: i16 = 140;
|
||||
|
||||
pub(super) fn garage_machine_save_provider() -> SimpleFunc<41, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
|
||||
SimpleFunc::new(|params, user: &crate::UserTy| {
|
||||
log::debug!("machine save params: {:?}", params);
|
||||
let mut params = params.to_dict();
|
||||
if let Some(Typed::Int(slot_index)) = params.remove(&SLOT_PARAM_KEY) {
|
||||
if let Some(Typed::Bytes(robot_data)) = params.remove(&COMPRESSED_ROBOT_DATA_PARAM_KEY) {
|
||||
if let Some(Typed::Bytes(colour_data)) = params.remove(&COMPRESSED_COLOUR_DATA_PARAM_KEY) {
|
||||
if let Some(Typed::Arr(weapon_order)) = params.remove(&WEAPON_ORDER_PARAM_KEY) {
|
||||
let weapon_order_filtered: Vec<_> = weapon_order.items.into_iter().filter_map(|ty| if let Typed::Int(i) = ty { Some(i) } else { None }).collect();
|
||||
let lock = user.read().unwrap();
|
||||
let user_info = lock.user()?;
|
||||
let vehicle_data = crate::persist::user::VehicleData {
|
||||
id: slot_index,
|
||||
robot_data: robot_data.vec,
|
||||
colour_data: colour_data.vec,
|
||||
weapon_order: weapon_order_filtered,
|
||||
};
|
||||
user_info.save_slot(vehicle_data)?;
|
||||
let mut params_out = std::collections::HashMap::with_capacity(1);
|
||||
params_out.insert(ERROR_PARAM_KEY, Typed::Int(0));
|
||||
return Ok(params_out.into());
|
||||
} else {
|
||||
log::warn!("weapon order is not this type (or does not exist)");
|
||||
}
|
||||
} else {
|
||||
log::warn!("colour data is not this type (or does not exist)");
|
||||
}
|
||||
} else {
|
||||
log::warn!("robot data is not this type (or does not exist)");
|
||||
}
|
||||
} else {
|
||||
log::warn!("slot is not this type (or does not exist)");
|
||||
}
|
||||
Err(INVALID_ROBOT_ERR)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user