Buttplug sex toy control library

chore: Fix user defined device creation

Don't create extra features

+34 -13
+1 -1
crates/buttplug_server_device_config/src/device_config_file/device.rs
··· 104 104 &self, 105 105 base: &ServerDeviceDefinition, 106 106 ) -> Result<ServerDeviceDefinition, ButtplugDeviceConfigError> { 107 - let mut builder = ServerDeviceDefinitionBuilder::from_base(base, self.id); 107 + let mut builder = ServerDeviceDefinitionBuilder::from_base(base, self.id, false); 108 108 builder.display_name(&self.user_config.display_name); 109 109 if let Some(message_gap_ms) = self.user_config.message_gap_ms { 110 110 builder.message_gap_ms(message_gap_ms);
+5 -4
crates/buttplug_server_device_config/src/device_config_file/mod.rs
··· 192 192 .base_device_definitions() 193 193 .get(&user_device_config_pair.identifier().into()) 194 194 { 195 - if let Ok(user_config) = user_device_config_pair 195 + if let Ok(loaded_user_config) = user_device_config_pair 196 196 .config() 197 - .build_from_base_definition(base_config) 198 - && let Err(e) = 199 - dcm_builder.user_device_definition(user_device_config_pair.identifier(), &user_config) 197 + .build_from_base_definition(base_config) { 198 + if let Err(e) = 199 + dcm_builder.user_device_definition(user_device_config_pair.identifier(), &loaded_user_config) 200 200 { 201 201 error!( 202 202 "Device definition not valid, skipping:\n{:?}\n{:?}", 203 203 e, user_config 204 204 ) 205 205 } 206 + } 206 207 } else { 207 208 error!( 208 209 "Device identifier {:?} does not have a match base identifier that matches anything in the base config, removing from database.",
+2 -2
crates/buttplug_server_device_config/src/device_config_manager.rs
··· 274 274 "Protocol + Identifier device config found for {:?}, creating new user device from configuration", 275 275 identifier 276 276 ); 277 - let mut builder = ServerDeviceDefinitionBuilder::from_base(definition, Uuid::new_v4()); 277 + let mut builder = ServerDeviceDefinitionBuilder::from_base(definition, Uuid::new_v4(), true); 278 278 builder.index(self.device_index(identifier)).finish() 279 279 } else if let Some(definition) = self 280 280 .base_device_definitions ··· 284 284 "Protocol device config found for {:?}, creating new user device from protocol defaults", 285 285 identifier 286 286 ); 287 - let mut builder = ServerDeviceDefinitionBuilder::from_base(definition, Uuid::new_v4()); 287 + let mut builder = ServerDeviceDefinitionBuilder::from_base(definition, Uuid::new_v4(), true); 288 288 builder.index(self.device_index(identifier)).finish() 289 289 } else { 290 290 return None;
+14 -2
crates/buttplug_server_device_config/src/device_definitions.rs
··· 27 27 features: Vec<ServerDeviceFeature>, 28 28 } 29 29 30 + #[derive(Debug)] 30 31 pub struct ServerDeviceDefinitionBuilder { 31 32 def: ServerDeviceDefinition, 32 33 } ··· 50 51 } 51 52 52 53 // Used to create new user definitions from a base definition. 53 - pub fn from_base(value: &ServerDeviceDefinition, id: Uuid) -> Self { 54 + pub fn from_base(value: &ServerDeviceDefinition, id: Uuid, with_features: bool) -> Self { 54 55 let mut value = value.clone(); 55 56 value.base_id = Some(value.id); 56 57 value.id = id; 57 - value.features = value.features().iter().map(|x| x.as_new_user_feature()).collect(); 58 + if with_features { 59 + value.features = value.features().iter().map(|x| x.as_new_user_feature()).collect(); 60 + } else { 61 + value.features = vec!(); 62 + } 58 63 ServerDeviceDefinitionBuilder { def: value } 59 64 } 60 65 ··· 104 109 105 110 pub fn add_feature(&mut self, feature: &ServerDeviceFeature) -> &mut Self { 106 111 self.def.features.push(feature.clone()); 112 + self 113 + } 114 + 115 + pub fn replace_feature(&mut self, feature: &ServerDeviceFeature) -> &mut Self { 116 + if let Some(f) = self.def.features.iter_mut().find(|x| x.id() == feature.id()) { 117 + *f = feature.clone(); 118 + } 107 119 self 108 120 } 109 121
+12 -4
crates/buttplug_server_device_config/src/server_device_feature.rs
··· 51 51 } 52 52 } 53 53 54 + pub fn new_with_user(base: &RangeInclusive<i32>, user: &Option<RangeInclusive<u32>>) -> Self { 55 + Self { 56 + base: base.clone(), 57 + internal_base: RangeInclusive::new(0, *base.end() as u32), 58 + user: user.clone(), 59 + } 60 + } 61 + 54 62 pub fn step_limit(&self) -> RangeInclusive<i32> { 55 63 if *self.base.start() < 0 { 56 64 RangeInclusive::new(-(self.step_count() as i32), self.step_count() as i32) ··· 280 288 } 281 289 282 290 #[derive(Clone, Debug, Getters, Setters, Default)] 283 - #[getset(get = "pub", set = "pub(crate)")] 291 + #[getset(get = "pub", set = "pub")] 284 292 pub struct ServerDeviceFeatureOutput { 285 293 vibrate: Option<ServerDeviceFeatureOutputValueProperties>, 286 294 rotate: Option<ServerDeviceFeatureOutputValueProperties>, ··· 304 312 OutputType::Position => self.position.is_some(), 305 313 OutputType::PositionWithDuration => self.position_with_duration.is_some(), 306 314 OutputType::Rotate => self.rotate.is_some(), 307 - OutputType::RotateWithDirection => self.rotate_with_direction.is_some(), 315 + OutputType::RotateWithDirection => self.rotate.is_some(), 308 316 OutputType::Spray => self.spray.is_some(), 309 317 OutputType::Unknown => false, 310 318 OutputType::Vibrate => self.vibrate.is_some(), ··· 532 540 } 533 541 } 534 542 535 - #[derive(Clone, Debug, Getters, CopyGetters)] 543 + #[derive(Clone, Debug, Getters, CopyGetters, Setters)] 536 544 pub struct ServerDeviceFeature { 537 545 #[getset(get = "pub")] 538 546 description: String, ··· 542 550 base_id: Option<Uuid>, 543 551 #[getset(get_copy = "pub")] 544 552 alt_protocol_index: Option<u32>, 545 - #[getset(get = "pub")] 553 + #[getset(get = "pub", set = "pub")] 546 554 output: Option<ServerDeviceFeatureOutput>, 547 555 #[getset(get = "pub")] 548 556 input: Option<ServerDeviceFeatureInput>,