Skip to content

Commit af1d079

Browse files
committed
support for v5 required key in dependencies
1 parent a3563a0 commit af1d079

File tree

2 files changed

+32
-39
lines changed

2 files changed

+32
-39
lines changed

src/project.rs

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::logging::ask_value;
22
use crate::mod_file::{PlatformName, ToGeodeString};
3-
use crate::util::mod_file::{DependencyImportance, GDVersion};
3+
use crate::util::mod_file::GDVersion;
44
use crate::{done, fail, fatal, index, info, warn, NiceUnwrap};
55
use crate::{
66
file::read_dir_recursive,
@@ -158,10 +158,7 @@ impl Found {
158158
}
159159
}
160160

161-
fn find_existing_dependency(
162-
dep: &Dependency,
163-
_config: &Config,
164-
) -> Result<Found, String> {
161+
fn find_existing_dependency(dep: &Dependency, _config: &Config) -> Result<Found, String> {
165162
let mut path = env::temp_dir();
166163
path.push(format!("{}.geode", dep.id));
167164

@@ -302,30 +299,28 @@ pub fn check_dependencies(
302299
// Check if platform is supported
303300
match mod_info.gd {
304301
GDVersion::Simple(_) => {}
305-
GDVersion::Detailed(gd) => {
306-
match platform {
307-
PlatformName::Windows => {
308-
if gd.win.is_none() {
309-
fatal!("Geometry Dash version not specified for Windows, please specify one in mod.json");
310-
}
302+
GDVersion::Detailed(gd) => match platform {
303+
PlatformName::Windows => {
304+
if gd.win.is_none() {
305+
fatal!("Geometry Dash version not specified for Windows, please specify one in mod.json");
311306
}
312-
PlatformName::MacOS | PlatformName::MacArm | PlatformName::MacIntel => {
313-
if gd.mac.is_none() {
314-
fatal!("Geometry Dash version not specified for macOS, please specify one in mod.json");
315-
}
307+
}
308+
PlatformName::MacOS | PlatformName::MacArm | PlatformName::MacIntel => {
309+
if gd.mac.is_none() {
310+
fatal!("Geometry Dash version not specified for macOS, please specify one in mod.json");
316311
}
317-
PlatformName::Android | PlatformName::Android32 | PlatformName::Android64 => {
318-
if gd.android.is_none() {
319-
fatal!("Geometry Dash version not specified for Android, please specify one in mod.json");
320-
}
312+
}
313+
PlatformName::Android | PlatformName::Android32 | PlatformName::Android64 => {
314+
if gd.android.is_none() {
315+
fatal!("Geometry Dash version not specified for Android, please specify one in mod.json");
321316
}
322-
PlatformName::Ios => {
323-
if gd.ios.is_none() {
324-
fatal!("Geometry Dash version not specified for iOS, please specify one in mod.json");
325-
}
317+
}
318+
PlatformName::Ios => {
319+
if gd.ios.is_none() {
320+
fatal!("Geometry Dash version not specified for iOS, please specify one in mod.json");
326321
}
327322
}
328-
}
323+
},
329324
}
330325

331326
// If no dependencies, skippy wippy
@@ -437,8 +432,7 @@ pub fn check_dependencies(
437432
info!("Dependency '{}' found in cache", dep.id);
438433
path_to_dep_geode = inst_path;
439434
_geode_info = inst_info;
440-
}
441-
else {
435+
} else {
442436
// check index
443437
let found_in_index = match find_index_dependency(dep, &config) {
444438
Ok(f) => f,
@@ -456,7 +450,7 @@ pub fn check_dependencies(
456450
if !matches!(found_in_index, Found::Some(_, _))
457451
&& !matches!(found_in_installed, Found::Some(_, _))
458452
{
459-
if dep.importance == DependencyImportance::Required {
453+
if dep.required {
460454
fail!(
461455
"Dependency '{0}' not found in installed mods nor index! \
462456
If this is a mod that hasn't been published yet, install it \
@@ -604,14 +598,7 @@ pub fn check_dependencies(
604598
// know if to link or not)
605599
fs::write(
606600
dep_dir.join(&dep.id).join("geode-dep-options.json"),
607-
format!(
608-
r#"{{ "required": {} }}"#,
609-
if dep.importance == DependencyImportance::Required {
610-
"true"
611-
} else {
612-
"false"
613-
}
614-
),
601+
format!(r#"{{ "required": {} }}"#, dep.required),
615602
)
616603
.nice_unwrap("Unable to save dep options");
617604
}

src/util/mod_file.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn all_platforms() -> HashSet<PlatformName> {
283283
])
284284
}
285285

286-
#[derive(Default, Deserialize, PartialEq)]
286+
#[derive(Default, Deserialize, PartialEq, Clone)]
287287
#[serde(rename_all = "camelCase")]
288288
pub enum DependencyImportance {
289289
#[default]
@@ -298,8 +298,9 @@ pub struct Dependency {
298298
pub id: String,
299299
#[serde(deserialize_with = "parse_comparable_version")]
300300
pub version: VersionReq,
301+
pub importance: Option<DependencyImportance>,
301302
#[serde(default)]
302-
pub importance: DependencyImportance,
303+
pub required: bool,
303304
#[serde(default = "all_platforms")]
304305
pub platforms: HashSet<PlatformName>,
305306
}
@@ -359,14 +360,18 @@ where
359360
Ok(version) => Ok(Dependency {
360361
id: id.clone(),
361362
version,
362-
importance: DependencyImportance::Required,
363+
importance: Some(DependencyImportance::Required),
364+
required: true,
363365
platforms: all_platforms(),
364366
}),
365367
// Longhand is "[mod.id]": { ... }
366368
Err(_) => Dependency::deserialize(json)
367369
// The ID isn't parsed from the object itself but is the key
368370
.map(|mut d| {
369371
d.id.clone_from(&id);
372+
if let Some(i) = &d.importance {
373+
d.required = *i == DependencyImportance::Required;
374+
}
370375
d
371376
})
372377
.map_err(D::Error::custom),
@@ -386,7 +391,8 @@ where
386391
Dependency {
387392
id: dep.id,
388393
version: dep.version,
389-
importance: dep.importance,
394+
importance: Some(dep.importance.clone()),
395+
required: dep.importance == DependencyImportance::Required,
390396
platforms: dep.platforms,
391397
},
392398
);

0 commit comments

Comments
 (0)