|
- use glc::vector::Vector2f;
- use serde::{Deserialize, Serialize};
- use specs::{Component, VecStorage};
-
- #[derive(Clone, Debug, Default, Serialize, Deserialize)]
- pub struct Position {
- pub pos: Vector2f,
- pub shape: Shape,
- }
-
- #[derive(Clone, Debug, Serialize, Deserialize)]
- pub enum Shape {
- Dot,
- Circle(f32),
- }
-
- impl Component for Position {
- type Storage = VecStorage<Self>;
- }
-
- impl Shape {
- pub fn radius(&self) -> Option<f32> {
- match self {
- Self::Dot => Some(0.0),
- Self::Circle(r) => Some(*r),
- }
- }
-
- pub fn circle(&self) -> Option<f32> {
- if let Self::Circle(r) = &self {
- Some(*r)
- } else {
- None
- }
- }
- }
-
- impl Default for Shape {
- fn default() -> Self {
- Self::Dot
- }
- }
|