diff --git a/src/entity/item/unit.rs b/src/entity/item/unit.rs new file mode 100644 index 0000000..0f7b326 --- /dev/null +++ b/src/entity/item/unit.rs @@ -0,0 +1,60 @@ +use std::convert::{TryFrom, Into}; + +pub enum UnitTypeError { + UnknownUnit(String) +} + + +#[derive(Debug, Copy, Clone, PartialEq)] +pub enum UnitType { + None +} + +impl UnitType { + pub fn value(&self) -> [u8; 3] { + match self { + UnitType::None => [0; 3] + } + } +} + +#[derive(Debug, Copy, Clone, PartialEq)] +pub enum UnitModifier { + PlusPlus, + Plus, + Minus, + MinusMinus, +} + +#[derive(Debug, Copy, Clone, PartialEq)] +pub struct Unit { + pub unit: UnitType, + pub modifier: UnitModifier, +} + + +impl Unit { + pub fn as_bytes(&self) -> [u8; 16] { + let mut result = [0; 16]; + result[0..3].copy_from_slice(&self.unit.value()); + + match self.modifier { + UnitModifier::PlusPlus => { + result[7] = 3; + }, + UnitModifier::Plus => { + result[7] = 1; + }, + UnitModifier::Minus => { + result[7] = 0xFF; + result[8] = 0xFF; + }, + UnitModifier::MinusMinus => { + result[7] = 0xFE; + result[8] = 0xFF; + }, + } + + result + } +}