Skip to content

Commit

Permalink
Don't use ModInfo as map key
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank authored and jieyouxu committed Feb 24, 2024
1 parent 87f714c commit 800edbd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
10 changes: 5 additions & 5 deletions mint_lib/src/mod_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{collections::BTreeSet, fmt::Display};
use serde::{Deserialize, Serialize};

/// Tags from mod.io.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone)]
pub struct ModioTags {
pub qol: bool,
pub gameplay: bool,
Expand All @@ -15,13 +15,13 @@ pub struct ModioTags {
pub approval_status: ApprovalStatus,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone)]
pub enum RequiredStatus {
RequiredByAll,
Optional,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum ApprovalStatus {
Verified,
Approved,
Expand All @@ -36,7 +36,7 @@ pub enum ResolvableStatus {
}

/// Returned from ModStore
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone)]
pub struct ModInfo {
pub provider: &'static str,
pub name: String,
Expand Down Expand Up @@ -75,7 +75,7 @@ impl ModSpecification {
}

/// Points to a specific version of a specific mod
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd, Hash)]
pub struct ModResolution {
pub url: ModIdentifier,
pub status: ResolvableStatus,
Expand Down
16 changes: 6 additions & 10 deletions src/gui/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
};

use anyhow::Result;
use mint_lib::mod_info::MetaConfig;
use mint_lib::mod_info::{MetaConfig, ModIdentifier};
use tokio::{
sync::mpsc::{self, Sender},
task::JoinHandle,
Expand Down Expand Up @@ -180,7 +180,7 @@ impl ResolveMods {
#[derive(Debug)]
pub struct Integrate {
rid: RequestID,
result: Result<HashMap<ModInfo, bool>, IntegrationErr>,
result: Result<HashMap<ModIdentifier, bool>, IntegrationErr>,
}

impl Integrate {
Expand Down Expand Up @@ -212,16 +212,12 @@ impl Integrate {
if Some(self.rid) == app.integrate_rid.as_ref().map(|r| r.rid) {
match self.result {
Ok(res) => {
let resolution_gameplay_affecting_map = res
.iter()
.map(|(k, v)| (k.resolution.clone(), v))
.collect::<HashMap<_, _>>();
let resolution_gameplay_affecting_map =
res.into_iter().collect::<HashMap<_, _>>();
debug!(?resolution_gameplay_affecting_map);

for (res, stat) in resolution_gameplay_affecting_map {
app.state
.store
.update_gameplay_affecting_status(res.url, *stat);
app.state.store.update_gameplay_affecting_status(res, stat);
}

info!("integration complete");
Expand Down Expand Up @@ -401,7 +397,7 @@ async fn integrate_async(
config: MetaConfig,
rid: RequestID,
message_tx: Sender<Message>,
) -> Result<HashMap<ModInfo, bool>, IntegrationErr> {
) -> Result<HashMap<ModIdentifier, bool>, IntegrationErr> {
let update = false;

let mods = store
Expand Down
4 changes: 1 addition & 3 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use eframe::{
epaint::{text::LayoutJob, Color32, Stroke},
};
use egui_commonmark::{CommonMarkCache, CommonMarkViewer};
use mint_lib::mod_info::{ModioTags, RequiredStatus};
use mint_lib::mod_info::{ModIdentifier, ModioTags, RequiredStatus};
use tokio::{
sync::mpsc::{self, Receiver, Sender},
task::JoinHandle,
Expand All @@ -45,8 +45,6 @@ use find_string::FindString;
use message::MessageHandle;
use request_counter::{RequestCounter, RequestID};

use mint_lib::mod_info::*;

use self::toggle_switch::toggle_switch;

pub fn gui(dirs: Dirs, args: Option<Vec<String>>) -> Result<()> {
Expand Down
12 changes: 8 additions & 4 deletions src/integrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use std::io::{self, BufReader, BufWriter, Cursor, ErrorKind, Read, Seek};
use std::path::{Path, PathBuf};

use anyhow::{Context, Result};
use mint_lib::mod_info::{ApprovalStatus, Meta, MetaConfig, MetaMod, ModioTags, SemverVersion};
use mint_lib::mod_info::{
ApprovalStatus, Meta, MetaConfig, MetaMod, ModIdentifier, ModioTags, SemverVersion,
};
use mint_lib::DRGInstallation;
use repak::PakWriter;
use serde::Deserialize;
Expand Down Expand Up @@ -164,7 +166,7 @@ pub fn integrate<P: AsRef<Path>>(
path_pak: P,
config: MetaConfig,
mods: Vec<(ModInfo, PathBuf)>,
) -> Result<HashMap<ModInfo, bool>, IntegrationErr> {
) -> Result<HashMap<ModIdentifier, bool>, IntegrationErr> {
let installation = DRGInstallation::from_pak_path(&path_pak).map_err(|e| IntegrationErr {
mod_ctxt: None,
kind: IntegrationErrKind::Generic(e),
Expand Down Expand Up @@ -420,7 +422,7 @@ pub fn integrate<P: AsRef<Path>>(

debug!(?mod_info, ?gameplay_affecting);

gameplay_affecting_results.insert(mod_info.clone(), gameplay_affecting);
gameplay_affecting_results.insert(mod_info.resolution.url.clone(), gameplay_affecting);

let mount = Path::new(pak.mount_point());

Expand Down Expand Up @@ -628,7 +630,9 @@ pub fn integrate<P: AsRef<Path>>(
Some(_) => true,
None => gameplay_affecting_results
.iter()
.find_map(|(mod_info, res)| (mod_info == info).then_some(*res))
.find_map(|(ident, res)| {
(*ident == info.resolution.url).then_some(*res)
})
.unwrap_or(true),
},
})
Expand Down

0 comments on commit 800edbd

Please sign in to comment.