diff options
author | Silas Bartha <[email protected]> | 2024-11-21 12:17:08 -0500 |
---|---|---|
committer | Silas Bartha <[email protected]> | 2024-11-21 12:17:08 -0500 |
commit | 57827d53713e9bdf65a0bcc34fe670cfe8b356dd (patch) | |
tree | 478ae6a9c50d3bc6f89696494884b6be7f2918d8 /src/components.rs | |
parent | 85c80561669bdf7b0f491ee4d7e49f2cc8f7b81c (diff) |
Thu Nov 21 12:17:08 PM EST 2024
Diffstat (limited to 'src/components.rs')
-rw-r--r-- | src/components.rs | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/components.rs b/src/components.rs index 1be2f2c..c2b2547 100644 --- a/src/components.rs +++ b/src/components.rs @@ -6,7 +6,7 @@ use bevy::{prelude::*, utils::HashSet}; /// /// An entity with an `Interactor` component can be passed to an `InteractorFiredEvent` in order to /// start an interaction with any nearby `Interactable` entities. -#[derive(Component, Default)] +#[derive(Component, Default, Debug)] pub struct Interactor { /// All `Interactable` targets in-range of this interactor. pub targets: HashSet<Entity>, @@ -18,10 +18,19 @@ pub struct Interactor { /// /// An entity with an `Interactable` component might get passed to an `InteractionEvent` when an /// `Interactor` requests an interaction, if the interactable is in range. -#[derive(Component)] +#[derive(Component, Clone, Debug)] pub struct Interactable { + /// An optional name for this interactable + pub name: Option<String>, + /// An optional description of the action + pub description: Option<String>, + /// Predicate to check to see if interaction is possible + pub predicate: Option<fn(Entity, &mut World) -> bool>, pub(crate) exclusive: bool, pub(crate) max_distance_squared: f32, + pub(crate) possible: bool, + /// Whether this pickup is enabled + pub enabled: bool, } impl Interactable { @@ -30,17 +39,27 @@ impl Interactable { /// If exclusive, this interactable will only be interacted with if it's the closest one to the /// interactor, and the interaction will *not* be processed for any other in-range /// interactables. - pub fn new(max_distance: f32, exclusive: bool) -> Self { + pub fn new(max_distance: f32, exclusive: bool, name: Option<String>, description: Option<String>, predicate: Option<fn(Entity, &mut World) -> bool>) -> Self { Self { + name, + description, + predicate, exclusive, max_distance_squared: max_distance * max_distance, + possible: true, + enabled: true, } } + + /// Gets whether this interaction is currently possible. Set this value using predicate. + pub fn possible(&self) -> bool { + self.possible + } } impl Default for Interactable { fn default() -> Self { - Self::new(1.0, false) + Self::new(1.0, false, None, None, None) } } |