Navigation Menu

Skip to content

Commit

Permalink
feat: able to clear all overlays (#1536)
Browse files Browse the repository at this point in the history
* feat: able to clear all overlays

* feat: able to clear all overlays

Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
  • Loading branch information
wolfenrain and spydon committed Apr 12, 2022
1 parent 4f7a12e commit 7b15c9a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/flame/lib/src/game/mixins/game.dart
Expand Up @@ -302,6 +302,12 @@ mixin Game {
class ActiveOverlaysNotifier extends ChangeNotifier {
final Set<String> _activeOverlays = {};

/// Clear all active overlays.
void clear() {
value.clear();
notifyListeners();
}

/// Mark a, overlay to be rendered.
///
/// See also:
Expand Down
72 changes: 72 additions & 0 deletions packages/flame/test/game/active_overlays_notifier_test.dart
@@ -0,0 +1,72 @@
import 'package:flame/game.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('ActiveOverlaysNotifier', () {
test('can be constructed', () {
expect(ActiveOverlaysNotifier(), isNotNull);
});

late ActiveOverlaysNotifier notifier;

setUp(() {
notifier = ActiveOverlaysNotifier();
});

group('add', () {
test('can add an overlay', () {
final result = notifier.add('test');

expect(result, true);
expect(notifier.isActive('test'), true);
});

test('wont add same overlay', () {
notifier.add('test');
final result = notifier.add('test');

expect(result, false);
});
});

group('remove', () {
test('can remove an overlay', () {
notifier.add('test');

final result = notifier.remove('test');

expect(result, true);
expect(notifier.isActive('test'), false);
});

test('wont result in removal if there is nothing to remove', () {
final result = notifier.remove('test');

expect(result, false);
});
});

group('isActive', () {
test('is true when overlay is active', () {
notifier.add('test');
expect(notifier.isActive('test'), true);
});

test('is false when overlay is active', () {
expect(notifier.isActive('test'), false);
});
});

group('clear', () {
test('clears all overlays', () {
notifier.add('test1');
notifier.add('test2');

notifier.clear();

expect(notifier.isActive('test1'), false);
expect(notifier.isActive('test2'), false);
});
});
});
}

0 comments on commit 7b15c9a

Please sign in to comment.