Skip to content

Commit

Permalink
wip: Start reflecting GameEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
futile committed Jul 17, 2024
1 parent a5a3f7e commit fda61fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/abilities/needling_hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
game_logic::{
commands::{CastAbility, CastAbilityInterface, GameCommand, GameCommandKind},
damage_resolution::{DamageInstance, DealDamage},
effects::{GameEffect, UniqueEffectInterface},
effects::{GameEffect, ReflectGameEffect, UniqueEffectInterface},
faction::Faction,
fight::FightInterface,
Ability, AbilityId, AbilitySlot,
Expand All @@ -34,6 +34,7 @@ fn add_to_ability_catalog(mut abilties_catalog: ResMut<AbilityCatalog>) {
}

#[derive(Debug, Component, Reflect, Deref, DerefMut)]
#[reflect(GameEffect)]
struct NeedlingHexEffect(FiniteRepeatingTimer);

impl GameEffect for NeedlingHexEffect {}
Expand Down
7 changes: 4 additions & 3 deletions src/game_logic/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ impl EffectsHolder {
}

/// Marker trait for components that represent effects
pub trait GameEffect: Component + Reflect + std::fmt::Debug {}
#[reflect_trait]
pub trait GameEffect: Reflect + std::fmt::Debug {}

#[derive(SystemParam)]
pub struct UniqueEffectInterface<'w, 's, E: GameEffect> {
pub struct UniqueEffectInterface<'w, 's, E: GameEffect + Component> {
has_effects: Query<'w, 's, &'static HasEffects>,
effects_holders: Query<'w, 's, &'static EffectsHolder>,
children: Query<'w, 's, &'static Children>,
Expand All @@ -48,7 +49,7 @@ pub struct UniqueEffectInterface<'w, 's, E: GameEffect> {
effect_query: Query<'w, 's, Entity, With<E>>,
}

impl<'w, 's, E: GameEffect> UniqueEffectInterface<'w, 's, E> {
impl<'w, 's, E: GameEffect + Component> UniqueEffectInterface<'w, 's, E> {
pub fn spawn_or_replace_unique_effect(&mut self, target: Entity, effect: E) {
let effect_e = self
.get_unique_effect(target)
Expand Down

0 comments on commit fda61fb

Please sign in to comment.