You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
797 B

  1. use glc::vector::Vector2f;
  2. use serde::{Deserialize, Serialize};
  3. use specs::{Component, VecStorage};
  4. #[derive(Clone, Debug, Default, Serialize, Deserialize)]
  5. pub struct Position {
  6. pub pos: Vector2f,
  7. pub shape: Shape,
  8. }
  9. #[derive(Clone, Debug, Serialize, Deserialize)]
  10. pub enum Shape {
  11. Dot,
  12. Circle(f32),
  13. }
  14. impl Component for Position {
  15. type Storage = VecStorage<Self>;
  16. }
  17. impl Shape {
  18. pub fn radius(&self) -> Option<f32> {
  19. match self {
  20. Self::Dot => Some(0.0),
  21. Self::Circle(r) => Some(*r),
  22. }
  23. }
  24. pub fn circle(&self) -> Option<f32> {
  25. if let Self::Circle(r) = &self {
  26. Some(*r)
  27. } else {
  28. None
  29. }
  30. }
  31. }
  32. impl Default for Shape {
  33. fn default() -> Self {
  34. Self::Dot
  35. }
  36. }