Skip to content

Commit

Permalink
Adds from to struct color for lighter syntax
Browse files Browse the repository at this point in the history
remove ununsed traits
  • Loading branch information
Slyker committed Apr 16, 2024
1 parent 5c1a10e commit 6badd97
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 58 deletions.
55 changes: 17 additions & 38 deletions src-tauri/src/data/cloud_detection_categorie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,14 @@ const FULL_BOUNDS: Bounds = Bounds { // Full screen not really full cause of sta
h: 600,
};

#[derive(Debug, Copy, PartialEq, Eq, Default, Hash)]
#[derive(Debug, Copy, PartialEq, Eq, Default, Hash, Clone)]
pub enum CloudDetectionCategorie {
#[default]
None,
Mover(CloudDetectionKind),
Stat(CloudDetectionKind),
}

impl Clone for CloudDetectionCategorie {
fn clone(&self) -> Self {
match self {
Self::None => Self::None,
Self::Mover(t) => Self::Mover(t.clone()),
Self::Stat(t) => Self::Stat(t.clone()),
}
}
}

impl CloudDetectionCategorie {
pub fn get_bounds(&self) -> Bounds {
match self {
Expand Down Expand Up @@ -79,35 +69,24 @@ impl CloudDetectionCategorie {
Self::Stat(t) => {
match t {
CloudDetectionKind::HP(_) =>
Some(ColorDetection {
colors: vec![
Color::new([174, 18, 55], None),
Color::new([188, 24, 62], None),
Color::new([204, 30, 70], None),
Color::new([220, 36, 78], None)
],
tolerance: 5,
}),
Some(
ColorDetection::from(
vec![[174, 18, 55], [188, 24, 62], [204, 30, 70], [220, 36, 78]]
)
),
CloudDetectionKind::MP(_) =>
Some(ColorDetection {
colors: vec![
Color::new([20, 84, 196], None),
Color::new([36, 132, 220], None),
Color::new([44, 164, 228], None),
Color::new([56, 188, 232], None)
],
tolerance: 5,
}),
Some(
ColorDetection::from(
vec![[20, 84, 196], [36, 132, 220], [44, 164, 228], [56, 188, 232]]
)
),

CloudDetectionKind::FP =>
Some(ColorDetection {
colors: vec![
Color::new([45, 230, 29], None),
Color::new([28, 172, 28], None),
Color::new([44, 124, 52], None),
Color::new([20, 146, 20], None)
],
tolerance: 5,
}),
Some(
ColorDetection::from(
vec![[45, 230, 29], [28, 172, 28], [44, 124, 52], [20, 146, 20]]
)
),
_ => None,
}
}
Expand Down
14 changes: 1 addition & 13 deletions src-tauri/src/data/cloud_detection_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Display;

use super::MobType;

#[derive(Debug, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, PartialEq, Eq, Hash, Clone)]
pub enum CloudDetectionKind {
HP(bool), // bool is for whether we search for player or target stats
MP(bool),
Expand Down Expand Up @@ -35,18 +35,6 @@ impl CloudDetectionKind {
}
}

impl Clone for CloudDetectionKind {
fn clone(&self) -> Self {
match self {
Self::HP(t) => Self::HP(*t),
Self::MP(t) => Self::MP(*t),
Self::FP => Self::FP,
Self::Mob(t) => Self::Mob(*t),
Self::Target(t) => Self::Target(*t),
}
}
}

impl Display for CloudDetectionKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.to_string().fmt(f)
Expand Down
25 changes: 25 additions & 0 deletions src-tauri/src/data/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ pub struct ColorDetection {
}

impl ColorDetection {
pub fn from(color: Vec<[u8; 3]>) -> Self{
Self {
colors: {
let mut colors = vec![];
for c in color {
colors.push(Color::new(c, None));
}
colors
},
tolerance: 5,
}
}

/* pub fn from_with_tolerance(color: Vec<[u8; 4]>, tolerance: u8) -> Self{
Self {
colors: {
let mut colors = vec![];
for c in color {
colors.push(Color::new([c[0],c[1],c[2]], Some(c[3])));
}
colors
},
tolerance,
}
} */
#[inline(always)]
pub fn color_match(&self, color: &[u8; 4]) -> bool {
// Color matching based on tolerance
Expand Down
7 changes: 0 additions & 7 deletions src-tauri/src/image_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,6 @@ impl<'a> ImageAnalyzer<'a> {
.collect();

self.client_stats.update(&detected_clouds);
/* // remove stats clouds
detected_clouds.retain(|x| {
match x.kind {
CloudDetectionCategorie::Stat(_) => false,
_ => true,
}
}); */

let result = detected_clouds.par_iter().find_map_first(move |cloud| {
match cloud.kind {
Expand Down

0 comments on commit 6badd97

Please sign in to comment.