Skip to content

Commit

Permalink
rarity
Browse files Browse the repository at this point in the history
Co-authored-by: Yjn024 <[email protected]>
  • Loading branch information
0123456789-jpg and JieningYu committed Nov 8, 2023
1 parent eba451e commit ae1837c
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions core/src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use formatting::Formatting;

pub mod formatting;
pub mod math;

#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct ColorIndex {
value: i8,
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
#[repr(u8)]
pub enum Rarity {
Common,
Uncommon,
Rare,
Epic,
}

impl ColorIndex {
#[inline]
pub fn new(value: Option<u8>) -> Self {
Self {
value: value.map(|e| e as i8).unwrap_or(-1),
}
}

impl From<Rarity> for Formatting {
#[inline]
pub fn value(self) -> Option<u8> {
if self.value == -1 {
None
} else {
Some(self.value as u8)
fn from(value: Rarity) -> Self {
match value {
Rarity::Common => Formatting::White,
Rarity::Uncommon => Formatting::Yellow,
Rarity::Rare => Formatting::Aqua,
Rarity::Epic => Formatting::LightPurple,
}
}
}

0 comments on commit ae1837c

Please sign in to comment.