use bevy::prelude::*;
use issun_core::mechanics::spatial::{NodeId, SpatialEvent, SpatialGraph, SpatialQuery};
#[derive(Resource, Clone, Reflect)]
#[reflect(Resource)]
pub struct SpatialGraphResource {
#[reflect(ignore)]
pub graph: SpatialGraph,
}
impl SpatialGraphResource {
pub fn new(graph: SpatialGraph) -> Self {
Self { graph }
}
}
#[derive(Component, Clone, Debug, Reflect)]
#[reflect(Component)]
pub struct SpatialLocation {
pub node: NodeId,
}
impl SpatialLocation {
pub fn new(node: impl Into<String>) -> Self {
Self { node: node.into() }
}
}
#[derive(bevy::ecs::message::Message, Clone, Debug)]
pub struct SpatialQueryRequest {
pub query: SpatialQuery,
}
impl SpatialQueryRequest {
pub fn new(query: SpatialQuery) -> Self {
Self { query }
}
pub fn neighbors(node: impl Into<String>) -> Self {
Self {
query: SpatialQuery::Neighbors { node: node.into() },
}
}
pub fn distance(from: impl Into<String>, to: impl Into<String>) -> Self {
Self {
query: SpatialQuery::Distance {
from: from.into(),
to: to.into(),
},
}
}
pub fn can_move(from: impl Into<String>, to: impl Into<String>) -> Self {
Self {
query: SpatialQuery::CanMove {
from: from.into(),
to: to.into(),
},
}
}
}
#[derive(bevy::ecs::message::Message, Clone, Debug)]
pub struct SpatialQueryResult {
pub event: SpatialEvent,
}
impl SpatialQueryResult {
pub fn new(event: SpatialEvent) -> Self {
Self { event }
}
}
#[derive(bevy::ecs::message::Message, Clone, Debug)]
pub struct MoveEntityRequest {
pub entity: Entity,
pub from: Option<NodeId>,
pub to: NodeId,
}
impl MoveEntityRequest {
pub fn new(entity: Entity, from: Option<NodeId>, to: impl Into<String>) -> Self {
Self {
entity,
from,
to: to.into(),
}
}
pub fn spawn(entity: Entity, to: impl Into<String>) -> Self {
Self::new(entity, None, to)
}
pub fn move_to(entity: Entity, from: impl Into<String>, to: impl Into<String>) -> Self {
Self::new(entity, Some(from.into()), to)
}
}