use arma_rs::{FromArma, IntoArma}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum VehicleCategory { Cars, Armor, Helis, Planes, Naval, Other, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct VGarage { pub cars: Vec, pub armor: Vec, pub helis: Vec, pub planes: Vec, pub naval: Vec, pub other: Vec, } impl VGarage { pub fn new() -> Self { Self::default_unlocks() } fn default_unlocks() -> Self { Self { cars: vec!["B_Quadbike_01_F".to_string()], armor: Vec::new(), helis: Vec::new(), planes: Vec::new(), naval: Vec::new(), other: Vec::new(), } } pub fn add(&mut self, category: VehicleCategory, classnames: Vec) { let target_array = match category { VehicleCategory::Cars => &mut self.cars, VehicleCategory::Armor => &mut self.armor, VehicleCategory::Helis => &mut self.helis, VehicleCategory::Planes => &mut self.planes, VehicleCategory::Naval => &mut self.naval, VehicleCategory::Other => &mut self.other, }; for classname in classnames { if !target_array.contains(&classname) { target_array.push(classname); } } } pub fn get(&self, category: VehicleCategory) -> &Vec { match category { VehicleCategory::Cars => &self.cars, VehicleCategory::Armor => &self.armor, VehicleCategory::Helis => &self.helis, VehicleCategory::Planes => &self.planes, VehicleCategory::Naval => &self.naval, VehicleCategory::Other => &self.other, } } pub fn remove(&mut self, category: VehicleCategory, classname: &str) -> Option { let target_array = match category { VehicleCategory::Cars => &mut self.cars, VehicleCategory::Armor => &mut self.armor, VehicleCategory::Helis => &mut self.helis, VehicleCategory::Planes => &mut self.planes, VehicleCategory::Naval => &mut self.naval, VehicleCategory::Other => &mut self.other, }; if let Some(pos) = target_array.iter().position(|x| x == classname) { Some(target_array.remove(pos)) } else { None } } } impl FromArma for VGarage { fn from_arma(s: String) -> Result { serde_json::from_str(&s) .map_err(|e| arma_rs::FromArmaError::InvalidPrimitive(format!("Invalid JSON: {}", e))) } } impl IntoArma for VGarage { fn to_arma(&self) -> arma_rs::Value { let json_str = serde_json::to_string(self).unwrap_or_default(); arma_rs::Value::String(json_str) } }