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(crate) struct ModInfo {
pub id: String, pub id: String,
pub name: 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, pub enabled: bool,
#[lens(ignore)] #[lens(ignore)]
#[data(ignore)] #[data(ignore)]
@ -89,9 +93,13 @@ impl ModInfo {
Self { Self {
id: cfg.id, id: cfg.id,
name: cfg.name, 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, enabled: false,
packages, packages,
categories: cfg.categories.into_iter().collect(),
resources: ModResourceInfo { resources: ModResourceInfo {
init: cfg.resources.init, init: cfg.resources.init,
data: cfg.resources.data, 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. // so that we can center-align it.
.expand_width() .expand_width()
.lens(ModInfo::name.in_arc()); .lens(ModInfo::name.in_arc());
let description = Label::raw() let summary = Label::raw()
.with_line_break_mode(LineBreaking::WordWrap) .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() Flex::column()
.cross_axis_alignment(CrossAxisAlignment::Start) .cross_axis_alignment(CrossAxisAlignment::Start)
.main_axis_alignment(MainAxisAlignment::Start) .main_axis_alignment(MainAxisAlignment::Start)
.with_child(name) .with_child(name)
.with_spacer(4.) .with_spacer(4.)
.with_child(description) .with_child(summary)
.with_spacer(4.)
.with_child(version_line)
.with_spacer(4.)
.with_child(categories)
}, },
Flex::column, Flex::column,
) )

View file

@ -13,8 +13,27 @@ const TEMPLATES: [(&str, &str); 5] = [
"dtmt.cfg", "dtmt.cfg",
r#"id = "{{id}}" r#"id = "{{id}}"
name = "{{name}}" name = "{{name}}"
description = "This is my new mod '{{name}}'!"
version = "0.1.0" 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 = { resources = {
init = "scripts/mods/{{id}}/init" init = "scripts/mods/{{id}}/init"
@ -23,16 +42,12 @@ resources = {
} }
packages = [ packages = [
"packages/{{id}}" "packages/mods/{{id}}"
]
depends = [
"dmf"
] ]
"#, "#,
), ),
( (
"packages/{{id}}.package", "packages/mods/{{id}}.package",
r#"lua = [ r#"lua = [
"scripts/mods/{{id}}/*" "scripts/mods/{{id}}/*"
] ]

View file

@ -36,9 +36,13 @@ pub struct ModConfig {
pub dir: std::path::PathBuf, pub dir: std::path::PathBuf,
pub id: String, pub id: String,
pub name: String, pub name: String,
pub description: String, pub summary: String,
pub description: Option<String>,
pub author: Option<String>,
pub version: String, pub version: String,
pub packages: Vec<std::path::PathBuf>, #[serde(default)]
pub categories: Vec<String>,
pub packages: Vec<PathBuf>,
pub resources: ModConfigResources, pub resources: ModConfigResources,
#[serde(default)] #[serde(default)]
pub depends: Vec<ModDependency>, pub depends: Vec<ModDependency>,