give feedback on errors

This commit is contained in:
Max Bradbury 2020-07-19 22:02:57 +01:00
parent d32ad0d27d
commit ffd8a15eda
1 changed files with 16 additions and 5 deletions

View File

@ -26,14 +26,25 @@ fn tile_name(prefix: &str, index: &u32) -> Option<String> {
/// prefix will be ignored if empty
#[wasm_bindgen]
pub fn add_tiles(game_data: String, image: String, prefix: String) -> String {
let mut game = Game::from(game_data)
.expect("Couldn't parse game data");
let game = Game::from(game_data);
if game.is_err() {
return format!("Couldn't parse game data");
}
let mut game = game.unwrap();
let image: Vec<&str> = image.split("base64,").collect();
let image = image[1];
let image = base64::decode(image).unwrap();
let image = image::load_from_memory(image.as_ref())
.expect("Couldn't load image");
let image = base64::decode(image);
if image.is_err() {
return format!("Couldn't decode image");
}
let image = image.unwrap();
let image = image::load_from_memory(image.as_ref());
if image.is_err() {
return format!("Couldn't load image");
}
let image = image.unwrap();
let width = image.width();
let height = image.height();