From f3aaacb9bcfd8423bf3872180b81415ef1f2c74b Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Sat, 1 Oct 2022 15:16:46 +0200 Subject: [PATCH] chore: Remove deprecations for v1.4.0 (#1978) Just removes all the methods and classes that should be removed for v1.4.0 --- .github/workflows/cicd.yml | 3 +- .../flame/lib/src/game/overlay_manager.dart | 3 - packages/flame_bloc/lib/flame_bloc.dart | 2 - .../flame_bloc/lib/src/flame_bloc_game.dart | 143 ------------------ .../flame_bloc/test/flame_bloc_game_test.dart | 141 ----------------- 5 files changed, 2 insertions(+), 290 deletions(-) delete mode 100644 packages/flame_bloc/lib/src/flame_bloc_game.dart delete mode 100644 packages/flame_bloc/test/flame_bloc_game_test.dart diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 37fe9f2a9..414cec002 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -52,5 +52,6 @@ jobs: channel: 'stable' cache: true - uses: bluefireteam/melos-action@main - - uses: bluefireteam/spec-action@main + - run: melos run test # TODO(spydon): Remove once Spec is fixed. + #- uses: bluefireteam/spec-action@main # END TESTING STAGE diff --git a/packages/flame/lib/src/game/overlay_manager.dart b/packages/flame/lib/src/game/overlay_manager.dart index e0c92f6fc..4026cb105 100644 --- a/packages/flame/lib/src/game/overlay_manager.dart +++ b/packages/flame/lib/src/game/overlay_manager.dart @@ -19,9 +19,6 @@ class OverlayManager { return UnmodifiableListView(_activeOverlays); } - @Deprecated('Use .activeOverlays instead. Will be removed in 1.4.0') - Set get value => _activeOverlays.toSet(); - /// Returns if the given [overlayName] is active bool isActive(String overlayName) => _activeOverlays.contains(overlayName); diff --git a/packages/flame_bloc/lib/flame_bloc.dart b/packages/flame_bloc/lib/flame_bloc.dart index d8b117164..b5d121eaa 100644 --- a/packages/flame_bloc/lib/flame_bloc.dart +++ b/packages/flame_bloc/lib/flame_bloc.dart @@ -1,5 +1,3 @@ -export 'src/flame_bloc_game.dart'; - export 'src/flame_bloc_listenable.dart'; export 'src/flame_bloc_listener.dart'; export 'src/flame_bloc_provider.dart'; diff --git a/packages/flame_bloc/lib/src/flame_bloc_game.dart b/packages/flame_bloc/lib/src/flame_bloc_game.dart deleted file mode 100644 index 0304d68e5..000000000 --- a/packages/flame_bloc/lib/src/flame_bloc_game.dart +++ /dev/null @@ -1,143 +0,0 @@ -// ignore_for_file: deprecated_member_use_from_same_package - -import 'dart:async'; - -import 'package:flame/components.dart'; -import 'package:flame/game.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -/// Adds capabilities for a [Component] to listen and have access -/// to a [Bloc] state. -@Deprecated('Use FlameBlocProvider and FlameBlocListenable instead') -mixin BlocComponent, S> on Component { - StreamSubscription? _subscription; - - S? _state; - - /// The current state of the [Bloc] that this [Component] is listening to. - /// Flame keeps a copy of the state on the [Component] so this can be directly - /// accessed in both the [update] and the [render] method. - S? get state => _state; - - /// Makes this component subscribe to the Bloc changes. - /// Visible only for test purposes. - @visibleForTesting - void subscribe(FlameBloc game) { - final _bloc = game.read(); - _state = _bloc.state; - - _subscription = _bloc.stream.listen((newState) { - if (_state != newState) { - final _callNewState = listenWhen(_state, newState); - _state = newState; - - if (_callNewState) { - onNewState(newState); - } - } - }); - } - - /// Makes this component stop listening to the [Bloc] changes. - /// Visible only for test purposes. - @visibleForTesting - void unsubscribe() { - _subscription?.cancel(); - _subscription = null; - } - - /// Override this to make [onNewState] be called only when - /// a certain state change happens. - /// - /// Default implementation returns true. - bool listenWhen(S? previousState, S newState) => true; - - /// Listener called everytime a new state is emitted to this component. - /// - /// Default implementation is a no-op. - void onNewState(S state) {} - - @override - @mustCallSuper - void onMount() { - super.onMount(); - assert( - findGame()! is FlameBloc, - 'BlocComponent can only be added to a FlameBloc game', - ); - final game = findGame()! as FlameBloc; - if (game.isAttached) { - subscribe(game); - } else { - game.subscriptionQueue.add(this); - } - } - - @override - @mustCallSuper - void onRemove() { - super.onRemove(); - unsubscribe(); - } -} - -/// A mixin that enhances a [FlameGame] enabling features to receive -/// and emit changes to a [Bloc] state. -@Deprecated('Use FlameBlocProvider and FlameBlocListener instead') -mixin FlameBloc on FlameGame { - /// Contains a list of all of the [BlocComponent]s with an active - /// subscription. Only visible for testing. - @visibleForTesting - final List subscriptionQueue = []; - - @override - @mustCallSuper - void onAttach() { - _runSubscriptionQueue(); - } - - @override - @mustCallSuper - void onRemove() { - super.onRemove(); - _unsubscribe(); - } - - /// Convenience method for obtaining the nearest ancestor provider of type - /// [T]. - /// - /// This method will do a lookup in the tree for [T], so avoid calling this - /// inside the game loop methods like [update] and [render] to avoid - /// performance issues. - T read() { - final context = buildContext; - if (context == null) { - throw Exception('build context is not available yet'); - } - - return context.read(); - } - - void _runSubscriptionQueue() { - while (subscriptionQueue.isNotEmpty) { - final component = subscriptionQueue.removeAt(0); - component.subscribe(this); - } - } - - void _unsubscribe() { - children.whereType().forEach((element) { - element.unsubscribe(); - }); - } -} - -/// Provides a default, concrete implementation of a [FlameBloc] game. -@Deprecated('Use FlameBlocProvider and FlameBlocListener instead') -class FlameBlocGame extends FlameGame with FlameBloc { - /// FlameBlocGame constructor with an optional [Camera] as a parameter to - /// FlameGame. - @Deprecated('Use FlameBlocProvider and FlameBlocListener instead') - FlameBlocGame({super.camera}); -} diff --git a/packages/flame_bloc/test/flame_bloc_game_test.dart b/packages/flame_bloc/test/flame_bloc_game_test.dart deleted file mode 100644 index 59f027074..000000000 --- a/packages/flame_bloc/test/flame_bloc_game_test.dart +++ /dev/null @@ -1,141 +0,0 @@ -// ignore_for_file: deprecated_member_use_from_same_package - -import 'package:flame/components.dart'; -import 'package:flame_bloc/flame_bloc.dart'; -import 'package:flame_test/flame_test.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_test/flutter_test.dart'; - -enum InventoryState { - sword, - bow, -} - -class InventoryCubit extends Cubit { - InventoryCubit() : super(InventoryState.sword); - - void selectBow() { - emit(InventoryState.bow); - } - - void selectSword() { - emit(InventoryState.bow); - } -} - -class MyBlocGame extends FlameBlocGame {} - -class InventoryComponent extends Component - with BlocComponent {} - -class MockInventoryComponent extends Component - with BlocComponent { - int numSubscribeCalls = 0; - - @override - void subscribe(FlameBloc game) { - numSubscribeCalls++; - } -} - -void main() { - group('FlameBlocGame', () { - late InventoryCubit cubit; - - setUp(() { - cubit = InventoryCubit(); - }); - - final blocGame = FlameTester( - MyBlocGame.new, - pumpWidget: (gameWidget, tester) async { - await tester.pumpWidget( - BlocProvider.value( - value: cubit, - child: gameWidget, - ), - ); - }, - ); - - blocGame.testGameWidget( - 'can emit states', - verify: (game, tester) async { - game.read().selectBow(); - - expect(cubit.state, equals(InventoryState.bow)); - }, - ); - - blocGame.test( - 'read throws exception when game is not attached yet', - (game) { - expect(() => game.read(), throwsException); - }, - ); - - blocGame.test( - 'adds component to queue when is not attached', - (game) { - game.add(InventoryComponent()); - game.update(0); - - expect(game.subscriptionQueue.length, equals(1)); - }, - ); - - blocGame.test( - 'runs the queue when game is attached', - (game) { - final component = MockInventoryComponent(); - game.add(component); - game.update(0); - expect(game.subscriptionQueue.length, 1); - game.onAttach(); - - expect(component.numSubscribeCalls, 1); - }, - ); - - blocGame.testGameWidget( - 'init components with the initial state', - setUp: (game, _) async { - await game.ensureAdd(InventoryComponent()); - }, - verify: (game, tester) async { - final component = game.firstChild(); - expect(component?.state, equals(InventoryState.sword)); - }, - ); - - blocGame.testGameWidget( - 'Components can be removed', - setUp: (game, tester) async { - await game.ensureAdd(InventoryComponent()); - }, - verify: (game, tester) async { - expect(game.children.length, 1); - - final component = game.firstChild(); - expect(component, isNotNull); - - game.remove(component!); - game.update(0); - expect(game.children.length, 0); - }, - ); - - blocGame.testGameWidget( - 'components listen to changes', - setUp: (game, _) async { - await game.ensureAdd(InventoryComponent()); - }, - verify: (game, tester) async { - final component = game.firstChild(); - game.read().selectBow(); - - expect(component?.state, equals(InventoryState.sword)); - }, - ); - }); -}