use crate::prelude::*;
pub fn street_around(map: &mut Map, texture_id: u32) {
let inner_shape = map.get_shape();
let outer_width = inner_shape.width + 2;
let outer_height = inner_shape.height + 2;
let mut edge_coords = Vec::new();
for x in 0..outer_width {
edge_coords.push(Coordinates { x: x, y: 0 });
edge_coords.push(Coordinates {
x,
y: (outer_height - 1),
});
}
for y in 1..(outer_height - 1) {
edge_coords.push(Coordinates { x: 0, y: y });
edge_coords.push(Coordinates {
x: (outer_width - 1),
y,
});
}
let mask = Mask::new(
"street_border".to_string(),
edge_coords
.into_iter()
.map(|c| Rect::new(c, Shape::from_square(1)))
.collect(),
vec![Effect::Texture(texture_id)],
);
let street_layer = Layer::new("street".to_string(), vec![mask], 3);
map.load_layer(street_layer);
}
pub fn street_layer_around(shape: Shape, texture_id: u32) -> Layer {
let outer_shape = Shape {
width: shape.width + 2,
height: shape.height + 2,
};
let mut edge_coords = Vec::new();
for x in 0..outer_shape.width {
edge_coords.push(Coordinates { x, y: 0 }); edge_coords.push(Coordinates {
x,
y: outer_shape.height - 1,
}); }
for y in 1..(outer_shape.height - 1) {
edge_coords.push(Coordinates { x: 0, y }); edge_coords.push(Coordinates {
x: outer_shape.width - 1,
y,
}); }
let mask = Mask::new(
"street_border".to_string(),
edge_coords
.iter()
.map(|c| Rect::new(*c, Shape::from_square(1)))
.collect(),
vec![Effect::Texture(texture_id)],
);
let street_layer = Layer::new("street".to_string(), vec![mask], 3);
street_layer
}