check if line is numeric before appending it to pixel data; check if colour ID is ok

This commit is contained in:
Max Bradbury 2020-04-25 14:17:52 +01:00
parent 5184060372
commit f18b0de251
1 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,4 @@
use crate::{from_base36, optional_data_line, AnimationFrames, Image, Position, ToBase36}; use crate::{from_base36, optional_data_line, AnimationFrames, Image, Position, ToBase36, is_string_numeric};
use std::error::Error; use std::error::Error;
/// avatar is a "sprite" in the game data but with a specific id /// avatar is a "sprite" in the game data but with a specific id
@ -51,8 +51,14 @@ impl Avatar {
} else if last_line.starts_with("NAME") { } else if last_line.starts_with("NAME") {
name = Some(last_line.replace("NAME ", "")); name = Some(last_line.replace("NAME ", ""));
} else if last_line.starts_with("COL") { } else if last_line.starts_with("COL") {
colour_id = Some(last_line.replace("COL ", "").parse().unwrap()); let last_line = last_line.replace("COL ", "");
} else { let result = last_line.parse();
if result.is_ok() {
colour_id = Some(result.unwrap());
} else {
println!("Bad colour id: {}", last_line)
}
} else if is_string_numeric(last_line.to_string()) {
lines.push(last_line); lines.push(last_line);
break; break;
} }