Attempt at moving away some of the launcher logic from the GUI

This commit is contained in:
2023-06-16 18:40:01 +01:00
parent 587b81c69e
commit b60eb87e34
2 changed files with 90 additions and 47 deletions

View File

@@ -20,6 +20,60 @@ pub struct LauncherInfo {
pub name: String,
}
pub struct LauncherManager {
pub launchers: Vec<LauncherInfo>,
pub current_selected: Option<usize>,
}
impl LauncherManager {
pub fn new() -> LauncherManager {
LauncherManager {
launchers: Vec::new(),
current_selected: None,
}
}
pub fn add(&mut self, launcher: LauncherInfo) {
self.launchers.push(launcher);
}
pub fn get(&self, index: usize) -> Option<(&LauncherInfo, bool)> {
if index > self.launchers.len() {
None
} else {
Some((self.launchers.get(index).unwrap(), index == self.current_selected.unwrap_or(std::usize::MAX)))
}
}
pub fn get_current(&self) -> Option<&LauncherInfo> {
match self.current_selected {
None => None,
Some(pos) => Some(self.launchers.get(pos).unwrap()),
}
}
pub fn set_current(&mut self, index: usize) {
assert!(index <= self.launchers.len());
self.current_selected = Some(index);
}
pub fn clear_current(&mut self) {
self.current_selected = None;
}
pub fn remove_launcher(&mut self, index: usize) {
assert!(index <= self.launchers.len());
self.launchers.remove(index);
}
pub fn iter_with_pos_and_selected(
&mut self,
) -> impl Iterator<Item = (&mut LauncherInfo, usize, bool)> + '_ {
self.launchers
.iter_mut()
.enumerate()
.map(|(i, l)| (l, i, i == self.current_selected.unwrap_or(std::usize::MAX)))
}
}
pub struct IwadManager {
pub wads: Vec<WadInfo>,
pub current_selected: Option<usize>,
}
#[derive(PartialEq, Clone, Copy)]
pub enum Difficulty {
None,
@@ -64,5 +118,5 @@ impl Difficulty {
Difficulty::Hard => "4",
Difficulty::Nightmare => "5",
}
}
}
}