feat(dtmm): Add additional details fields

Ref: #15.
This commit is contained in:
Lucas Schwiderski 2023-03-09 14:29:44 +01:00
parent c32927941e
commit 65c0974de2
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8
4 changed files with 72 additions and 14 deletions

View file

@ -73,7 +73,11 @@ impl From<dtmt_shared::ModDependency> for ModDependency {
pub(crate) struct ModInfo {
pub id: String,
pub name: String,
pub description: Arc<String>,
pub summary: Arc<String>,
pub description: Option<Arc<String>>,
pub categories: Vector<String>,
pub author: Option<String>,
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,

View file

@ -220,16 +220,47 @@ fn build_mod_details_info() -> impl Widget<State> {
// 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<ModInfo>, _| {
if let Some(author) = &info.author {
format!("Version: {}, by {author}", info.version)
} else {
format!("Version: {}", info.version)
}
});
let categories = Label::dynamic(|info: &Arc<ModInfo>, _| {
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,
)

View file

@ -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}}/*"
]

View file

@ -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<String>,
pub author: Option<String>,
pub version: String,
pub packages: Vec<std::path::PathBuf>,
#[serde(default)]
pub categories: Vec<String>,
pub packages: Vec<PathBuf>,
pub resources: ModConfigResources,
#[serde(default)]
pub depends: Vec<ModDependency>,