pub fn save(&self, output_folder: &Path) -> Result<(), std::io::Error> {
        if output_folder.exists() {
            eprintln!("Removing previous contents of output directory");
            std::fs::remove_dir_all(output_folder)?;
        }

        std::fs::create_dir(&output_folder)?;

        let mcmeta_contents = json!({
            "pack": {
                "pack_format": 5,
                "description": self.description
            }
        });

        std::fs::write(
            output_folder.join("pack.mcmeta"),
            mcmeta_contents.to_string(),
        )?;

        std::fs::create_dir_all(output_folder.join(Path::new("data/setup/functions/")))?;
        std::fs::write(
            output_folder.join(Path::new("data/setup/functions/setup.mcfunction")),
            SETUP_STR,
        )?;

        std::fs::create_dir_all(output_folder.join(Path::new("data/stdout/functions/")))?;
        std::fs::write(
            output_folder.join(Path::new("data/stdout/functions/putc.mcfunction")),
            PUTC_STR,
        )?;
        std::fs::write(
            output_folder.join(Path::new("data/stdout/functions/flush.mcfunction")),
            FLUSH_STR,
        )?;

        // Iterator over (ID, contents)
        let funcs= self.functions.iter()
            .map(|func| {
                let contents = func
                    .cmds
                    .iter()
                    .map(|cmd| cmd.to_string())
                    .collect::<Vec<_>>();

                let contents = contents.join("\n");

                (&func.id, contents)
            });

        for (id, contents) in funcs {
            let path = id.path();
            let path_folders = &path[..path.len() - 1];
            let file_name = &path[path.len() - 1];

            let mut full_path = output_folder
                .join(Path::new("data"))
                .join(Path::new(id.namespace()))
                .join(Path::new("functions"));

            for folder in path_folders {
                full_path = full_path.join(Path::new(folder));
            }

            std::fs::create_dir_all(&full_path)?;

            full_path = full_path.join(format!("{}.mcfunction", file_name));

            std::fs::write(full_path, contents.as_bytes())?
        }

        Ok(())
    }
/// Creates a datapack with the given root directory, erasing the previous contents of the folder.
Creates a datapack with the given root directory, erasing the previous contents of the folder.
Creates a datapack with the given root directory erasing the previous contents of the folder .
pub fn save(&self, output_folder: &Path) -> Result<(), std::io::Error> {
        if output_folder.exists() {
            eprintln!("Removing previous contents of output directory");
            std::fs::remove_dir_all(output_folder)?;
        }
        std::fs::create_dir(&output_folder)?;
        let mcmeta_contents = json!({
            "pack": {
                "pack_format": 5,
                "description": self.description
            }
        });
        std::fs::write(
            output_folder.join("pack.mcmeta"),
            mcmeta_contents.to_string(),
        )?;
        std::fs::create_dir_all(output_folder.join(Path::new("data/setup/functions/")))?;
        std::fs::write(
            output_folder.join(Path::new("data/setup/functions/setup.mcfunction")),
            SETUP_STR,
        )?;
        std::fs::create_dir_all(output_folder.join(Path::new("data/stdout/functions/")))?;
        std::fs::write(
            output_folder.join(Path::new("data/stdout/functions/putc.mcfunction")),
            PUTC_STR,
        )?;
        std::fs::write(
            output_folder.join(Path::new("data/stdout/functions/flush.mcfunction")),
            FLUSH_STR,
        )?;
        // Iterator over (ID, contents)
        let funcs= self.functions.iter()
            .map(|func| {
                let contents = func
                    .cmds
                    .iter()
                    .map(|cmd| cmd.to_string())
                    .collect::<Vec<_>>();
                let contents = contents.join("\n");
                (&func.id, contents)
            });
        for (id, contents) in funcs {
            let path = id.path();
            let path_folders = &path[..path.len() - 1];
            let file_name = &path[path.len() - 1];
            let mut full_path = output_folder
                .join(Path::new("data"))
                .join(Path::new(id.namespace()))
                .join(Path::new("functions"));
            for folder in path_folders {
                full_path = full_path.join(Path::new(folder));
            }
            std::fs::create_dir_all(&full_path)?;
            full_path = full_path.join(format!("{}.mcfunction", file_name));
            std::fs::write(full_path, contents.as_bytes())?
        }
        Ok(())
    }
pub fn save ( & self , output_folder : & Path ) -> Result < ( ) , std :: io :: Error > { if output_folder . exists ( ) { eprintln ! ( " " ) ; std :: fs :: remove_dir_all ( output_folder ) ? ; } std :: fs :: create_dir ( & output_folder ) ? ; let mcmeta_contents = json ! ( { " " { " " 5 " " self description } } ) ; std :: fs :: write ( output_folder . join ( " " ) , mcmeta_contents . to_string ( ) , ) ? ; std :: fs :: create_dir_all ( output_folder . join ( Path :: new ( " " ) ) ) ? ; std :: fs :: write ( output_folder . join ( Path :: new ( " " ) ) , SETUP_STR , ) ? ; std :: fs :: create_dir_all ( output_folder . join ( Path :: new ( " " ) ) ) ? ; std :: fs :: write ( output_folder . join ( Path :: new ( " " ) ) , PUTC_STR , ) ? ; std :: fs :: write ( output_folder . join ( Path :: new ( " " ) ) , FLUSH_STR , ) ? ; // Iterator over (ID, contents) let funcs = self . functions . iter ( ) . map ( | func | { let contents = func . cmds . iter ( ) . map ( | cmd | cmd . to_string ( ) ) . collect :: < Vec < _ > > ( ) ; let contents = contents . join ( " \n " ) ; ( & func . id , contents ) } ) ; for ( id , contents ) in funcs { let path = id . path ( ) ; let path_folders = & path [ .. path . len ( ) - 1 ] ; let file_name = & path [ path . len ( ) - 1 ] ; let mut full_path = output_folder . join ( Path :: new ( " " ) ) . join ( Path :: new ( id . namespace ( ) ) ) . join ( Path :: new ( " " ) ) ; for folder in path_folders { full_path = full_path . join ( Path :: new ( folder ) ) ; } std :: fs :: create_dir_all ( & full_path ) ? ; full_path = full_path . join ( format ! ( " " file_name ) ) ; std :: fs :: write ( full_path , contents . as_bytes ( ) ) ? } Ok ( ( ) ) }
Creates a datapack with the given root directory, erasing the previous contents of the folder.
Creates a datapack with the given root directory erasing the previous contents of the folder .
&self
output_folder
&Path
&self
output_folder
&Path