Compare commits

...

4 Commits

Author SHA1 Message Date
Max Bradbury e5a87f854e this would break things 2020-11-08 17:35:08 +00:00
Max Bradbury c2787db422 better load_image errors 2020-11-08 17:34:48 +00:00
Max Bradbury 7d274bb3c2 this function doesn't return anything 2020-11-08 17:33:39 +00:00
Max Bradbury fbe40fb866 dedupe palette function 2020-11-08 17:33:15 +00:00
3 changed files with 20 additions and 23 deletions

View File

@ -5,4 +5,3 @@
* noise reduction (remove lonely pixels)
* implement Atkinson and Bayer dithering options
* stats for added room (number of tiles)
* dedupe "palette from custom colours" functionality

View File

@ -96,7 +96,7 @@ async function run() {
}
function new_game() {
console.debug(load_default_game());
load_default_game();
textareaGameDataInput.value = output();
checkGameData();
// we don't need to look at the default game data, so skip ahead to the image page

View File

@ -95,6 +95,11 @@ pub fn load_image(image_base64: String) -> String {
let mut state = STATE.lock().expect("Couldn't lock application state");
let image_base64: Vec<&str> = image_base64.split("base64,").collect();
if image_base64.len() < 2 {
return format!("Error: Badly-formatted base64: {}", image_base64.join(""));
}
let image_base64 = image_base64[1];
match base64::decode(image_base64) {
@ -109,13 +114,13 @@ pub fn load_image(image_base64: String) -> String {
},
_ => {
state.image = None;
"Couldn't load image".to_string()
"Error: Couldn't load image".to_string()
}
}
},
_ => {
state.image = None;
"Couldn't decode image".to_string()
"Error: Couldn't decode image".to_string()
}
}
}
@ -185,19 +190,23 @@ fn image_to_base64(image: &DynamicImage) -> String {
format!("data:image/png;base64,{}", base64::encode(&bytes))
}
fn palette_from(bg: &bitsy_parser::Colour, fg: &bitsy_parser::Colour) -> bitsy_parser::Palette {
bitsy_parser::Palette {
id: "0".to_string(),
name: None,
colours: vec![
bg.clone(), fg.clone(), bitsy_parser::Colour { red: 0, green: 0, blue: 0 }
],
}
}
fn render_preview(state: &State) -> DynamicImage {
let mut buffer = state.image.as_ref().unwrap().clone().into_rgba();
let palette = match &state.palette {
SelectedPalette::None => bitsy_parser::mock::game_default().palettes[0].clone(),
SelectedPalette::Existing { id } => state.game.as_ref().unwrap().get_palette(id).unwrap().clone(),
SelectedPalette::New { background, foreground } => bitsy_parser::Palette {
id: "0".to_string(),
name: None,
colours: vec![
background.clone(), foreground.clone(), bitsy_parser::Colour { red: 0, green: 0, blue: 0 }
],
},
SelectedPalette::New { background, foreground } => palette_from(background, foreground),
};
let colour_map = crate::ColourMap::from(&palette);
@ -258,15 +267,7 @@ pub fn add_room() -> String {
SelectedPalette::None => bitsy_parser::mock::game_default().palettes[0].id.clone(),
SelectedPalette::Existing { id } => id.clone(),
SelectedPalette::New { background, foreground } => {
game.add_palette(bitsy_parser::Palette {
id: "0".to_string(),
name: None,
colours: vec![
background.clone(),
foreground.clone(),
bitsy_parser::Colour { red: 0, green: 0, blue: 0 }
],
})
game.add_palette(palette_from(background, foreground))
},
});
@ -319,9 +320,6 @@ pub fn add_room() -> String {
}
}
// todo if player selected "create new game", delete room 0 here?
// that would probably break unless the avatar was also placed in the room
game.add_room(bitsy_parser::Room {
id: "0".to_string(),
palette_id,