(&self, context: &mut Context, command: &'static str,
nav_state_top: Option<(&NavigationPosition, &'static str)>)
| 190 | } |
| 191 | |
| 192 | fn init_navigation_context(&self, context: &mut Context, command: &'static str, |
| 193 | nav_state_top: Option<(&NavigationPosition, &'static str)>) { |
| 194 | context.set_variable("NavCommand", command); |
| 195 | |
| 196 | if command == "WhereAmI" && self.where_am_i == NavigationPosition::default() { |
| 197 | context.set_variable("NavNode", self.where_am_i.current_node.as_str()); |
| 198 | context.set_variable("NavNodeOffset", self.where_am_i.current_node_offset as f64); |
| 199 | } else { |
| 200 | let position = &self.position_stack[self.position_stack.len()-1]; |
| 201 | context.set_variable("NavNode", position.current_node.as_str()); |
| 202 | context.set_variable("NavNodeOffset", position.current_node_offset as f64); |
| 203 | } |
| 204 | |
| 205 | // get the index from command (e.g., '3' in 'SetPlacemarker3 or MoveTo3' and set 'PlaceMarker' to it's position) |
| 206 | if command.ends_with(|ch: char| ch.is_ascii_digit()) { |
| 207 | let index = convert_last_char_to_number(command); |
| 208 | let position = &self.place_markers[index]; |
| 209 | context.set_variable("PlaceMarkerIndex", index as f64); |
| 210 | context.set_variable("PlaceMarker", position.current_node.as_str()); |
| 211 | context.set_variable("PlaceMarkerOffset", position.current_node_offset as f64); |
| 212 | } |
| 213 | |
| 214 | context.set_variable("ReadZoomLevel", (if self.mode == "Enhanced" {-1} else {1}) as f64); |
| 215 | context.set_variable("MatchCounter", 0 as f64); |
| 216 | |
| 217 | if command == "MoveLastLocation" { |
| 218 | let previous_command = match nav_state_top { |
| 219 | None => "None", |
| 220 | Some( (_, previous_command) ) => previous_command, |
| 221 | }; |
| 222 | context.set_variable("PreviousNavCommand", previous_command); |
| 223 | } |
| 224 | |
| 225 | // used by nav rules for speech -- needs an initial value so tests don't fail |
| 226 | context.set_variable("Move2D", "" ); |
| 227 | context.set_variable("SpeakExpression", true ); // default is to speak the expr after navigation |
| 228 | return; |
| 229 | |
| 230 | fn convert_last_char_to_number(str: &str) -> usize { |
| 231 | let last_char = str.as_bytes()[str.len()-1]; |
| 232 | assert!( last_char.is_ascii_digit() ); |
| 233 | return (last_char - b'0') as usize; |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // convert the last digit of a Placemarker command to an integer |
no test coverage detected