From 65c0974de20a0f64410424dc4fa85547db320b09 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Thu, 9 Mar 2023 14:29:44 +0100 Subject: [PATCH] feat(dtmm): Add additional details fields Ref: #15. --- crates/dtmm/src/state/data.rs | 12 ++++++++-- crates/dtmm/src/ui/window/main.rs | 37 ++++++++++++++++++++++++++++--- crates/dtmt/src/cmd/new.rs | 29 ++++++++++++++++++------ lib/dtmt-shared/src/lib.rs | 8 +++++-- 4 files changed, 72 insertions(+), 14 deletions(-) diff --git a/crates/dtmm/src/state/data.rs b/crates/dtmm/src/state/data.rs index 779b67c..ae622f7 100644 --- a/crates/dtmm/src/state/data.rs +++ b/crates/dtmm/src/state/data.rs @@ -73,7 +73,11 @@ impl From for ModDependency { pub(crate) struct ModInfo { pub id: String, pub name: String, - pub description: Arc, + pub summary: Arc, + pub description: Option>, + pub categories: Vector, + pub author: Option, + pub version: String, pub enabled: bool, #[lens(ignore)] #[data(ignore)] @@ -89,9 +93,13 @@ impl ModInfo { Self { id: cfg.id, name: cfg.name, - description: Arc::new(cfg.description), + summary: Arc::new(cfg.summary), + description: cfg.description.map(Arc::new), + author: cfg.author, + version: cfg.version, enabled: false, packages, + categories: cfg.categories.into_iter().collect(), resources: ModResourceInfo { init: cfg.resources.init, data: cfg.resources.data, diff --git a/crates/dtmm/src/ui/window/main.rs b/crates/dtmm/src/ui/window/main.rs index f48b5c3..8fa7de0 100644 --- a/crates/dtmm/src/ui/window/main.rs +++ b/crates/dtmm/src/ui/window/main.rs @@ -220,16 +220,47 @@ fn build_mod_details_info() -> impl Widget { // so that we can center-align it. .expand_width() .lens(ModInfo::name.in_arc()); - let description = Label::raw() + let summary = Label::raw() .with_line_break_mode(LineBreaking::WordWrap) - .lens(ModInfo::description.in_arc()); + .lens(ModInfo::summary.in_arc()); + + // TODO: Image/icon? + + let version_line = Label::dynamic(|info: &Arc, _| { + if let Some(author) = &info.author { + format!("Version: {}, by {author}", info.version) + } else { + format!("Version: {}", info.version) + } + }); + + let categories = Label::dynamic(|info: &Arc, _| { + if info.categories.is_empty() { + String::from("Uncategorized") + } else { + info.categories.iter().enumerate().fold( + String::from("Category: "), + |mut s, (i, category)| { + if i > 0 { + s.push_str(", "); + } + s.push_str(category); + s + }, + ) + } + }); Flex::column() .cross_axis_alignment(CrossAxisAlignment::Start) .main_axis_alignment(MainAxisAlignment::Start) .with_child(name) .with_spacer(4.) - .with_child(description) + .with_child(summary) + .with_spacer(4.) + .with_child(version_line) + .with_spacer(4.) + .with_child(categories) }, Flex::column, ) diff --git a/crates/dtmt/src/cmd/new.rs b/crates/dtmt/src/cmd/new.rs index 77fa649..374cdb7 100644 --- a/crates/dtmt/src/cmd/new.rs +++ b/crates/dtmt/src/cmd/new.rs @@ -13,8 +13,27 @@ const TEMPLATES: [(&str, &str); 5] = [ "dtmt.cfg", r#"id = "{{id}}" name = "{{name}}" -description = "This is my new mod '{{name}}'!" version = "0.1.0" +// author = "" + +// A one- or two-line short description. +summary = "This is my new mod '{{name}}'!" +// description = "" + +// Can contain arbitrary strings. But to keep things consistent and useful, +// capitalize names and check existing mods for matching categories. +categories = [ + Misc + // UI + // QoL + // Tools +] + +// A list of mod IDs that this mod depends on. You can find +// those IDs by downloading the mod and extracting their `dtmt.cfg`. +depends = [ + DMF +] resources = { init = "scripts/mods/{{id}}/init" @@ -23,16 +42,12 @@ resources = { } packages = [ - "packages/{{id}}" -] - -depends = [ - "dmf" + "packages/mods/{{id}}" ] "#, ), ( - "packages/{{id}}.package", + "packages/mods/{{id}}.package", r#"lua = [ "scripts/mods/{{id}}/*" ] diff --git a/lib/dtmt-shared/src/lib.rs b/lib/dtmt-shared/src/lib.rs index 17b8d92..0bf3924 100644 --- a/lib/dtmt-shared/src/lib.rs +++ b/lib/dtmt-shared/src/lib.rs @@ -36,9 +36,13 @@ pub struct ModConfig { pub dir: std::path::PathBuf, pub id: String, pub name: String, - pub description: String, + pub summary: String, + pub description: Option, + pub author: Option, pub version: String, - pub packages: Vec, + #[serde(default)] + pub categories: Vec, + pub packages: Vec, pub resources: ModConfigResources, #[serde(default)] pub depends: Vec,