use bevy::prelude::*;
use crate::{
commands::CommandsExt,
interactives::ItemRef,
state::WorldState,
textdisplay::Message,
Item,
};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug)]
pub enum Action<State> {
AddItem(Item),
Animation(String),
Audio(String),
Message(Message),
Transition(State),
Move(String),
Jump(String),
}
impl<State> Action<State> {
pub fn single(self) -> Vec<Self> {
vec![self]
}
}
impl<T> From<Action<T>> for Vec<Action<T>> {
fn from(action: Action<T>) -> Self {
vec![action]
}
}
impl<T> From<Item> for Action<T> {
fn from(item: Item) -> Self {
Action::AddItem(item)
}
}
impl<T> From<Item> for Vec<Action<T>> {
fn from(item: Item) -> Self {
vec![item.into()]
}
}
impl<T> From<Message> for Action<T> {
fn from(message: Message) -> Self {
Action::Message(message)
}
}
impl<T> From<Message> for Vec<Action<T>> {
fn from(message: Message) -> Self {
vec![message.into()]
}
}
pub fn invalid_item_used<T>() -> Vec<Action<T>> {
Action::Message(Message::InvalidItemUsed).single()
}
#[allow(unused_variables)]
pub trait Interactive {
type State: States;
fn use_item(
&mut self,
state: &mut ResMut<WorldState>,
item: &mut ItemRef,
) -> Vec<Action<Self::State>> {
Action::Message(Message::InvalidItemUsed).single()
}
fn update(&mut self, commands: &mut CommandsExt, state: &mut ResMut<WorldState>) {}
fn interact(&mut self, state: &mut ResMut<WorldState>) -> Vec<Action<Self::State>>;
}