Documentation
use super::*;

/// Physics character component
///
/// Use to get predictable collisions against the physics world for an entity. Suitable for things
/// like FPS shooter characters and other similar things that are directly controlled by the player
/// and would be impractical to get to behave correctly using real physics.
///
/// Puts a capsule around the entity, defined by the height and radius properties, to do collisions.
/// Uses the `Velocity` component to update the position of the entity and leaves adding gravity to that
/// to the user.

#[cfg(target_arch = "wasm32")]
pub struct PhysicsCharacter {
    id: Entity,
}

impl std::fmt::Debug for PhysicsCharacter {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("PhysicsCharacter")
            .field("entity", &self.id.name())
            .finish_non_exhaustive()
    }
}

#[cfg(target_arch = "wasm32")]
impl PhysicsCharacter {
    impl_world_accessor!(
        /// Returns a `ValueAccessor` for the character radius (horizontal plane).
        PhysicsCharacter,
        Radius,
        f32,
        radius,
        ValueAccessorReadWriteAnimate
    );

    impl_world_accessor!(
        /// Returns a `ValueAccessor` for the character vertical height.
        PhysicsCharacter,
        Height,
        f32,
        height,
        ValueAccessorReadWriteAnimate
    );

    impl_world_accessor!(
        /// Returns a `ValueAccessor` for the character up direction.
        PhysicsCharacter,
        UpDirection,
        Vec3,
        up_direction,
        ValueAccessorReadWriteAnimate
    );

    impl_world_accessor!(
        /// Returns a `ValueAccessor` for the character collision flags.
        ///
        /// Use it to see what collisions the last frame resulted in, for instance
        /// to reset velocity if ground was hit. Can only be read.
        PhysicsCharacter,
        CollisionFlags,
        CharacterCollisionFlags,
        collision_flags,
        ValueAccessorRead
    );

    impl_world_accessor!(
        /// Returns a `ValueAccessor` for the world linear velocity of the physics character.
        ///
        /// Used to set/get/animate the velocity.
        PhysicsCharacter,
        Velocity,
        Vec3,
        velocity,
        ValueAccessorReadWriteAnimate
    );
}

impl_world_component!(PhysicsCharacter);