Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Being able to add more time to a Timer #2357

Closed
Skyost opened this issue Feb 21, 2023 · 2 comments · Fixed by #2358
Closed

Being able to add more time to a Timer #2357

Skyost opened this issue Feb 21, 2023 · 2 comments · Fixed by #2358
Assignees

Comments

@Skyost
Copy link
Contributor

Skyost commented Feb 21, 2023

What could be improved

Currently, it isn't possible to change the elapsed time of a Timer. It's also not possible to change the limit.
I think this could easily be improved by removing the final keyword of the limit variable in the Timer class.

Why should this be improved

I use timers in my game as a countdown before the player dies in a level. But some objects should act as bonus that give some time to the player.

What I've done so far is that I've created a MutableTimer class that allows me to change the limit :

/// A [Timer] that allows to change its limit.
class MutableTimer extends Timer {
  /// The current timer limit.
  double _limit;

  /// Creates a new mutable timer instance.
  MutableTimer(
    double limit, {
    super.onTick,
    super.repeat,
    super.autoStart,
  })  : _limit = limit,
        super(limit);

  @override
  double get limit => _limit;

  /// Changes the current timer limit.
  set limit(double limit) => _limit = limit;
}

but it really is a workaround.

Any risks?

Not to my knowledge.

@spydon
Copy link
Member

spydon commented Feb 21, 2023

Sounds reasonable, I don't see any reason for keeping it final.
Should I assign you to the issue?

@Skyost
Copy link
Contributor Author

Skyost commented Feb 21, 2023

@spydon Sure, I can make a PR if you want 🙂

spydon pushed a commit that referenced this issue Feb 21, 2023
As stated in #2357, the field `limit` of the class `Timer` had no reason
to be final. By removing this keyword, we make it possible to add more
time to a given `Timer` object (so that they can be used as a countdown
for example).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants