Darktide Mod Manager #39

Merged
lucas merged 91 commits from feat/dtmm into master 2023-03-01 22:27:42 +01:00
4 changed files with 40 additions and 19 deletions
Showing only changes of commit 701516aa7c - Show all commits

View file

@ -156,15 +156,31 @@ fn build_mod_data_lua(state: Arc<State>) -> 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());
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(mod_info.get_resources().get_init());
lua.push_str(resources.get_init());
if let Some(data) = resources.get_data() {
lua.push_str("\",\n data = \"");
lua.push_str(mod_info.get_resources().get_data());
lua.push_str(data);
}
if let Some(localization) = resources.get_localization() {
lua.push_str("\",\n localization = \"");
lua.push_str(mod_info.get_resources().get_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() {

View file

@ -62,8 +62,8 @@ impl PackageInfo {
#[derive(Clone, Data, Debug)]
pub(crate) struct ModResourceInfo {
init: String,
data: String,
localization: String,
data: Option<String>,
localization: Option<String>,
}
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()
}
}

View file

@ -72,9 +72,12 @@ async fn find_project_config(dir: Option<PathBuf>) -> Result<ModConfig> {
};
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)
}

View file

@ -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<String>,
#[serde(default)]
pub localization: Option<String>,
}
#[derive(Clone, Debug, Default, serde::Deserialize)]