Darktide Mod Manager #39
4 changed files with 40 additions and 19 deletions
|
@ -156,15 +156,31 @@ fn build_mod_data_lua(state: Arc<State>) -> String {
|
||||||
lua.push_str(mod_info.get_id());
|
lua.push_str(mod_info.get_id());
|
||||||
|
|
||||||
lua.push_str("\",\n run = function()\n");
|
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();
|
||||||
lua.push_str("\", {\n init = \"");
|
if resources.get_data().is_some() || resources.get_localization().is_some() {
|
||||||
lua.push_str(mod_info.get_resources().get_init());
|
lua.push_str(" new_mod(\"");
|
||||||
lua.push_str("\",\n data = \"");
|
lua.push_str(mod_info.get_id());
|
||||||
lua.push_str(mod_info.get_resources().get_data());
|
lua.push_str("\", {\n init = \"");
|
||||||
lua.push_str("\",\n localization = \"");
|
lua.push_str(resources.get_init());
|
||||||
lua.push_str(mod_info.get_resources().get_localization());
|
|
||||||
lua.push_str("\",\n })\n");
|
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");
|
lua.push_str(" end,\n packages = [\n");
|
||||||
|
|
||||||
for pkg_info in mod_info.get_packages() {
|
for pkg_info in mod_info.get_packages() {
|
||||||
|
|
|
@ -62,8 +62,8 @@ impl PackageInfo {
|
||||||
#[derive(Clone, Data, Debug)]
|
#[derive(Clone, Data, Debug)]
|
||||||
pub(crate) struct ModResourceInfo {
|
pub(crate) struct ModResourceInfo {
|
||||||
init: String,
|
init: String,
|
||||||
data: String,
|
data: Option<String>,
|
||||||
localization: String,
|
localization: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModResourceInfo {
|
impl ModResourceInfo {
|
||||||
|
@ -71,12 +71,12 @@ impl ModResourceInfo {
|
||||||
&self.init
|
&self.init
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_data(&self) -> &String {
|
pub(crate) fn get_data(&self) -> Option<&String> {
|
||||||
&self.data
|
self.data.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_localization(&self) -> &String {
|
pub(crate) fn get_localization(&self) -> Option<&String> {
|
||||||
&self.localization
|
self.localization.as_ref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,9 +72,12 @@ async fn find_project_config(dir: Option<PathBuf>) -> Result<ModConfig> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut buf = String::new();
|
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;
|
cfg.dir = path;
|
||||||
Ok(cfg)
|
Ok(cfg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,10 @@ pub use context::Context;
|
||||||
#[derive(Clone, Debug, Default, serde::Deserialize)]
|
#[derive(Clone, Debug, Default, serde::Deserialize)]
|
||||||
pub struct ModConfigResources {
|
pub struct ModConfigResources {
|
||||||
pub init: String,
|
pub init: String,
|
||||||
pub data: String,
|
#[serde(default)]
|
||||||
pub localization: String,
|
pub data: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub localization: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, serde::Deserialize)]
|
#[derive(Clone, Debug, Default, serde::Deserialize)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue