@@ -54,6 +54,34 @@ impl Timer {
5454 }
5555 }
5656
57+ /// Returns `true` if the timer has reached its duration.
58+ ///
59+ /// For repeating timers, this method behaves identically to [`Timer::just_finished`].
60+ ///
61+ /// # Examples
62+ /// ```
63+ /// # use bevy_time::*;
64+ /// use std::time::Duration;
65+ ///
66+ /// let mut timer_once = Timer::from_seconds(1.0, TimerMode::Once);
67+ /// timer_once.tick(Duration::from_secs_f32(1.5));
68+ /// assert!(timer_once.is_finished());
69+ /// timer_once.tick(Duration::from_secs_f32(0.5));
70+ /// assert!(timer_once.is_finished());
71+ ///
72+ /// let mut timer_repeating = Timer::from_seconds(1.0, TimerMode::Repeating);
73+ /// timer_repeating.tick(Duration::from_secs_f32(1.1));
74+ /// assert!(timer_repeating.is_finished());
75+ /// timer_repeating.tick(Duration::from_secs_f32(0.8));
76+ /// assert!(!timer_repeating.is_finished());
77+ /// timer_repeating.tick(Duration::from_secs_f32(0.6));
78+ /// assert!(timer_repeating.is_finished());
79+ /// ```
80+ #[ inline]
81+ pub fn is_finished ( & self ) -> bool {
82+ self . finished
83+ }
84+
5785 /// Returns `true` if the timer has reached its duration.
5886 ///
5987 /// For repeating timers, this method behaves identically to [`Timer::just_finished`].
@@ -77,6 +105,7 @@ impl Timer {
77105 /// timer_repeating.tick(Duration::from_secs_f32(0.6));
78106 /// assert!(timer_repeating.finished());
79107 /// ```
108+ #[ deprecated( since = "0.17.0" , note = "Use `is_finished` instead" ) ]
80109 #[ inline]
81110 pub fn finished ( & self ) -> bool {
82111 self . finished
@@ -143,7 +172,7 @@ impl Timer {
143172 /// timer.set_elapsed(Duration::from_secs(2));
144173 /// assert_eq!(timer.elapsed(), Duration::from_secs(2));
145174 /// // the timer is not finished even if the elapsed time is greater than the duration.
146- /// assert!(!timer.finished ());
175+ /// assert!(!timer.is_finished ());
147176 /// ```
148177 #[ inline]
149178 pub fn set_elapsed ( & mut self , time : Duration ) {
@@ -230,23 +259,23 @@ impl Timer {
230259 /// assert_eq!(repeating.elapsed_secs(), 0.5);
231260 /// ```
232261 pub fn tick ( & mut self , delta : Duration ) -> & Self {
233- if self . paused ( ) {
262+ if self . is_paused ( ) {
234263 self . times_finished_this_tick = 0 ;
235264 if self . mode == TimerMode :: Repeating {
236265 self . finished = false ;
237266 }
238267 return self ;
239268 }
240269
241- if self . mode != TimerMode :: Repeating && self . finished ( ) {
270+ if self . mode != TimerMode :: Repeating && self . is_finished ( ) {
242271 self . times_finished_this_tick = 0 ;
243272 return self ;
244273 }
245274
246275 self . stopwatch . tick ( delta) ;
247276 self . finished = self . elapsed ( ) >= self . duration ( ) ;
248277
249- if self . finished ( ) {
278+ if self . is_finished ( ) {
250279 if self . mode == TimerMode :: Repeating {
251280 self . times_finished_this_tick = self
252281 . elapsed ( )
@@ -308,6 +337,25 @@ impl Timer {
308337 self . stopwatch . unpause ( ) ;
309338 }
310339
340+ /// Returns `true` if the timer is paused.
341+ ///
342+ /// See also [`Stopwatch::is_paused`](Stopwatch::is_paused).
343+ ///
344+ /// # Examples
345+ /// ```
346+ /// # use bevy_time::*;
347+ /// let mut timer = Timer::from_seconds(1.0, TimerMode::Once);
348+ /// assert!(!timer.is_paused());
349+ /// timer.pause();
350+ /// assert!(timer.is_paused());
351+ /// timer.unpause();
352+ /// assert!(!timer.is_paused());
353+ /// ```
354+ #[ inline]
355+ pub fn is_paused ( & self ) -> bool {
356+ self . stopwatch . is_paused ( )
357+ }
358+
311359 /// Returns `true` if the timer is paused.
312360 ///
313361 /// See also [`Stopwatch::is_paused`](Stopwatch::is_paused).
@@ -322,6 +370,7 @@ impl Timer {
322370 /// timer.unpause();
323371 /// assert!(!timer.paused());
324372 /// ```
373+ #[ deprecated( since = "0.17.0" , note = "Use `is_paused` instead" ) ]
325374 #[ inline]
326375 pub fn paused ( & self ) -> bool {
327376 self . stopwatch . is_paused ( )
@@ -338,7 +387,7 @@ impl Timer {
338387 /// let mut timer = Timer::from_seconds(1.0, TimerMode::Once);
339388 /// timer.tick(Duration::from_secs_f32(1.5));
340389 /// timer.reset();
341- /// assert!(!timer.finished ());
390+ /// assert!(!timer.is_finished ());
342391 /// assert!(!timer.just_finished());
343392 /// assert_eq!(timer.elapsed_secs(), 0.0);
344393 /// ```
@@ -466,7 +515,7 @@ mod tests {
466515 assert_eq ! ( t. elapsed_secs( ) , 0.25 ) ;
467516 assert_eq ! ( t. elapsed_secs_f64( ) , 0.25 ) ;
468517 assert_eq ! ( t. duration( ) , Duration :: from_secs_f32( 10.0 ) ) ;
469- assert ! ( !t. finished ( ) ) ;
518+ assert ! ( !t. is_finished ( ) ) ;
470519 assert ! ( !t. just_finished( ) ) ;
471520 assert_eq ! ( t. times_finished_this_tick( ) , 0 ) ;
472521 assert_eq ! ( t. mode( ) , TimerMode :: Once ) ;
@@ -477,7 +526,7 @@ mod tests {
477526 t. tick ( Duration :: from_secs_f32 ( 500.0 ) ) ;
478527 assert_eq ! ( t. elapsed_secs( ) , 0.25 ) ;
479528 assert_eq ! ( t. duration( ) , Duration :: from_secs_f32( 10.0 ) ) ;
480- assert ! ( !t. finished ( ) ) ;
529+ assert ! ( !t. is_finished ( ) ) ;
481530 assert ! ( !t. just_finished( ) ) ;
482531 assert_eq ! ( t. times_finished_this_tick( ) , 0 ) ;
483532 assert_eq ! ( t. mode( ) , TimerMode :: Once ) ;
@@ -488,7 +537,7 @@ mod tests {
488537 t. tick ( Duration :: from_secs_f32 ( 500.0 ) ) ;
489538 assert_eq ! ( t. elapsed_secs( ) , 10.0 ) ;
490539 assert_eq ! ( t. elapsed_secs_f64( ) , 10.0 ) ;
491- assert ! ( t. finished ( ) ) ;
540+ assert ! ( t. is_finished ( ) ) ;
492541 assert ! ( t. just_finished( ) ) ;
493542 assert_eq ! ( t. times_finished_this_tick( ) , 1 ) ;
494543 assert_eq ! ( t. fraction( ) , 1.0 ) ;
@@ -497,7 +546,7 @@ mod tests {
497546 t. tick ( Duration :: from_secs_f32 ( 1.0 ) ) ;
498547 assert_eq ! ( t. elapsed_secs( ) , 10.0 ) ;
499548 assert_eq ! ( t. elapsed_secs_f64( ) , 10.0 ) ;
500- assert ! ( t. finished ( ) ) ;
549+ assert ! ( t. is_finished ( ) ) ;
501550 assert ! ( !t. just_finished( ) ) ;
502551 assert_eq ! ( t. times_finished_this_tick( ) , 0 ) ;
503552 assert_eq ! ( t. fraction( ) , 1.0 ) ;
@@ -512,7 +561,7 @@ mod tests {
512561 assert_eq ! ( t. elapsed_secs( ) , 0.75 ) ;
513562 assert_eq ! ( t. elapsed_secs_f64( ) , 0.75 ) ;
514563 assert_eq ! ( t. duration( ) , Duration :: from_secs_f32( 2.0 ) ) ;
515- assert ! ( !t. finished ( ) ) ;
564+ assert ! ( !t. is_finished ( ) ) ;
516565 assert ! ( !t. just_finished( ) ) ;
517566 assert_eq ! ( t. times_finished_this_tick( ) , 0 ) ;
518567 assert_eq ! ( t. mode( ) , TimerMode :: Repeating ) ;
@@ -522,7 +571,7 @@ mod tests {
522571 t. tick ( Duration :: from_secs_f32 ( 1.5 ) ) ;
523572 assert_eq ! ( t. elapsed_secs( ) , 0.25 ) ;
524573 assert_eq ! ( t. elapsed_secs_f64( ) , 0.25 ) ;
525- assert ! ( t. finished ( ) ) ;
574+ assert ! ( t. is_finished ( ) ) ;
526575 assert ! ( t. just_finished( ) ) ;
527576 assert_eq ! ( t. times_finished_this_tick( ) , 1 ) ;
528577 assert_eq ! ( t. fraction( ) , 0.125 ) ;
@@ -531,7 +580,7 @@ mod tests {
531580 t. tick ( Duration :: from_secs_f32 ( 1.0 ) ) ;
532581 assert_eq ! ( t. elapsed_secs( ) , 1.25 ) ;
533582 assert_eq ! ( t. elapsed_secs_f64( ) , 1.25 ) ;
534- assert ! ( !t. finished ( ) ) ;
583+ assert ! ( !t. is_finished ( ) ) ;
535584 assert ! ( !t. just_finished( ) ) ;
536585 assert_eq ! ( t. times_finished_this_tick( ) , 0 ) ;
537586 assert_eq ! ( t. fraction( ) , 0.625 ) ;
@@ -546,7 +595,7 @@ mod tests {
546595 assert_eq ! ( t. times_finished_this_tick( ) , 3 ) ;
547596 assert_eq ! ( t. elapsed_secs( ) , 0.5 ) ;
548597 assert_eq ! ( t. elapsed_secs_f64( ) , 0.5 ) ;
549- assert ! ( t. finished ( ) ) ;
598+ assert ! ( t. is_finished ( ) ) ;
550599 assert ! ( t. just_finished( ) ) ;
551600 t. tick ( Duration :: from_secs_f32 ( 0.2 ) ) ;
552601 assert_eq ! ( t. times_finished_this_tick( ) , 0 ) ;
@@ -607,12 +656,12 @@ mod tests {
607656
608657 t. tick ( Duration :: from_secs_f32 ( 10.0 ) ) ;
609658 assert ! ( t. just_finished( ) ) ;
610- assert ! ( t. finished ( ) ) ;
659+ assert ! ( t. is_finished ( ) ) ;
611660 // A paused timer should change just_finished to false after a tick
612661 t. pause ( ) ;
613662 t. tick ( Duration :: from_secs_f32 ( 5.0 ) ) ;
614663 assert ! ( !t. just_finished( ) ) ;
615- assert ! ( t. finished ( ) ) ;
664+ assert ! ( t. is_finished ( ) ) ;
616665 }
617666
618667 #[ test]
@@ -621,11 +670,11 @@ mod tests {
621670
622671 t. tick ( Duration :: from_secs_f32 ( 10.0 ) ) ;
623672 assert ! ( t. just_finished( ) ) ;
624- assert ! ( t. finished ( ) ) ;
673+ assert ! ( t. is_finished ( ) ) ;
625674 // A paused repeating timer should change finished and just_finished to false after a tick
626675 t. pause ( ) ;
627676 t. tick ( Duration :: from_secs_f32 ( 5.0 ) ) ;
628677 assert ! ( !t. just_finished( ) ) ;
629- assert ! ( !t. finished ( ) ) ;
678+ assert ! ( !t. is_finished ( ) ) ;
630679 }
631680}
0 commit comments