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