-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Yjn024 <[email protected]>
- Loading branch information
1 parent
eba451e
commit ae1837c
Showing
1 changed file
with
16 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} | ||
} |