mirror of
https://github.com/WarrenHood/MCModpackManager.git
synced 2025-04-30 00:04:59 +01:00
Switch to using a hashmap for the mods in the modpack
This commit is contained in:
parent
64bd74c2de
commit
5b04b78d0a
|
@ -1,4 +1,4 @@
|
||||||
use std::{borrow::BorrowMut, error::Error, path::PathBuf};
|
use std::{borrow::BorrowMut, collections::HashMap, error::Error, path::PathBuf};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -35,14 +35,6 @@ pub struct ModMeta {
|
||||||
download_url: Option<String>,
|
download_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
struct ModMetaBuilder {
|
|
||||||
mod_name: String,
|
|
||||||
version: String,
|
|
||||||
providers: Option<Vec<ModProvider>>,
|
|
||||||
download_url: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ModMeta {
|
impl ModMeta {
|
||||||
pub fn new(mod_name: &str) -> Result<Self, Box<dyn Error>> {
|
pub fn new(mod_name: &str) -> Result<Self, Box<dyn Error>> {
|
||||||
if mod_name.contains("@") {
|
if mod_name.contains("@") {
|
||||||
|
@ -128,7 +120,7 @@ pub struct ModpackMeta {
|
||||||
pack_name: String,
|
pack_name: String,
|
||||||
mc_version: String,
|
mc_version: String,
|
||||||
modloader: ModLoader,
|
modloader: ModLoader,
|
||||||
mods: Vec<ModMeta>,
|
mods: HashMap<String, ModMeta>,
|
||||||
default_providers: Vec<ModProvider>,
|
default_providers: Vec<ModProvider>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,18 +159,16 @@ impl ModpackMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_mod(mut self, mod_meta: ModMeta) -> Self {
|
pub fn add_mod(mut self, mod_meta: ModMeta) -> Self {
|
||||||
if !self.mods.contains(&mod_meta) {
|
if let Some(old_mod_meta) = self.mods.get(&mod_meta.mod_name) {
|
||||||
self.mods = self
|
println!("Updating {} version {}->{}", mod_meta.mod_name, old_mod_meta.version, mod_meta.version);
|
||||||
.mods
|
}
|
||||||
.into_iter()
|
else {
|
||||||
.filter(|m| m.mod_name != mod_meta.mod_name)
|
|
||||||
.collect();
|
|
||||||
println!(
|
println!(
|
||||||
"Adding {}@{} to modpack '{}'...",
|
"Adding {}@{} to modpack '{}'...",
|
||||||
mod_meta.mod_name, mod_meta.version, self.pack_name
|
mod_meta.mod_name, mod_meta.version, self.pack_name
|
||||||
);
|
);
|
||||||
self.mods.push(mod_meta);
|
|
||||||
}
|
}
|
||||||
|
self.mods.insert(mod_meta.mod_name.to_string(), mod_meta);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue