From 3e2c24db8a0e12d1383d102dd7cdbdc82bde65ae Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 16 May 2021 17:05:08 +0100 Subject: [PATCH] generic from_file for palettes --- src/palette.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/palette.rs b/src/palette.rs index 3bc974f..c4ddfb0 100644 --- a/src/palette.rs +++ b/src/palette.rs @@ -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();