diff --git a/lib/character_themes/character_theme.dart b/lib/character_themes/character_theme.dart index d755a2c7..459ab69a 100644 --- a/lib/character_themes/character_theme.dart +++ b/lib/character_themes/character_theme.dart @@ -3,6 +3,9 @@ import 'package:flame/palette.dart'; /// {@template character_theme} /// Template for creating character themes. +/// +/// Any character specific game pieces should have a getter specified here so +/// their corresponding assets can be retrieved for the game. /// {@endtemplate} abstract class CharacterTheme extends Equatable { /// {@macro character_theme} diff --git a/lib/character_themes/cubit/theme_cubit.dart b/lib/character_themes/cubit/theme_cubit.dart new file mode 100644 index 00000000..ae60877e --- /dev/null +++ b/lib/character_themes/cubit/theme_cubit.dart @@ -0,0 +1,13 @@ +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:pinball/character_themes/character_themes.dart'; + +part 'theme_state.dart'; + +class ThemeCubit extends Cubit { + ThemeCubit() : super(const ThemeState(DashTheme())); + + void themeSelected(CharacterTheme theme) { + emit(ThemeState(theme)); + } +} diff --git a/lib/character_themes/cubit/theme_state.dart b/lib/character_themes/cubit/theme_state.dart new file mode 100644 index 00000000..de15b437 --- /dev/null +++ b/lib/character_themes/cubit/theme_state.dart @@ -0,0 +1,10 @@ +part of 'theme_cubit.dart'; + +class ThemeState extends Equatable { + const ThemeState(this.theme); + + final CharacterTheme theme; + + @override + List get props => [theme]; +} diff --git a/test/character_themes/cubit/theme_cubit_test.dart b/test/character_themes/cubit/theme_cubit_test.dart new file mode 100644 index 00000000..fda2b7cd --- /dev/null +++ b/test/character_themes/cubit/theme_cubit_test.dart @@ -0,0 +1,23 @@ +import 'package:bloc_test/bloc_test.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pinball/character_themes/character_themes.dart'; + +void main() { + group('ThemeCubit', () { + test('initial state has Dash theme', () { + final themeCubit = ThemeCubit(); + expect(themeCubit.state.theme, equals(const DashTheme())); + }); + + group('themeSelected', () { + blocTest( + 'emits selected theme', + build: ThemeCubit.new, + act: (bloc) => bloc.themeSelected(const SparkyTheme()), + expect: () => [ + const ThemeState(SparkyTheme()), + ], + ); + }); + }); +} diff --git a/test/character_themes/cubit/theme_state_test.dart b/test/character_themes/cubit/theme_state_test.dart new file mode 100644 index 00000000..0161dc10 --- /dev/null +++ b/test/character_themes/cubit/theme_state_test.dart @@ -0,0 +1,19 @@ +// ignore_for_file: prefer_const_constructors + +import 'package:flutter_test/flutter_test.dart'; +import 'package:pinball/character_themes/character_themes.dart'; + +void main() { + group('ThemeState', () { + test('can be instantiated', () { + expect(const ThemeState(DashTheme()), isNotNull); + }); + + test('supports value equality', () { + expect( + ThemeState(DashTheme()), + equals(const ThemeState(DashTheme())), + ); + }); + }); +}