pong_cli/components/confined.rs
1use crate::geo::Rect;
2
3use super::component_prelude::*;
4
5/// Entities' `Position`s are _confined_ to an area with this component.
6/// Their `Position` may never leave this confined area.
7#[derive(Component)]
8#[storage(DenseVecStorage)]
9pub struct Confined {
10 pub rect: Rect,
11}
12impl Confined {
13 pub fn new(rect: Rect) -> Self {
14 Self { rect }
15 }
16}
17
18impl From<Rect> for Confined {
19 fn from(rect: Rect) -> Self {
20 Self { rect }
21 }
22}
23
24impl From<&Rect> for Confined {
25 fn from(rect: &Rect) -> Self {
26 Self { rect: rect.clone() }
27 }
28}