mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-12 19:01:09 +08:00
Small fixes and nits to make null-safe simpler (#686)
This commit is contained in:
12
README.md
12
README.md
@@ -25,13 +25,13 @@ A minimalistic Flutter game engine.
|
||||
|
||||
## About 1.0.0
|
||||
|
||||
This is a release candidate for version 1.0.0 of Flame. This is not ready for production use and the documentation found here is not completely updated according to the code, also everything here can be changed before the full release.
|
||||
Our goal is to release v1 soon. We are periodically launching RCs (release candidates) as we evolve the code, and we are already quite happy with where we are (but there might still be further changes). Our documentation is still not completely updated to v1, and things are still open to change.
|
||||
|
||||
Use this version to get a preview of how the new Flame version will be and also to give the team feedback about the new structure and/or features.
|
||||
Please use this version to get a preview of the new Flame version and also to give the team feedback about the new structure and/or features.
|
||||
|
||||
Checkout the branches `develop-v0.x` and `master-v0.x` for the current last 0.x version. However no new updates will be added to v0 except for bugfixes.
|
||||
The `master` branch is the bleeding edge of the v1 migration. The `master-v0.x` branch is the latest v0 release (where we are still merging some patches and crucial fixes).
|
||||
|
||||
The current v1 release is `1.0.0-rc6` on pub. The last stable version so far is `0.29.0`. Feel free to choose the one that better suits your need.
|
||||
The current v1 release is <a title="Pub" href="https://pub.dartlang.org/packages/flame" ><img src="https://img.shields.io/pub/v/flame.svg?style=popout&include_prereleases" /></a> on pub. The latest stable version so far is <a title="Pub" href="https://pub.dartlang.org/packages/flame" ><img src="https://img.shields.io/pub/v/flame.svg?style=popout" /></a>. Feel free to choose the one that better suits your need.
|
||||
|
||||
---
|
||||
|
||||
@@ -99,13 +99,13 @@ You can also show on your repository that your game is made with Flame by using
|
||||
|
||||
## Contributing
|
||||
|
||||
__Warning__: We are working on bringing Flame to its first stable version, updates on `0.x` versions are frozen, except for bugs. If you want to contribute on that version, by sure that it is a bugfix. For contributions for the stable version, your PR must point to the `v1.0.0` branch and by sure to talk about your contribution to the team, which is accessible on [Discord](https://discord.gg/pxrBmy4).
|
||||
__Warning__: We are working on bringing Flame to its first stable version, updates on `0.x` versions are frozen, except for crucial bug fixes. If you want to contribute to that version, please be mindful of that, and use the `master-v0.x` branch. For contributions for v1, your PR must point to the `master` branch. If in doubt, make sure to talk about your contribution to the team, either via an issue or [Discord](https://discord.gg/pxrBmy4).
|
||||
|
||||
Any help is appreciated! Comments, suggestions, issues, PRs.
|
||||
|
||||
Have you found a bug or have a suggestion of how to enhance Flame, open an issue and we will take a look at it as soon as possible.
|
||||
|
||||
Do you want to contribute with a PR? PRs are always welcome, just be sure to create it from the `develop` branch and follow the [checklist](.github/pull_request_template.md) which will appear when you open it.
|
||||
Do you want to contribute with a PR? PRs are always welcome, just be sure to create it from the correct branch (see above) and follow the [checklist](.github/pull_request_template.md) which will appear when you open it.
|
||||
|
||||
## Getting started
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ dart_code_metrics:
|
||||
- test/**
|
||||
metrics:
|
||||
number-of-arguments: 8
|
||||
number-of-methods: 28
|
||||
number-of-methods: 32
|
||||
lines-of-executable-code: 200
|
||||
cyclomatic-complexity: 36
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ void main() {
|
||||
class MyGame extends BaseGame with MouseMovementDetector {
|
||||
static const speed = 200.0;
|
||||
|
||||
Vector2 position = Vector2(0, 0);
|
||||
Vector2 position = Vector2.zero();
|
||||
Vector2 target;
|
||||
|
||||
final Paint _blue = Paint()..color = const Color(0xFF0000FF);
|
||||
|
||||
@@ -15,14 +15,8 @@ void main() {
|
||||
class MyGame extends BaseGame with MultiTouchTapDetector {
|
||||
final _whitePaint = BasicPalette.white.paint;
|
||||
|
||||
Paint _paint;
|
||||
|
||||
final Map<int, Rect> _taps = {};
|
||||
|
||||
MyGame() {
|
||||
_paint = _whitePaint;
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapDown(int pointerId, TapDownDetails details) {
|
||||
_taps[pointerId] = Rect.fromLTWH(
|
||||
@@ -47,7 +41,7 @@ class MyGame extends BaseGame with MultiTouchTapDetector {
|
||||
void render(Canvas canvas) {
|
||||
super.render(canvas);
|
||||
_taps.values.forEach((rect) {
|
||||
canvas.drawRect(rect, _paint);
|
||||
canvas.drawRect(rect, _whitePaint);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,18 +17,12 @@ class MyGame extends BaseGame
|
||||
with MultiTouchTapDetector, MultiTouchDragDetector {
|
||||
final _whitePaint = BasicPalette.white.paint;
|
||||
|
||||
Paint _paint;
|
||||
|
||||
final Map<int, Rect> _taps = {};
|
||||
|
||||
Vector2 _start;
|
||||
Vector2 _end;
|
||||
Rect _panRect;
|
||||
|
||||
MyGame() {
|
||||
_paint = _whitePaint;
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapDown(int pointerId, TapDownDetails details) {
|
||||
_taps[pointerId] = Rect.fromLTWH(
|
||||
@@ -83,11 +77,11 @@ class MyGame extends BaseGame
|
||||
void render(Canvas canvas) {
|
||||
super.render(canvas);
|
||||
_taps.values.forEach((rect) {
|
||||
canvas.drawRect(rect, _paint);
|
||||
canvas.drawRect(rect, _whitePaint);
|
||||
});
|
||||
|
||||
if (_panRect != null) {
|
||||
canvas.drawRect(_panRect, _paint);
|
||||
canvas.drawRect(_panRect, _whitePaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ void main() {
|
||||
}
|
||||
|
||||
class TapableSquare extends PositionComponent with Tapable {
|
||||
Paint _randomPaint() {
|
||||
static Paint _randomPaint() {
|
||||
final rng = math.Random();
|
||||
final color = Color.fromRGBO(
|
||||
rng.nextInt(256),
|
||||
@@ -31,10 +31,9 @@ class TapableSquare extends PositionComponent with Tapable {
|
||||
return PaletteEntry(color).paint;
|
||||
}
|
||||
|
||||
Paint currentPaint;
|
||||
final Paint _paint = _randomPaint();
|
||||
|
||||
TapableSquare({Vector2 position}) {
|
||||
currentPaint = _randomPaint();
|
||||
size = Vector2.all(100);
|
||||
this.position = position ?? Vector2.all(100);
|
||||
}
|
||||
@@ -42,7 +41,7 @@ class TapableSquare extends PositionComponent with Tapable {
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
super.render(canvas);
|
||||
canvas.drawRect(size.toRect(), currentPaint);
|
||||
canvas.drawRect(size.toRect(), _paint);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -14,8 +14,6 @@ dependencies:
|
||||
flame:
|
||||
path: ../../../
|
||||
|
||||
cupertino_icons: ^0.1.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
@@ -14,8 +14,6 @@ dependencies:
|
||||
flame:
|
||||
path: ../../../
|
||||
|
||||
cupertino_icons: ^0.1.3
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
@@ -37,17 +37,14 @@ class MyGame extends BaseGame {
|
||||
/// Defines the lifespan of all the particles in these examples
|
||||
final sceneDuration = const Duration(seconds: 1);
|
||||
|
||||
Vector2 cellSize;
|
||||
Vector2 halfCellSize;
|
||||
Vector2 get cellSize => size / gridSize;
|
||||
Vector2 get halfCellSize => cellSize / 2;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await images.load('zap.png');
|
||||
await images.load('boom3.png');
|
||||
|
||||
cellSize = size / gridSize;
|
||||
halfCellSize = cellSize * .5;
|
||||
|
||||
// Spawn new particles every second
|
||||
Timer.periodic(sceneDuration, (_) => spawnParticles());
|
||||
}
|
||||
@@ -87,8 +84,7 @@ class MyGame extends BaseGame {
|
||||
final particle = particles.removeLast();
|
||||
final col = particles.length % gridSize;
|
||||
final row = (particles.length ~/ gridSize).toDouble();
|
||||
final cellCenter =
|
||||
(cellSize.clone()..multiply(Vector2(col, row))) + (cellSize * .5);
|
||||
final cellCenter = (cellSize..multiply(Vector2(col, row))) + halfCellSize;
|
||||
|
||||
add(
|
||||
// Bind all the particles to a [Component] update
|
||||
|
||||
@@ -65,7 +65,8 @@ class MyGame extends Game with TapDetector {
|
||||
|
||||
int elapsedSecs = 0;
|
||||
|
||||
MyGame() {
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
countdown = Timer(2);
|
||||
interval = Timer(
|
||||
1,
|
||||
|
||||
@@ -15,7 +15,6 @@ dependencies:
|
||||
path: ../../../
|
||||
dashbook: ^0.0.6
|
||||
|
||||
cupertino_icons: ^0.1.2
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
assets:
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
export 'joystick.dart';
|
||||
export 'joystick.dart';
|
||||
export 'src/anchor.dart';
|
||||
export 'src/components/base_component.dart';
|
||||
export 'src/components/component.dart';
|
||||
export 'src/components/isometric_tile_map_component.dart';
|
||||
export 'src/components/mixins/collidable.dart';
|
||||
export 'src/components/mixins/draggable.dart';
|
||||
export 'src/components/mixins/draggable.dart';
|
||||
export 'src/components/mixins/has_collidables.dart';
|
||||
export 'src/components/mixins/has_game_ref.dart';
|
||||
export 'src/components/mixins/has_game_ref.dart';
|
||||
export 'src/components/mixins/hitbox.dart';
|
||||
export 'src/components/mixins/hitbox.dart';
|
||||
export 'src/components/mixins/single_child_particle.dart';
|
||||
export 'src/components/mixins/single_child_particle.dart';
|
||||
export 'src/components/mixins/tapable.dart';
|
||||
export 'src/components/mixins/tapable.dart';
|
||||
export 'src/components/nine_tile_box_component.dart';
|
||||
export 'src/components/parallax_component.dart';
|
||||
@@ -28,4 +22,3 @@ export 'src/components/text_component.dart';
|
||||
export 'src/extensions/vector2.dart';
|
||||
export 'src/text_config.dart';
|
||||
export 'src/timer.dart';
|
||||
export 'src/timer.dart';
|
||||
|
||||
@@ -52,7 +52,7 @@ class Anchor {
|
||||
///
|
||||
/// This should only be used for serialization purposes.
|
||||
String get name {
|
||||
return _valueNames.containsKey(this) ? _valueNames[this] : 'Anchor($x, $y)';
|
||||
return _valueNames[this] ?? 'Anchor($x, $y)';
|
||||
}
|
||||
|
||||
/// Returns a string representation of this Anchor.
|
||||
@@ -86,9 +86,9 @@ class Anchor {
|
||||
return _valueNames.entries.singleWhere((e) => e.value == name).key;
|
||||
} else {
|
||||
final regexp = RegExp(r'^\Anchor\(([^,]+), ([^\)]+)\)');
|
||||
final matches = regexp.allMatches(name).first.group;
|
||||
assert(matches != null, 'Bad Anchor format');
|
||||
return Anchor(double.parse(matches(1)), double.parse(matches(2)));
|
||||
final matches = regexp.firstMatch(name)?.groups([1, 2]);
|
||||
assert(matches != null && matches.length == 2, 'Bad anchor format');
|
||||
return Anchor(double.parse(matches[0]), double.parse(matches[1]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,7 @@ class IsometricTileMapComponent extends PositionComponent {
|
||||
this.matrix, {
|
||||
this.destTileSize,
|
||||
Vector2 position,
|
||||
}) {
|
||||
this.position = position ?? Vector2.zero();
|
||||
}
|
||||
}) : super(position: position);
|
||||
|
||||
/// This is the size the tiles will be drawn (either original or overwritten).
|
||||
Vector2 get effectiveTileSize => destTileSize ?? tileset.srcSize;
|
||||
|
||||
@@ -55,8 +55,6 @@ class JoystickComponent extends JoystickController {
|
||||
void removeAction(int actionId) {
|
||||
final action = children
|
||||
.firstWhere((e) => e is JoystickAction && e.actionId == actionId);
|
||||
if (action != null) {
|
||||
removeChild(action);
|
||||
}
|
||||
removeChild(action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class SpriteAnimationWidget extends StatefulWidget {
|
||||
final bool playing;
|
||||
|
||||
const SpriteAnimationWidget({
|
||||
this.animation,
|
||||
@required this.animation,
|
||||
this.playing = true,
|
||||
this.anchor = Anchor.topLeft,
|
||||
});
|
||||
|
||||
@@ -42,7 +42,7 @@ class _ButtonState extends State<SpriteButton> {
|
||||
onTapUp: (_) {
|
||||
setState(() => _pressed = false);
|
||||
|
||||
widget.onPressed?.call();
|
||||
widget.onPressed.call();
|
||||
},
|
||||
child: Container(
|
||||
width: width,
|
||||
|
||||
@@ -19,5 +19,12 @@ void main() {
|
||||
expect(const Anchor(0.2, 0.2).toString(), 'Anchor(0.2, 0.2)');
|
||||
expect(Anchor.valueOf('Anchor(0.2, 0.2)'), const Anchor(0.2, 0.2));
|
||||
});
|
||||
|
||||
test('fail to parse invalid anchor', () async {
|
||||
expect(
|
||||
() => Anchor.valueOf('foobar'),
|
||||
throwsA(const TypeMatcher<AssertionError>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame/src/geometry/polygon.dart';
|
||||
import 'package:flame/geometry.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
class MyComponent extends PositionComponent {}
|
||||
|
||||
@@ -16,8 +16,12 @@ class MockCanvas extends Fake implements Canvas {
|
||||
@override
|
||||
void scale(double sx, [double sy]) {
|
||||
final ssx = _normalize(sx);
|
||||
final ssy = _normalize(sy);
|
||||
methodCalls.add('scale($ssx, $ssy)');
|
||||
if (sy == null) {
|
||||
methodCalls.add('scale($ssx)');
|
||||
} else {
|
||||
final ssy = _normalize(sy);
|
||||
methodCalls.add('scale($ssx, $ssy)');
|
||||
}
|
||||
}
|
||||
|
||||
double _normalize(double d) {
|
||||
|
||||
Reference in New Issue
Block a user