mirror of https://github.com/flutter/pinball.git
commit
95cf07f5b8
@ -1,27 +1,47 @@
|
|||||||
import 'package:flame/components.dart';
|
import 'package:flame/components.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:pinball/game/game.dart';
|
import 'package:pinball/game/game.dart';
|
||||||
|
import 'package:pinball/l10n/l10n.dart';
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
import 'package:pinball_ui/pinball_ui.dart';
|
import 'package:pinball_ui/pinball_ui.dart';
|
||||||
|
|
||||||
final _bodyTextPaint = TextPaint(
|
final _bodyTextPaint = TextPaint(
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 3,
|
fontSize: 1.8,
|
||||||
color: PinballColors.white,
|
color: PinballColors.white,
|
||||||
fontFamily: PinballFonts.pixeloidSans,
|
fontFamily: PinballFonts.pixeloidSans,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/// {@template initials_submission_failure_display}
|
/// {@template initials_submission_failure_display}
|
||||||
/// [Backbox] display for when a failure occurs during initials submission.
|
/// [Backbox] display for when a failure occurs during initials submission.
|
||||||
/// {@endtemplate}
|
/// {@endtemplate}
|
||||||
class InitialsSubmissionFailureDisplay extends TextComponent {
|
class InitialsSubmissionFailureDisplay extends Component {
|
||||||
|
/// {@macro initials_submission_failure_display}
|
||||||
|
InitialsSubmissionFailureDisplay({
|
||||||
|
required this.onDismissed,
|
||||||
|
});
|
||||||
|
|
||||||
|
final VoidCallback onDismissed;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onLoad() async {
|
Future<void> onLoad() async {
|
||||||
await super.onLoad();
|
final l10n = readProvider<AppLocalizations>();
|
||||||
position = Vector2(0, -10);
|
|
||||||
anchor = Anchor.center;
|
await addAll([
|
||||||
text = 'Failure!';
|
ErrorComponent.bold(
|
||||||
textRenderer = _bodyTextPaint;
|
label: l10n.initialsErrorTitle,
|
||||||
|
position: Vector2(0, -20),
|
||||||
|
),
|
||||||
|
TextComponent(
|
||||||
|
text: l10n.initialsErrorMessage,
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(0, -12),
|
||||||
|
textRenderer: _bodyTextPaint,
|
||||||
|
),
|
||||||
|
TimerComponent(period: 4, onTick: onDismissed),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:pinball/l10n/l10n.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
/// {@template leaderboard_failure_display}
|
||||||
|
/// Display showing an error message when the leaderboard couldn't be loaded
|
||||||
|
/// {@endtemplate}
|
||||||
|
class LeaderboardFailureDisplay extends Component {
|
||||||
|
/// {@macro leaderboard_failure_display}
|
||||||
|
LeaderboardFailureDisplay();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
final l10n = readProvider<AppLocalizations>();
|
||||||
|
await add(
|
||||||
|
ErrorComponent(
|
||||||
|
label: l10n.leaderboardErrorMessage,
|
||||||
|
position: Vector2(0, -18),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:pinball/game/components/backbox/displays/displays.dart';
|
||||||
|
import 'package:pinball/l10n/l10n.dart';
|
||||||
|
import 'package:pinball_components/gen/assets.gen.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
class _TestGame extends Forge2DGame {
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
images.prefix = '';
|
||||||
|
await images.loadAll(
|
||||||
|
[
|
||||||
|
Assets.images.errorBackground.keyName,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> pump(LeaderboardFailureDisplay component) {
|
||||||
|
return ensureAdd(
|
||||||
|
FlameProvider.value(
|
||||||
|
_MockAppLocalizations(),
|
||||||
|
children: [component],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MockAppLocalizations extends Mock implements AppLocalizations {
|
||||||
|
@override
|
||||||
|
String get leaderboardErrorMessage => 'Message';
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
group('LeaderboardFailureDisplay', () {
|
||||||
|
final flameTester = FlameTester(_TestGame.new);
|
||||||
|
|
||||||
|
flameTester.test('renders correctly', (game) async {
|
||||||
|
await game.pump(LeaderboardFailureDisplay());
|
||||||
|
|
||||||
|
expect(
|
||||||
|
game
|
||||||
|
.descendants()
|
||||||
|
.where(
|
||||||
|
(component) =>
|
||||||
|
component is TextComponent && component.text == 'Message',
|
||||||
|
)
|
||||||
|
.length,
|
||||||
|
equals(1),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue