use std::collections::HashMap;
use crate::world::Size;
pub use self::constraint::{Constraint, ConstraintType};
#[macro_use]
mod constraint;
pub struct Tile<T> {
value: T,
constraints: Vec<Constraint>
}
impl<T: Clone> Tile<T> {
pub fn new(value: T) -> Tile<T> {
Tile {
value,
constraints: Vec::new()
}
}
pub fn when(self, constraint: Constraint) -> Tile<T> {
Tile {
constraints: { let mut cs = self.constraints; cs.push(constraint); cs },
..self
}
}
pub fn value(&self) -> T {
self.value.clone()
}
pub fn satisfied_by(&self, x: i64, y: i64, size: Size, chunk_x: i64, chunk_y: i64, nms: &mut HashMap<u64, Vec<Vec<f64>>>) -> bool {
self.constraints.iter().all(|constraint| constraint.satisfied_by(x, y, size, chunk_x, chunk_y, nms))
}
}