Skip to content

Commit 5b6ed01

Browse files
SUPERCILEXazarmadr
authored andcommitted
Make completed event API consistent (djeedai#30)
Signed-off-by: Alex Saveau <[email protected]>
1 parent 8e0ecab commit 5b6ed01

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

examples/sequence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
119119
},
120120
)
121121
// Get an event after each segment
122-
.with_completed_event(true, index as u64)
122+
.with_completed_event(index as u64)
123123
}));
124124

125125
commands
@@ -145,7 +145,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
145145
end: Vec3::new(200., 100., 0.),
146146
},
147147
)
148-
.with_completed_event(true, 99); // Get an event once move completed
148+
.with_completed_event(99); // Get an event once move completed
149149
let tween_rotate = Tween::new(
150150
EaseFunction::QuadraticInOut,
151151
TweeningType::Once,

src/tweenable.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl<T> Tween<T> {
374374
/// # end: Vec3::new(3.5, 0., 0.),
375375
/// # },
376376
/// )
377-
/// .with_completed_event(true, 42);
377+
/// .with_completed_event(42);
378378
///
379379
/// fn my_system(mut reader: EventReader<TweenCompleted>) {
380380
/// for ev in reader.iter() {
@@ -386,8 +386,8 @@ impl<T> Tween<T> {
386386
///
387387
/// [`set_completed()`]: Tween::set_completed
388388
#[must_use]
389-
pub fn with_completed_event(mut self, enabled: bool, user_data: u64) -> Self {
390-
self.event_data = if enabled { Some(user_data) } else { None };
389+
pub fn with_completed_event(mut self, user_data: u64) -> Self {
390+
self.event_data = Some(user_data);
391391
self
392392
}
393393

@@ -425,7 +425,7 @@ impl<T> Tween<T> {
425425
self.direction
426426
}
427427

428-
/// Set a callback invoked when the animation completed.
428+
/// Set a callback invoked when the animation completes.
429429
///
430430
/// The callback when invoked receives as parameters the [`Entity`] on which
431431
/// the target and the animator are, as well as a reference to the
@@ -439,7 +439,7 @@ impl<T> Tween<T> {
439439
self.on_completed = Some(Box::new(callback));
440440
}
441441

442-
/// Clear the callback invoked when the animation completed.
442+
/// Clear the callback invoked when the animation completes.
443443
pub fn clear_completed(&mut self) {
444444
self.on_completed = None;
445445
}
@@ -454,8 +454,13 @@ impl<T> Tween<T> {
454454
///
455455
/// [`set_completed()`]: Tween::set_completed
456456
/// [`with_completed_event()`]: Tween::with_completed_event
457-
pub fn set_completed_event(&mut self, enabled: bool, user_data: u64) {
458-
self.event_data = if enabled { Some(user_data) } else { None };
457+
pub fn set_completed_event(&mut self, user_data: u64) {
458+
self.event_data = Some(user_data);
459+
}
460+
461+
/// Clear the event sent when the animation completes.
462+
pub fn clear_completed_event(&mut self) {
463+
self.event_data = None;
459464
}
460465
}
461466

@@ -959,7 +964,7 @@ mod tests {
959964

960965
// Activate event sending
961966
const USER_DATA: u64 = 54789; // dummy
962-
tween.set_completed_event(true, USER_DATA);
967+
tween.set_completed_event(USER_DATA);
963968
assert!(tween.event_data.is_some());
964969
assert_eq!(tween.event_data.unwrap(), USER_DATA);
965970

0 commit comments

Comments
 (0)