palette to string function

This commit is contained in:
Max Bradbury 2020-04-11 23:05:47 +01:00
parent 46458e2506
commit 2e4d9fd36e
1 changed files with 15 additions and 0 deletions

View File

@ -517,6 +517,21 @@ fn test_palette_from_string_no_name() {
assert_eq!(output, expected); assert_eq!(output, expected);
} }
fn palette_to_string(palette: Palette) -> String {
let name = if palette.name.is_some() {
format!("NAME {}\n", palette.name.unwrap())
} else {
"".to_string()
};
let colours: Vec<String> = palette.colours.into_iter().map(|colour| {
colour_to_string(colour)
}).collect();
let colours = colours.join("\n");
format!("PAL {}\n{}{}", palette.id, name, colours)
}
fn position_from_string(string: String) -> Position { fn position_from_string(string: String) -> Position {
// e.g. "2,5" // e.g. "2,5"
let xy: Vec<&str> = string.split(',').collect(); let xy: Vec<&str> = string.split(',').collect();