diff --git a/src/game/card/action.rs b/src/game/card/action.rs index ba5ad66..fe17c07 100644 --- a/src/game/card/action.rs +++ b/src/game/card/action.rs @@ -37,17 +37,15 @@ impl FromWorld for CardActionMap { CardActionKey::Step, world.register_system(|In(entity): In, world: &mut World| { r!(world.get_entity_mut(entity)) - .insert((MoveTowardsFacing, RemoveOnBeat::::new(5))); + .insert(RemoveOnBeat::bundle(MoveTowardsFacing, 1)); }), ), ( CardActionKey::DoubleBeat, world.register_system(|In(entity): In, world: &mut World| { r!(world.get_entity_mut(entity)).insert(( - DoubleBeat, - RemoveOnBeat::::new(2), - AimTowardsFacing, - RemoveOnBeat::::new(2), + RemoveOnBeat::bundle(DoubleBeat, 2), + RemoveOnBeat::bundle(AimTowardsFacing, 2), )); }), ), diff --git a/src/game/cleanup.rs b/src/game/cleanup.rs index 17f4370..006e691 100644 --- a/src/game/cleanup.rs +++ b/src/game/cleanup.rs @@ -128,20 +128,24 @@ pub struct RemoveOnTimer { phantom: PhantomData, } +impl Configure for RemoveOnTimer { + fn configure(app: &mut App) { + app.register_type::(); + app.add_systems(Update, remove_on_timer::.in_set(UpdateSet::SyncLate)); + } +} + +#[allow(dead_code)] impl RemoveOnTimer { - #[allow(dead_code)] pub fn new(timer: Timer) -> Self { - RemoveOnTimer { + Self { timer, - phantom: PhantomData::, + phantom: PhantomData, } } -} -impl Configure for RemoveOnTimer { - fn configure(app: &mut App) { - app.register_type::(); - app.add_systems(Update, remove_on_timer::.in_set(UpdateSet::SyncLate)); + pub fn bundle(component: C, timer: Timer) -> (C, Self) { + (component, Self::new(timer)) } } @@ -152,7 +156,7 @@ fn remove_on_timer( ) { for (entity, mut remove) in &mut remove_query { if remove.timer.tick(time.delta()).finished() { - commands.entity(entity).remove::<(RemoveOnTimer, C)>(); + commands.entity(entity).remove::<(C, RemoveOnTimer)>(); } } } @@ -178,12 +182,16 @@ impl Configure for RemoveOnBeat { } impl RemoveOnBeat { - pub fn new(count: usize) -> Self { - RemoveOnBeat { - beat: count, + pub fn new(beat: usize) -> Self { + Self { + beat, phantom: PhantomData, } } + + pub fn bundle(component: C, beat: usize) -> (C, Self) { + (component, Self::new(beat)) + } } fn remove_on_beat( @@ -192,7 +200,7 @@ fn remove_on_beat( ) { for (entity, mut remove) in &mut remove_query { if remove.beat <= 1 { - commands.entity(entity).remove::<(RemoveOnBeat, C)>(); + commands.entity(entity).remove::<(C, RemoveOnBeat)>(); } remove.beat = remove.beat.saturating_sub(1); }