From f18b0de2518012ff243ae37ae7c9c51c7f1b3491 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sat, 25 Apr 2020 14:17:52 +0100 Subject: [PATCH] check if line is numeric before appending it to pixel data; check if colour ID is ok --- src/avatar.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/avatar.rs b/src/avatar.rs index 3357ec4..a4c3939 100644 --- a/src/avatar.rs +++ b/src/avatar.rs @@ -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; /// 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") { name = Some(last_line.replace("NAME ", "")); } else if last_line.starts_with("COL") { - colour_id = Some(last_line.replace("COL ", "").parse().unwrap()); - } else { + let last_line = last_line.replace("COL ", ""); + 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); break; }