| 124 | } |
| 125 | |
| 126 | pub(crate) fn parse_text_map(cur: &str) -> Result<GameMap, Error> { |
| 127 | let mut tok = Tok { |
| 128 | cur, |
| 129 | line: 0, |
| 130 | col: 0 |
| 131 | }; |
| 132 | |
| 133 | let mut orbit_amplitude: Option<Rounds> = None; |
| 134 | let mut orbit_period: Option<Rounds> = None; |
| 135 | let mut orbit_center: Option<Rounds> = None; |
| 136 | let mut seed: Option<u16> = None; |
| 137 | |
| 138 | let mut names = FnvHashMap::<char, Thing>::default(); |
| 139 | |
| 140 | let mut cur_planet: Option<Planet> = None; |
| 141 | let mut planets = [ |
| 142 | PlanetData { width: None, height: None, symmetry: None, cur_y: None, things: FnvHashMap::default() }, |
| 143 | PlanetData { width: None, height: None, symmetry: None, cur_y: None, things: FnvHashMap::default() } |
| 144 | ]; |
| 145 | let mut asteroids: Vec<(usize, usize, usize, usize)> = vec![]; |
| 146 | |
| 147 | while tok.has() { |
| 148 | let start = tok.chew(); |
| 149 | if start.is_none() { |
| 150 | continue; |
| 151 | } |
| 152 | let start = start.unwrap(); |
| 153 | if start == "EARTH" || start == "MARS" { |
| 154 | if tok.chew() != Some(":") { |
| 155 | bail!("{} must be followed by a colon!", start); |
| 156 | } |
| 157 | cur_planet = if start == "EARTH" { |
| 158 | Some(Planet::Earth) |
| 159 | } else { |
| 160 | Some(Planet::Mars) |
| 161 | }; |
| 162 | continue; |
| 163 | } |
| 164 | if start == ">" { |
| 165 | if cur_planet.is_none() { |
| 166 | bail!("need to set planet to draw map at line {} col {}", tok.line, tok.col); |
| 167 | } |
| 168 | let p = cur_planet.unwrap() as usize; |
| 169 | |
| 170 | let y = planets[p].cur_y; |
| 171 | if y.is_none() { |
| 172 | bail!("need to set height before drawing map at line {} col {}", tok.line, tok.col); |
| 173 | } |
| 174 | let y = y.unwrap(); |
| 175 | if y == 9999 { |
| 176 | bail!("too many lines in map at line {} col {}", tok.line, tok.col); |
| 177 | } |
| 178 | let sym = planets[p].symmetry; |
| 179 | if sym.is_none() { |
| 180 | bail!("need to set symmetry before drawing map at line {} col {}", tok.line, tok.col); |
| 181 | } |
| 182 | let sym = sym.unwrap(); |
| 183 | let height = planets[p].height; |