Darktide Mod Manager #39
4 changed files with 36 additions and 28 deletions
|
@ -82,6 +82,7 @@ impl ModResourceInfo {
|
||||||
|
|
||||||
#[derive(Clone, Data, Debug, Lens)]
|
#[derive(Clone, Data, Debug, Lens)]
|
||||||
pub(crate) struct ModInfo {
|
pub(crate) struct ModInfo {
|
||||||
|
id: String,
|
||||||
name: String,
|
name: String,
|
||||||
description: Arc<String>,
|
description: Arc<String>,
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
|
@ -94,6 +95,7 @@ pub(crate) struct ModInfo {
|
||||||
impl ModInfo {
|
impl ModInfo {
|
||||||
pub fn new(cfg: ModConfig, packages: Vector<PackageInfo>) -> Self {
|
pub fn new(cfg: ModConfig, packages: Vector<PackageInfo>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
id: cfg.id,
|
||||||
name: cfg.name,
|
name: cfg.name,
|
||||||
description: Arc::new(cfg.description),
|
description: Arc::new(cfg.description),
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -114,6 +116,10 @@ impl ModInfo {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_id(&self) -> &String {
|
||||||
|
&self.id
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn get_enabled(&self) -> bool {
|
pub(crate) fn get_enabled(&self) -> bool {
|
||||||
self.enabled
|
self.enabled
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
|
||||||
};
|
};
|
||||||
|
|
||||||
let dest = {
|
let dest = {
|
||||||
let mut path = PathBuf::from(&cfg.name);
|
let mut path = PathBuf::from(&cfg.id);
|
||||||
path.set_extension("zip");
|
path.set_extension("zip");
|
||||||
Arc::new(path)
|
Arc::new(path)
|
||||||
};
|
};
|
||||||
|
@ -214,9 +214,9 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
|
||||||
|
|
||||||
{
|
{
|
||||||
let dest = dest.clone();
|
let dest = dest.clone();
|
||||||
let name = cfg.name.clone();
|
let id = cfg.id.clone();
|
||||||
tokio::task::spawn_blocking(move || {
|
tokio::task::spawn_blocking(move || {
|
||||||
let mut archive = Archive::new(name);
|
let mut archive = Archive::new(id);
|
||||||
|
|
||||||
archive.add_config(config_file);
|
archive.add_config(config_file);
|
||||||
|
|
||||||
|
|
|
@ -11,18 +11,19 @@ use tokio::fs::{self, DirBuilder};
|
||||||
const TEMPLATES: [(&str, &str); 5] = [
|
const TEMPLATES: [(&str, &str); 5] = [
|
||||||
(
|
(
|
||||||
"dtmt.cfg",
|
"dtmt.cfg",
|
||||||
r#"name = "{{name}}"
|
r#"id = "{{id}}"
|
||||||
|
name = "{{name}}"
|
||||||
description = "An elaborate description of my cool game mod!"
|
description = "An elaborate description of my cool game mod!"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
resources = {
|
resources = {
|
||||||
script = "scripts/mods/{{name}}/init"
|
script = "scripts/mods/{{id}}/init"
|
||||||
data = "scripts/mods/{{name}}/data"
|
data = "scripts/mods/{{id}}/data"
|
||||||
localization = "scripts/mods/{{name}}/locationzation"
|
localization = "scripts/mods/{{id}}/localization"
|
||||||
}
|
}
|
||||||
|
|
||||||
packages = [
|
packages = [
|
||||||
"packages/{{name}}"
|
"packages/{{id}}"
|
||||||
]
|
]
|
||||||
|
|
||||||
depends = [
|
depends = [
|
||||||
|
@ -31,32 +32,32 @@ depends = [
|
||||||
"#,
|
"#,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"packages/{{name}}.package",
|
"packages/{{id}}.package",
|
||||||
r#"lua = [
|
r#"lua = [
|
||||||
"scripts/mods/{{name}}/*"
|
"scripts/mods/{{id}}/*"
|
||||||
]
|
]
|
||||||
"#,
|
"#,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"scripts/mods/{{name}}/init.lua",
|
"scripts/mods/{{id}}/init.lua",
|
||||||
r#"local mod = get_mod("{{name}}")
|
r#"local mod = get_mod("{{id}}")
|
||||||
|
|
||||||
-- Your mod code goes here.
|
-- Your mod code goes here.
|
||||||
-- https://vmf-docs.verminti.de
|
-- https://vmf-docs.verminti.de
|
||||||
"#,
|
"#,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"scripts/mods/{{name}}/data.lua",
|
"scripts/mods/{{id}}/data.lua",
|
||||||
r#"local mod = get_mod("{{name}}")
|
r#"local mod = get_mod("{{id}}")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name = "{{title}}",
|
name = "{{name}}",
|
||||||
description = mod:localize("mod_description"),
|
description = mod:localize("mod_description"),
|
||||||
is_togglable = true,
|
is_togglable = true,
|
||||||
}"#,
|
}"#,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"scripts/mods/{{name}}/localization.lua",
|
"scripts/mods/{{id}}/localization.lua",
|
||||||
r#"return {
|
r#"return {
|
||||||
mod_description = {
|
mod_description = {
|
||||||
en = "An elaborate description of my cool game mod!",
|
en = "An elaborate description of my cool game mod!",
|
||||||
|
@ -69,8 +70,8 @@ pub(crate) fn command_definition() -> Command {
|
||||||
Command::new("new")
|
Command::new("new")
|
||||||
.about("Create a new project")
|
.about("Create a new project")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("title")
|
Arg::new("name")
|
||||||
.long("title")
|
.long("name")
|
||||||
.help("The display name of the new mod."),
|
.help("The display name of the new mod."),
|
||||||
)
|
)
|
||||||
.arg(Arg::new("root").help(
|
.arg(Arg::new("root").help(
|
||||||
|
@ -98,14 +99,14 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let title = if let Some(title) = matches.get_one::<String>("title") {
|
let name = if let Some(name) = matches.get_one::<String>("name") {
|
||||||
title.clone()
|
name.clone()
|
||||||
} else {
|
} else {
|
||||||
promptly::prompt("The mod display name")?
|
promptly::prompt("The unique mod ID")?
|
||||||
};
|
};
|
||||||
|
|
||||||
let name = {
|
let id = {
|
||||||
let default = title
|
let default = name
|
||||||
.chars()
|
.chars()
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
if c.is_ascii_alphanumeric() {
|
if c.is_ascii_alphanumeric() {
|
||||||
|
@ -115,14 +116,14 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
promptly::prompt_default("The mod identifier name", default)?
|
promptly::prompt_default("The unique mod ID", default)?
|
||||||
};
|
};
|
||||||
|
|
||||||
tracing::debug!(root = %root.display(), title, name);
|
tracing::debug!(root = %root.display(), name, id);
|
||||||
|
|
||||||
let mut data = HashMap::new();
|
let mut data = HashMap::new();
|
||||||
data.insert("name", name.as_str());
|
data.insert("name", name.as_str());
|
||||||
data.insert("title", title.as_str());
|
data.insert("id", id.as_str());
|
||||||
|
|
||||||
let templates = TEMPLATES
|
let templates = TEMPLATES
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -158,7 +159,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"Created {} files for mod '{}' in '{}'.",
|
"Created {} files for mod '{}' in '{}'.",
|
||||||
TEMPLATES.len(),
|
TEMPLATES.len(),
|
||||||
title,
|
name,
|
||||||
root.display()
|
root.display()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ pub struct ModConfigResources {
|
||||||
pub struct ModConfig {
|
pub struct ModConfig {
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub dir: std::path::PathBuf,
|
pub dir: std::path::PathBuf,
|
||||||
|
pub id: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub version: String,
|
pub version: String,
|
||||||
|
|
Loading…
Add table
Reference in a new issue