refactor: simplified GoogleLetter

pull/172/head
alestiago 4 years ago
parent 77aa2e9426
commit 038b15a0d2

@ -4,17 +4,37 @@ import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
/// Circular sensor that represents "Google" letter.
class GoogleLetter extends BodyComponent with InitialPosition { class GoogleLetter extends BodyComponent with InitialPosition {
late final _GoogleLetterSprite _sprite; /// Circular sensor that represents the first letter "G" in "Google".
GoogleLetter.letter1() : _sprite = _GoogleLetterSprite.letter1();
void activate() => _sprite.activate(); /// Circular sensor that represents the first letter "O" in "Google".
GoogleLetter.letter2() : _sprite = _GoogleLetterSprite.letter2();
void deactivate() => _sprite.deactivate(); /// Circular sensor that represents the second letter "O" in "Google".
GoogleLetter.letter3() : _sprite = _GoogleLetterSprite.letter3();
/// Circular sensor that represents the letter "L" in "Google".
GoogleLetter.letter4() : _sprite = _GoogleLetterSprite.letter4();
/// Circular sensor that represents the letter "E" in "Google".
GoogleLetter.letter5() : _sprite = _GoogleLetterSprite.letter5();
final _GoogleLetterSprite _sprite;
/// Activates this [GoogleLetter].
// TODO(alestiago): Improve doc comment once activate and deactivate
// are implemented with the actual assets.
Future<void> activate() async => _sprite.activate();
/// Deactivates this [GoogleLetter].
Future<void> deactivate() async => _sprite.deactivate();
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await add(_sprite = _GoogleLetterSprite.letter1()); await add(_sprite);
} }
@override @override
@ -52,18 +72,14 @@ class _GoogleLetterSprite extends SpriteComponent with HasGameRef {
// TODO(alestiago): Correctly implement activate and deactivate once the // TODO(alestiago): Correctly implement activate and deactivate once the
// assets are provided. // assets are provided.
Future<void> activate() async { Future<void> activate() async {
const color = Colors.green;
tint(color);
await add( await add(
_GoogleLetterActivationEffect(color: color), _GoogleLetterColorEffect(color: Colors.green),
); );
} }
Future<void> deactivate() async { Future<void> deactivate() async {
const color = Colors.red;
tint(color);
await add( await add(
_GoogleLetterActivationEffect(color: color), _GoogleLetterColorEffect(color: Colors.red),
); );
} }
@ -73,13 +89,14 @@ class _GoogleLetterSprite extends SpriteComponent with HasGameRef {
final sprite = await gameRef.loadSprite(_spritePath); final sprite = await gameRef.loadSprite(_spritePath);
this.sprite = sprite; this.sprite = sprite;
// TODO(alestiago): Size correctly once the assets are provided.
size = sprite.originalSize / 5; size = sprite.originalSize / 5;
anchor = Anchor.center; anchor = Anchor.center;
} }
} }
class _GoogleLetterActivationEffect extends ColorEffect { class _GoogleLetterColorEffect extends ColorEffect {
_GoogleLetterActivationEffect({ _GoogleLetterColorEffect({
required Color color, required Color color,
}) : super( }) : super(
color, color,

Loading…
Cancel
Save