Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/flame/test/_goldens/camera_component_order_test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/flame/test/_goldens/clip_component_circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/flame/test/_goldens/clip_component_polygon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/flame/test/_goldens/clip_component_rect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/flame/test/_goldens/sprite_batch_test_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions packages/flame/test/camera/camera_component_test.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'dart:math';
import 'dart:ui' show PictureRecorder;
import 'dart:ui';

import 'package:flame/camera.dart';
import 'package:flame/components.dart';
import 'package:flame/experimental.dart';
import 'package:flame/extensions.dart';
import 'package:flame/palette.dart';
import 'package:flame/post_process.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart';

import 'camera_test_helpers.dart';

Expand Down Expand Up @@ -401,24 +401,24 @@ void main() {
CrossHair(
size: Vector2.all(28),
position: camera.viewport.size / 2 + Vector2.all(4),
color: Colors.teal,
color: BasicPalette.teal.color,
),
);
camera.viewfinder.add(
CrossHair(
size: Vector2.all(20),
position: Vector2(-2, 4),
color: Colors.white,
color: BasicPalette.white.color,
),
);
world.add(
CrossHair(size: Vector2.all(14), color: Colors.green),
CrossHair(size: Vector2.all(14), color: BasicPalette.green.color),
);
camera.viewport.add(
CrossHair(
size: Vector2.all(8),
position: camera.viewport.size / 2 + Vector2(4, -4),
color: Colors.red,
color: BasicPalette.red.color,
),
);
},
Expand All @@ -443,24 +443,24 @@ void main() {
CrossHair(
size: Vector2.all(28),
position: resolution / 2 + Vector2.all(4),
color: Colors.teal,
color: BasicPalette.teal.color,
),
);
camera.viewfinder.add(
CrossHair(
size: Vector2.all(20),
position: Vector2(0, 2),
color: Colors.white,
color: BasicPalette.white.color,
),
);
world.add(
CrossHair(size: Vector2.all(14), color: Colors.green),
CrossHair(size: Vector2.all(14), color: BasicPalette.green.color),
);
camera.viewport.add(
CrossHair(
size: Vector2.all(8),
position: resolution / 2 + Vector2(2, -2),
color: Colors.red,
color: BasicPalette.red.color,
),
);
},
Expand All @@ -485,24 +485,24 @@ void main() {
CrossHair(
size: Vector2.all(28),
position: resolution / 2 + Vector2.all(4),
color: Colors.teal,
color: BasicPalette.teal.color,
),
);
camera.viewfinder.add(
CrossHair(
size: Vector2.all(20),
position: Vector2(-2, 4),
color: Colors.white,
color: BasicPalette.white.color,
),
);
world.add(
CrossHair(size: Vector2.all(14), color: Colors.green),
CrossHair(size: Vector2.all(14), color: BasicPalette.green.color),
);
camera.viewport.add(
CrossHair(
size: Vector2.all(8),
position: resolution / 2 + Vector2(4, -4),
color: Colors.red,
color: BasicPalette.red.color,
),
);
},
Expand Down
4 changes: 2 additions & 2 deletions packages/flame/test/components/clip_component_test.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:flame/components.dart';
import 'package:flame/palette.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart';

class _Rectangle() extends RectangleComponent {
this
: super(
size: Vector2(200, 200),
anchor: Anchor.center,
paint: Paint()..color = Colors.blue,
paint: BasicPalette.blue.paint(),
);
}

Expand Down
31 changes: 16 additions & 15 deletions packages/flame/test/effects/color_effect_test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flame/components.dart';
import 'package:flame/effects.dart';
import 'package:flame/palette.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart';

class _PaintComponent() extends Component with HasPaint;

