pub struct MaterialStorage {
total_planks: u32,
planks_new: Vec<Plank>,
planks_used: Vec<Plank>,
planks_too_short: Vec<Plank>,
}
impl Default for MaterialStorage {
/// Create a new, default storage
fn default() -> Self {
Self {
total_planks: AVAILABLEPLANKS,
planks_new: vec![Plank::default(); AVAILABLEPLANKS as usize],
planks_used: vec![],
planks_too_short: vec![],
}
}
}
impl MaterialStorage {
pub fn new(&self) -> Self {
MaterialStorage::default()
}
/// Does there exist used/cut planks?
pub fn exists_used(&self) -> bool {
!self.planks_used.is_empty()
}
/// Get a used plank
pub fn get_used(&mut self) -> Option<Plank> {
self.planks_used.pop()
}
/// Get how many cut planks exists
pub fn get_used_count(&self) -> u32 {
self.planks_used.len() as u32
}
/// Does there exist new planks
pub fn exists_new(&self) -> bool {
!self.planks_new.is_empty()
}
/// Get a new plank
pub fn get_new(&mut self) -> Option<Plank> {
self.planks_new.pop()
}
}
// Define a plank piece structure
#[derive(Debug, Clone, Copy)]