use crate::traits::{LoadYaml, SaveMessagePack, SaveYaml};
use crate::{
structs::{Bookmark, Story},
Error,
};
use std::path::Path;
fn dump<S: SaveYaml + SaveMessagePack>(obj: &S, outpath: &Path) -> Result<(), Error> {
if cfg!(debug_assertions) {
obj.save_yml(outpath.with_extension("yml"))?;
}
obj.save_mp(outpath)
}
pub fn pack(dir: &str, outdir: &str) -> Result<(), Error> {
let path = Path::new(dir);
let outpath = Path::new(outdir);
let story = Story::load_yml(path.join("story"))?;
dump(&story, &outpath.join("story"))?;
let mut bookmark = Bookmark::load_yml(path.join("bookmark.yml"))?;
bookmark.init_state(&story);
dump(&bookmark, &outpath.join("bookmark"))?;
Ok(())
}