Skip to content

Commit

Permalink
improve responsiveness of flux interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
UkoeHB committed Aug 29, 2024
1 parent 6afd58b commit cc5f25e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion crates/sickle_ui_scaffold/src/flux_interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ impl Plugin for FluxInteractionPlugin {
.add_systems(
Update,
(
tick_flux_interaction_stopwatch,
update_flux_interaction,
reset_flux_interaction_stopwatch_on_change,
update_prev_interaction,
tick_flux_interaction_stopwatch,
)
.chain()
.in_set(FluxInteractionUpdate),
Expand Down
50 changes: 29 additions & 21 deletions crates/sickle_ui_scaffold/src/theme/dynamic_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ impl Plugin for DynamicStylePlugin {
.add_systems(
PostUpdate,
(
tick_dynamic_style_stopwatch,
update_dynamic_style_static_attributes,
update_dynamic_style_on_flux_change,
tick_dynamic_style_stopwatch,
update_dynamic_style_on_stopwatch_change,
cleanup_dynamic_style_stopwatch,
)
.chain()
.in_set(DynamicStylePostUpdate),
Expand All @@ -35,26 +36,6 @@ impl Plugin for DynamicStylePlugin {
#[derive(SystemSet, Clone, Eq, Debug, Hash, PartialEq)]
pub struct DynamicStylePostUpdate;

fn tick_dynamic_style_stopwatch(
time: Res<Time<Real>>,
mut q_stopwatches: Query<(Entity, &mut DynamicStyleStopwatch)>,
mut commands: Commands,
) {
for (entity, mut style_stopwatch) in &mut q_stopwatches {
let remove_stopwatch = match style_stopwatch.1 {
StopwatchLock::None => true,
StopwatchLock::Infinite => false,
StopwatchLock::Duration(length) => style_stopwatch.0.elapsed() > length,
};

if remove_stopwatch {
commands.entity(entity).remove::<DynamicStyleStopwatch>();
}

style_stopwatch.0.tick(time.delta());
}
}

fn update_dynamic_style_static_attributes(
mut q_styles: Query<(Entity, &mut DynamicStyle), Changed<DynamicStyle>>,
mut commands: Commands,
Expand Down Expand Up @@ -143,6 +124,16 @@ fn update_dynamic_style_on_flux_change(
}
}

fn tick_dynamic_style_stopwatch(
time: Res<Time<Real>>,
mut q_stopwatches: Query<(Entity, &mut DynamicStyleStopwatch)>,
mut commands: Commands,
) {
for (entity, mut style_stopwatch) in &mut q_stopwatches {
style_stopwatch.0.tick(time.delta());
}
}

fn update_dynamic_style_on_stopwatch_change(
mut q_styles: Query<
(
Expand Down Expand Up @@ -235,6 +226,23 @@ fn update_dynamic_style_on_stopwatch_change(
});
}

fn cleanup_dynamic_style_stopwatch(
mut q_stopwatches: Query<(Entity, &mut DynamicStyleStopwatch)>,
mut commands: Commands,
) {
for (entity, mut style_stopwatch) in &mut q_stopwatches {
let remove_stopwatch = match style_stopwatch.1 {
StopwatchLock::None => true,
StopwatchLock::Infinite => false,
StopwatchLock::Duration(length) => style_stopwatch.0.elapsed() > length,
};

if remove_stopwatch {
commands.entity(entity).remove::<DynamicStyleStopwatch>();
}
}
}

#[derive(Component, Clone, Debug, Default)]
#[component(storage = "SparseSet")]
pub struct DynamicStyleStopwatch(pub Stopwatch, pub StopwatchLock);
Expand Down

0 comments on commit cc5f25e

Please sign in to comment.