diff --git a/crates/dtmm/src/engine.rs b/crates/dtmm/src/engine.rs index f711503..c994091 100644 --- a/crates/dtmm/src/engine.rs +++ b/crates/dtmm/src/engine.rs @@ -156,15 +156,31 @@ fn build_mod_data_lua(state: Arc) -> String { lua.push_str(mod_info.get_id()); lua.push_str("\",\n run = function()\n"); - lua.push_str(" return new_mod(\""); - lua.push_str(mod_info.get_name()); - lua.push_str("\", {\n init = \""); - lua.push_str(mod_info.get_resources().get_init()); - lua.push_str("\",\n data = \""); - lua.push_str(mod_info.get_resources().get_data()); - lua.push_str("\",\n localization = \""); - lua.push_str(mod_info.get_resources().get_localization()); - lua.push_str("\",\n })\n"); + + let resources = mod_info.get_resources(); + if resources.get_data().is_some() || resources.get_localization().is_some() { + lua.push_str(" new_mod(\""); + lua.push_str(mod_info.get_id()); + lua.push_str("\", {\n init = \""); + lua.push_str(resources.get_init()); + + if let Some(data) = resources.get_data() { + lua.push_str("\",\n data = \""); + lua.push_str(data); + } + + if let Some(localization) = resources.get_localization() { + lua.push_str("\",\n localization = \""); + lua.push_str(localization); + } + + lua.push_str("\",\n })\n"); + } else { + lua.push_str(" return dofile(\""); + lua.push_str(resources.get_init()); + lua.push_str("\")"); + } + lua.push_str(" end,\n packages = [\n"); for pkg_info in mod_info.get_packages() { diff --git a/crates/dtmm/src/state.rs b/crates/dtmm/src/state.rs index 18a7735..f90b1d8 100644 --- a/crates/dtmm/src/state.rs +++ b/crates/dtmm/src/state.rs @@ -62,8 +62,8 @@ impl PackageInfo { #[derive(Clone, Data, Debug)] pub(crate) struct ModResourceInfo { init: String, - data: String, - localization: String, + data: Option, + localization: Option, } impl ModResourceInfo { @@ -71,12 +71,12 @@ impl ModResourceInfo { &self.init } - pub(crate) fn get_data(&self) -> &String { - &self.data + pub(crate) fn get_data(&self) -> Option<&String> { + self.data.as_ref() } - pub(crate) fn get_localization(&self) -> &String { - &self.localization + pub(crate) fn get_localization(&self) -> Option<&String> { + self.localization.as_ref() } } diff --git a/crates/dtmt/src/cmd/build.rs b/crates/dtmt/src/cmd/build.rs index a5a471f..55acad1 100644 --- a/crates/dtmt/src/cmd/build.rs +++ b/crates/dtmt/src/cmd/build.rs @@ -72,9 +72,12 @@ async fn find_project_config(dir: Option) -> Result { }; let mut buf = String::new(); - file.read_to_string(&mut buf).await?; + file.read_to_string(&mut buf) + .await + .wrap_err("invalid UTF-8")?; - let mut cfg: ModConfig = serde_sjson::from_str(&buf)?; + let mut cfg: ModConfig = + serde_sjson::from_str(&buf).wrap_err("failed to deserialize mod config")?; cfg.dir = path; Ok(cfg) } diff --git a/lib/sdk/src/lib.rs b/lib/sdk/src/lib.rs index 003e400..1e2f5bb 100644 --- a/lib/sdk/src/lib.rs +++ b/lib/sdk/src/lib.rs @@ -13,8 +13,10 @@ pub use context::Context; #[derive(Clone, Debug, Default, serde::Deserialize)] pub struct ModConfigResources { pub init: String, - pub data: String, - pub localization: String, + #[serde(default)] + pub data: Option, + #[serde(default)] + pub localization: Option, } #[derive(Clone, Debug, Default, serde::Deserialize)]