give feedback on errors
This commit is contained in:
parent
d32ad0d27d
commit
ffd8a15eda
21
src/lib.rs
21
src/lib.rs
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue