(&self, path: PathBuf)
| 226 | } |
| 227 | |
| 228 | pub fn apply_profile(&self, path: PathBuf) -> Result<(), Box<dyn Error>> { |
| 229 | // apply a profile to the features |
| 230 | |
| 231 | let json = std::fs::read_to_string(&path)?; |
| 232 | let saved: BlasterXG6 = serde_json::from_str(&json)?; |
| 233 | |
| 234 | for feature in &saved.features { |
| 235 | // don't write features that haven't been changed from defautl |
| 236 | if feature.value() == 0.0 { |
| 237 | continue; |
| 238 | } |
| 239 | |
| 240 | // don't write sliders if their toggle is off |
| 241 | if matches!(feature.id.value_kind(), ValueKind::Ranged { .. }) { |
| 242 | if let Some(toggle_id) = feature.id.paired_toggle() { |
| 243 | if self.feature(toggle_id).value() == 0.0 { |
| 244 | continue; |
| 245 | } |
| 246 | }; |
| 247 | } |
| 248 | |
| 249 | self.set_feature(feature.id, Some(feature.value()))?; |
| 250 | } |
| 251 | |
| 252 | info!("Applied Profile ({:?})", path); |
| 253 | |
| 254 | Ok(()) |
| 255 | } |
| 256 | } |
no test coverage detected