Browse Source

might help to include unit.rs

pbs
jake 5 years ago
parent
commit
c0479f5476
  1. 60
      src/entity/item/unit.rs

60
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
}
}
Loading…
Cancel
Save