Compare commits
No commits in common. "e5a87f854ec7a63041cd7979b6b6d8b457b5e0aa" and "7ff67e51f8190cc5002317e0d37628fe367297e3" have entirely different histories.
e5a87f854e
...
7ff67e51f8
1
TODO.md
1
TODO.md
|
@ -5,3 +5,4 @@
|
|||
* noise reduction (remove lonely pixels)
|
||||
* implement Atkinson and Bayer dithering options
|
||||
* stats for added room (number of tiles)
|
||||
* dedupe "palette from custom colours" functionality
|
||||
|
|
|
@ -96,7 +96,7 @@ async function run() {
|
|||
}
|
||||
|
||||
function new_game() {
|
||||
load_default_game();
|
||||
console.debug(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
|
||||
|
|
40
src/lib.rs
40
src/lib.rs
|
@ -95,11 +95,6 @@ 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) {
|
||||
|
@ -114,13 +109,13 @@ pub fn load_image(image_base64: String) -> String {
|
|||
},
|
||||
_ => {
|
||||
state.image = None;
|
||||
"Error: Couldn't load image".to_string()
|
||||
"Couldn't load image".to_string()
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
state.image = None;
|
||||
"Error: Couldn't decode image".to_string()
|
||||
"Couldn't decode image".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -190,23 +185,19 @@ 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 } => palette_from(background, foreground),
|
||||
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 }
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
let colour_map = crate::ColourMap::from(&palette);
|
||||
|
@ -267,7 +258,15 @@ 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(palette_from(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 }
|
||||
],
|
||||
})
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -320,6 +319,9 @@ 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,
|
||||
|
|
Loading…
Reference in New Issue