Compare commits
4 Commits
7ff67e51f8
...
e5a87f854e
Author | SHA1 | Date |
---|---|---|
Max Bradbury | e5a87f854e | |
Max Bradbury | c2787db422 | |
Max Bradbury | 7d274bb3c2 | |
Max Bradbury | fbe40fb866 |
1
TODO.md
1
TODO.md
|
@ -5,4 +5,3 @@
|
||||||
* noise reduction (remove lonely pixels)
|
* noise reduction (remove lonely pixels)
|
||||||
* implement Atkinson and Bayer dithering options
|
* implement Atkinson and Bayer dithering options
|
||||||
* stats for added room (number of tiles)
|
* stats for added room (number of tiles)
|
||||||
* dedupe "palette from custom colours" functionality
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ async function run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function new_game() {
|
function new_game() {
|
||||||
console.debug(load_default_game());
|
load_default_game();
|
||||||
textareaGameDataInput.value = output();
|
textareaGameDataInput.value = output();
|
||||||
checkGameData();
|
checkGameData();
|
||||||
// we don't need to look at the default game data, so skip ahead to the image page
|
// 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,6 +95,11 @@ pub fn load_image(image_base64: String) -> String {
|
||||||
let mut state = STATE.lock().expect("Couldn't lock application state");
|
let mut state = STATE.lock().expect("Couldn't lock application state");
|
||||||
|
|
||||||
let image_base64: Vec<&str> = image_base64.split("base64,").collect();
|
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];
|
let image_base64 = image_base64[1];
|
||||||
|
|
||||||
match base64::decode(image_base64) {
|
match base64::decode(image_base64) {
|
||||||
|
@ -109,13 +114,13 @@ pub fn load_image(image_base64: String) -> String {
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
state.image = None;
|
state.image = None;
|
||||||
"Couldn't load image".to_string()
|
"Error: Couldn't load image".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
state.image = None;
|
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))
|
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 {
|
fn render_preview(state: &State) -> DynamicImage {
|
||||||
let mut buffer = state.image.as_ref().unwrap().clone().into_rgba();
|
let mut buffer = state.image.as_ref().unwrap().clone().into_rgba();
|
||||||
|
|
||||||
let palette = match &state.palette {
|
let palette = match &state.palette {
|
||||||
SelectedPalette::None => bitsy_parser::mock::game_default().palettes[0].clone(),
|
SelectedPalette::None => bitsy_parser::mock::game_default().palettes[0].clone(),
|
||||||
SelectedPalette::Existing { id } => state.game.as_ref().unwrap().get_palette(id).unwrap().clone(),
|
SelectedPalette::Existing { id } => state.game.as_ref().unwrap().get_palette(id).unwrap().clone(),
|
||||||
SelectedPalette::New { background, foreground } => bitsy_parser::Palette {
|
SelectedPalette::New { background, foreground } => palette_from(background, foreground),
|
||||||
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);
|
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::None => bitsy_parser::mock::game_default().palettes[0].id.clone(),
|
||||||
SelectedPalette::Existing { id } => id.clone(),
|
SelectedPalette::Existing { id } => id.clone(),
|
||||||
SelectedPalette::New { background, foreground } => {
|
SelectedPalette::New { background, foreground } => {
|
||||||
game.add_palette(bitsy_parser::Palette {
|
game.add_palette(palette_from(background, foreground))
|
||||||
id: "0".to_string(),
|
|
||||||
name: None,
|
|
||||||
colours: vec![
|
|
||||||
background.clone(),
|
|
||||||
foreground.clone(),
|
|
||||||
bitsy_parser::Colour { red: 0, green: 0, blue: 0 }
|
|
||||||
],
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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 {
|
game.add_room(bitsy_parser::Room {
|
||||||
id: "0".to_string(),
|
id: "0".to_string(),
|
||||||
palette_id,
|
palette_id,
|
||||||
|
|
Loading…
Reference in New Issue