Skip to content

Commit

Permalink
Add load priority field (#159)
Browse files Browse the repository at this point in the history
Co-authored-by: Truman Kilen <[email protected]>
  • Loading branch information
bluez-dev and trumank authored Mar 28, 2024
1 parent e2f5569 commit 0267dc3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/gui/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ impl ResolveMods {
spec: info.spec.clone(),
required: info.suggested_require,
enabled: true,
priority: 50,
}),
);
}
Expand Down
62 changes: 53 additions & 9 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod toggle_switch;
//#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use std::collections::{BTreeMap, BTreeSet};
use std::ops::Deref;
use std::ops::{Deref, RangeInclusive};
use std::time::{Duration, SystemTime};
use std::{
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -466,6 +466,43 @@ impl App {
}
});

ui.scope(|ui| {
ui.style_mut().spacing.interact_size.x = 30.;
let dark = ui.visuals().dark_mode;
match mc.priority.cmp(&0) {
std::cmp::Ordering::Less => {
ui.visuals_mut().override_text_color = Some(if dark {
Color32::LIGHT_RED
} else {
Color32::DARK_RED
});
}
std::cmp::Ordering::Greater => {
ui.visuals_mut().override_text_color = Some(if dark {
Color32::LIGHT_GREEN
} else {
Color32::DARK_GREEN
});
}
_ => {}
}
ui.add(
egui::DragValue::new(&mut mc.priority)
.custom_formatter(|n, _| {
if n == 0. {
"-".to_string()
} else {
format!("{n}")
}
})
.speed(0.05)
.clamp_range(RangeInclusive::new(-999, 999)),
)
.on_hover_text_at_pointer(
"Load Priority\nIn case of asset conflict, mods with higher priority take precedent.\nCan have duplicate values.",
);
});

if ui
.button("📋")
.on_hover_text_at_pointer("copy URL")
Expand Down Expand Up @@ -1613,15 +1650,22 @@ impl eframe::App for App {
);
}

let mut mods = Vec::new();
let active_profile = self.state.mod_data.active_profile.clone();
self.state
.mod_data
.for_each_enabled_mod(&active_profile, |mc| {
mods.push(mc.spec.clone());
});

if button.clicked() {
let mut mod_configs = Vec::new();
let mut mods = Vec::new();
let active_profile = self.state.mod_data.active_profile.clone();
self.state
.mod_data
.for_each_enabled_mod(&active_profile, |mc| {
mod_configs.push(mc.clone());
});

mod_configs.sort_by_key(|k| -k.priority);

for config in mod_configs {
mods.push(config.spec.clone());
}

self.last_action_status = LastActionStatus::Idle;
self.integrate_rid = Some(message::Integrate::send(
&mut self.request_counter,
Expand Down
15 changes: 15 additions & 0 deletions src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ pub struct ModConfig {

#[serde(default = "default_true")]
pub enabled: bool,
#[serde(default, skip_serializing_if = "is_zero")]
pub priority: i32,
}

fn default_true() -> bool {
true
}

fn is_zero(value: &i32) -> bool {
*value == 0
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ModGroup {
pub mods: Vec<ModConfig>,
Expand Down Expand Up @@ -537,18 +543,21 @@ mod mod_data_tests {
spec: ModSpecification::new("a".to_string()),
required: false,
enabled: false,
priority: 50,
};

let mod_2 = ModConfig {
spec: ModSpecification::new("b".to_string()),
required: true,
enabled: false,
priority: 50,
};

let mod_3 = ModConfig {
spec: ModSpecification::new("c".to_string()),
required: false,
enabled: true,
priority: 50,
};

let mod_data = ModData {
Expand Down Expand Up @@ -588,18 +597,21 @@ mod mod_data_tests {
spec: ModSpecification::new("a".to_string()),
required: false,
enabled: false,
priority: 50,
};

let mod_2 = ModConfig {
spec: ModSpecification::new("b".to_string()),
required: true,
enabled: false,
priority: 50,
};

let mod_3 = ModConfig {
spec: ModSpecification::new("c".to_string()),
required: false,
enabled: true,
priority: 50,
};

let mod_data = ModData {
Expand Down Expand Up @@ -639,18 +651,21 @@ mod mod_data_tests {
spec: ModSpecification::new("a".to_string()),
required: false,
enabled: false,
priority: 50,
};

let mod_2 = ModConfig {
spec: ModSpecification::new("b".to_string()),
required: true,
enabled: false,
priority: 50,
};

let mod_3 = ModConfig {
spec: ModSpecification::new("c".to_string()),
required: false,
enabled: true,
priority: 50,
};

let mod_data = ModData {
Expand Down

0 comments on commit 0267dc3

Please sign in to comment.