generic from_file for palettes

This commit is contained in:
Max Bradbury 2021-05-16 17:05:08 +01:00
parent a8792744e1
commit 3e2c24db8a
1 changed files with 13 additions and 0 deletions

View File

@ -28,6 +28,19 @@ impl Palette {
}
}
/// todo result
pub fn from_file(path: PathBuf) -> Self {
match path.extension().unwrap().to_str().unwrap() {
"pal" => Self::from_jasc(path),
"gpl" => Self::from_gpl(path),
"toml" => Self::from(
path.file_stem().as_ref().unwrap().to_str().unwrap(),
&read_to_string(&path).unwrap()
),
_ => panic!("Bad palette")
}
}
/// JASC .pal format (Paint Shop Pro)
pub fn from_jasc(path: PathBuf) -> Self {
let name = path.file_stem().unwrap().to_str().unwrap().into();