diff --git a/Cargo.toml b/Cargo.toml index fd76fc2..6ecc833 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ colored = "2.1.0" serde = { version = "1.0.197", features = ["derive"] } thiserror = "1.0.58" toml = "0.8.12" -shulkerscript-lang = { git = "https://github.com/moritz-hoelting/shulkerscript-lang", features = ["shulkerbox"], default-features = false, rev = "44d634355b4ab5b652de56b0becd61b05680c068"} +shulkerscript-lang = { git = "https://github.com/moritz-hoelting/shulkerscript-lang", features = ["shulkerbox"], default-features = false, rev = "899a973315ce63ff20c789a7e7a784e926efc027"} shulkerbox = { git = "https://github.com/moritz-hoelting/shulkerbox", default-features = false, rev = "b79c9ecd6d45f9319c9083a8103ef0186839b0c0" } git2 = { version = "0.18.3", default-features = false } path-absolutize = "3.1.1" diff --git a/src/subcommands/build.rs b/src/subcommands/build.rs index 3a4c22c..2f0276d 100644 --- a/src/subcommands/build.rs +++ b/src/subcommands/build.rs @@ -1,6 +1,6 @@ use color_eyre::eyre::Result; use path_absolutize::Absolutize; -use shulkerbox::virtual_fs::VFolder; +use shulkerbox::virtual_fs::{VFile, VFolder}; use crate::{ config::ProjectConfig, @@ -40,12 +40,6 @@ pub fn build(_verbose: bool, args: &BuildArgs) -> Result<()> { path.absolutize()?.display() )); - // env::set_current_dir( - // toml_path - // .parent() - // .expect("Failed to get parent directory of pack.toml"), - // )?; - let (project_config, toml_path) = get_pack_config(path)?; let script_paths = get_script_paths( @@ -55,7 +49,15 @@ pub fn build(_verbose: bool, args: &BuildArgs) -> Result<()> { .join("src"), )?; - let compiled = shulkerscript_lang::compile(&script_paths)?; + let mut compiled = shulkerscript_lang::compile(&script_paths)?; + + let icon_path = toml_path.parent().unwrap().join("pack.png"); + + if icon_path.is_file() { + if let Ok(icon_data) = fs::read(icon_path) { + compiled.add_file("pack.png", VFile::Binary(icon_data)); + } + } let assets_path = args.assets.clone().or(project_config .compiler diff --git a/src/subcommands/package.rs b/src/subcommands/package.rs index ed03a66..457924b 100644 --- a/src/subcommands/package.rs +++ b/src/subcommands/package.rs @@ -1,8 +1,8 @@ -use std::{env, path::PathBuf}; +use std::{env, fs, path::PathBuf}; use color_eyre::eyre::Result; use path_absolutize::Absolutize; -use shulkerbox::virtual_fs::VFolder; +use shulkerbox::virtual_fs::{VFile, VFolder}; use crate::{ error::Error, @@ -40,7 +40,15 @@ pub fn package(_verbose: bool, args: &PackageArgs) -> Result<()> { .join("src"), )?; - let compiled = shulkerscript_lang::compile(&script_paths)?; + let mut compiled = shulkerscript_lang::compile(&script_paths)?; + + let icon_path = toml_path.parent().unwrap().join("pack.png"); + + if icon_path.is_file() { + if let Ok(icon_data) = fs::read(icon_path) { + compiled.add_file("pack.png", VFile::Binary(icon_data)); + } + } let assets_path = args.build_args.assets.clone().or(project_config .compiler