Expand All @@ -11,16 +11,17 @@ void main() {
testWithFlameGame('applies the correct color filter', (game) async {
final component = _PaintComponent();
await game.ensureAdd(component);
const color = Colors.red;
// has distinct components, so a swap fails
final color = BasicPalette.pink.color;
component.add(
ColorEffect(color, EffectController(duration: 1)),
);
game.update(0);
expect(
component.paint.colorFilter.toString(),
equals(
'ColorFilter.mode(Color(alpha: 0.0000, red: 0.9569, green: '
'0.2627, blue: 0.2118, colorSpace: ColorSpace.sRGB),'
'ColorFilter.mode(Color(alpha: 0.0000, red: 1.0000, green: '
'0.4118, blue: 0.7059, colorSpace: ColorSpace.sRGB),'
' BlendMode.srcATop)',
),
);
Expand All @@ -29,8 +30,8 @@ void main() {
expect(
component.paint.colorFilter.toString(),
equals(
'ColorFilter.mode(Color(alpha: 0.5000, red: 0.9569, green: '
'0.2627, blue: 0.2118, colorSpace: ColorSpace.sRGB), '
'ColorFilter.mode(Color(alpha: 0.5000, red: 1.0000, green: '
'0.4118, blue: 0.7059, colorSpace: ColorSpace.sRGB), '
'BlendMode.srcATop)',
),
);
Expand All @@ -43,7 +44,7 @@ void main() {
await game.ensureAdd(component);

final originalColorFilter = component.paint.colorFilter;
const color = Colors.red;
final color = BasicPalette.red.color;

final effect = ColorEffect(
color,
Expand Down Expand Up @@ -73,7 +74,7 @@ void main() {
await game.ensureAdd(component);

final originalColorFilter = component.paint.colorFilter;
const color = Colors.red;
final color = BasicPalette.red.color;

final effect = ColorEffect(
color,
Expand Down Expand Up @@ -103,7 +104,7 @@ void main() {
await game.ensureAdd(component);

final effect = ColorEffect(
Colors.red,
BasicPalette.red.color,
EffectController(duration: 1),
);
await component.ensureAdd(effect);
Expand All @@ -127,7 +128,7 @@ void main() {
final effect = ColorEffect(
opacityFrom: 1,
opacityTo: 0,
Colors.black,
BasicPalette.black.color,
ZigzagEffectController(
period: 1,
),
Expand All @@ -143,7 +144,7 @@ void main() {
test('Validates opacity values', () {
expect(
() => ColorEffect(
Colors.blue,
BasicPalette.blue.color,
EffectController(duration: 1),
opacityTo: 1.1,
),
Expand All @@ -152,7 +153,7 @@ void main() {

expect(
() => ColorEffect(
Colors.blue,
BasicPalette.blue.color,
EffectController(duration: 1),
opacityFrom: 255,
),
Expand All @@ -161,7 +162,7 @@ void main() {

expect(
() => ColorEffect(
Colors.blue,
BasicPalette.blue.color,
EffectController(duration: 1),
opacityTo: -254,
),
Expand All @@ -170,7 +171,7 @@ void main() {

expect(
() => ColorEffect(
Colors.blue,
BasicPalette.blue.color,
EffectController(duration: 1),
opacityFrom: -0.5,
),
Expand All @@ -179,7 +180,7 @@ void main() {

expect(
() => ColorEffect(
Colors.blue,
BasicPalette.blue.color,
EffectController(duration: 1),
opacityFrom: 0.1,
opacityTo: 0.9,
Expand Down
4 changes: 2 additions & 2 deletions packages/flame/test/extensions/image_extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'dart:typed_data';
import 'dart:ui';

import 'package:flame/extensions.dart';
import 'package:flame/palette.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart';

final _output = List.filled(8 * 8 * 4, 255);

Expand Down Expand Up @@ -120,7 +120,7 @@ void main() {
final recorder = PictureRecorder();
Canvas(recorder).drawRect(
const Rect.fromLTWH(0, 0, 100, 100),
Paint()..color = Colors.white,
BasicPalette.white.paint(),
);
final pic = recorder.endRecording();
final image = await pic.toImage(100, 100);
Expand Down
17 changes: 9 additions & 8 deletions packages/flame/test/sprite_batch_test.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:ui';

import 'package:flame/components.dart';
import 'package:flame/palette.dart';
import 'package:flame/sprite.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart' hide Image;
import 'package:mocktail/mocktail.dart';

import '_resources/load_image.dart';
Expand All @@ -24,17 +24,18 @@ void main() {
test('can replace the color of a batch', () {
final image = _MockImage();
final spriteBatch = SpriteBatch(image);
spriteBatch.add(source: Rect.zero, color: Colors.blue);
spriteBatch.add(source: Rect.zero, color: BasicPalette.blue.color);

spriteBatch.replace(0, color: Colors.red);
final red = BasicPalette.red.color;
spriteBatch.replace(0, color: red);

final batchItem = spriteBatch.getBatchItem(0);

/// Use .closeTo() to avoid floating point rounding errors.
expect(batchItem.paint.color.a, closeTo(Colors.red.a, 0.001));
expect(batchItem.paint.color.r, closeTo(Colors.red.r, 0.001));
expect(batchItem.paint.color.g, closeTo(Colors.red.g, 0.001));
expect(batchItem.paint.color.b, closeTo(Colors.red.b, 0.001));
expect(batchItem.paint.color.a, closeTo(red.a, 0.001));
expect(batchItem.paint.color.r, closeTo(red.r, 0.001));
expect(batchItem.paint.color.g, closeTo(red.g, 0.001));
expect(batchItem.paint.color.b, closeTo(red.b, 0.001));
});

test('can replace the source of a batch', () {
Expand Down Expand Up @@ -312,7 +313,7 @@ void main() {

spriteBatch.add(
source: source,
color: Colors.redAccent,
color: BasicPalette.red.color,
offset: Vector2.all(margin),
);

Expand Down
1 change: 0 additions & 1 deletion packages/flame_network_assets/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ dev_dependencies:
flame_lint: ^1.5.0-dev.1
flutter_test:
sdk: flutter
material_ui: ^1.0.0
mocktail: ^1.0.4
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:io';
import 'dart:ui';

import 'package:flame/palette.dart';
import 'package:flame_network_assets/flame_network_assets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart' hide Image;
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as path;

Expand Down Expand Up @@ -60,7 +60,7 @@ void main() {
final canvas = Canvas(recorder);
canvas.drawRect(
const Rect.fromLTWH(0, 0, 50, 50),
Paint()..color = Colors.pink,
BasicPalette.pink.paint(),
);
final picture = recorder.endRecording();
image = await picture.toImage(50, 50);
Expand Down
1 change: 0 additions & 1 deletion packages/flame_test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ dependencies:
dev_dependencies:
dartdoc: ^9.0.0
flame_lint: ^1.5.0-dev.1
material_ui: ^1.0.0
8 changes: 4 additions & 4 deletions packages/flame_test/test/golden_test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/palette.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart';

void main() {
group('Golden tests', () {
Expand All @@ -15,7 +15,7 @@ void main() {
CircleComponent(
radius: 10,
position: Vector2.all(100),
paint: Paint()..color = Colors.white,
paint: BasicPalette.white.paint(),
),
);
},
Expand All @@ -30,7 +30,7 @@ void main() {
testGolden(
'Same test but with testGolden',
(game, tester) async {
final paint = Paint()..color = Colors.white;
final paint = BasicPalette.white.paint();
game.add(
CircleComponent(radius: 10, position: Vector2.all(100), paint: paint),
);
Expand All @@ -41,7 +41,7 @@ void main() {
testGolden(
'Same test, but with smaller size',
(game, tester) async {
final paint = Paint()..color = Colors.white;
final paint = BasicPalette.white.paint();
game.add(
CircleComponent(radius: 10, position: Vector2.all(100), paint: paint),
);
Expand Down
Loading