mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-30 08:27:36 +08:00
chore: Update cicd.yml file on flame_3d to match main, rollback color changes (#3378)
Update cicd.yml file on flame_3d to match main. Since we finally updated main, we should require no difference whatsoever on this file anymore. This will require downgrading all the color changes, which is fine. This should never have been a part of flame_3d to begin with. Files were "untouched" by checking out the exact version as they are in main right now (will need to rebase flame_3d to main later). I had to add a couple more files because the files on main had dependencies on changes that are not yet rebased on flame_3d. These extra diffs should disappear when I do the final rebase.
This commit is contained in:
@ -127,7 +127,7 @@ class Trail extends Component {
|
||||
final path = _paths[i];
|
||||
final opacity = _opacities[i];
|
||||
if (opacity > 0) {
|
||||
_linePaint.color = _color.withValues(alpha: opacity);
|
||||
_linePaint.color = _color.withOpacity(opacity);
|
||||
_linePaint.strokeWidth = lineWidth * opacity;
|
||||
canvas.drawPath(path, _linePaint);
|
||||
}
|
||||
@ -216,11 +216,11 @@ class Star extends PositionComponent with DragCallbacks {
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
if (isDragged) {
|
||||
_paint.color = color.withValues(alpha: 0.5);
|
||||
_paint.color = color.withOpacity(0.5);
|
||||
canvas.drawPath(_path, _paint);
|
||||
canvas.drawPath(_path, _borderPaint);
|
||||
} else {
|
||||
_paint.color = color.withValues(alpha: 1);
|
||||
_paint.color = color.withOpacity(1);
|
||||
canvas.drawPath(_path, _shadowPaint);
|
||||
canvas.drawPath(_path, _paint);
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ class HoverTarget extends PositionComponent with HoverCallbacks {
|
||||
final _paint = Paint()
|
||||
..color = HSLColor.fromAHSL(1, _random.nextDouble() * 360, 1, 0.8)
|
||||
.toColor()
|
||||
.withValues(alpha: 0.5);
|
||||
.withOpacity(0.5);
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
@ -41,11 +41,11 @@ class HoverTarget extends PositionComponent with HoverCallbacks {
|
||||
|
||||
@override
|
||||
void onHoverEnter() {
|
||||
_paint.color = _paint.color.withValues(alpha: 1);
|
||||
_paint.color = _paint.color.withOpacity(1);
|
||||
}
|
||||
|
||||
@override
|
||||
void onHoverExit() {
|
||||
_paint.color = _paint.color.withValues(alpha: 0.5);
|
||||
_paint.color = _paint.color.withOpacity(0.5);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ class RayCastExample extends FlameGame with HasCollisionDetection {
|
||||
final velocity = 60;
|
||||
double get resetPosition => -canvasSize.y;
|
||||
|
||||
Paint paint = BasicPalette.red.withOpacity(0.6).paint();
|
||||
Paint paint = Paint()..color = Colors.red.withOpacity(0.6);
|
||||
|
||||
RaycastResult<ShapeHitbox>? result;
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class RayTraceExample extends FlameGame
|
||||
with HasCollisionDetection, TapDetector {
|
||||
Paint paint = BasicPalette.red.withOpacity(0.6).paint();
|
||||
Paint paint = Paint()..color = Colors.red.withOpacity(0.6);
|
||||
bool isClicked = false;
|
||||
|
||||
Vector2 get origin => canvasSize / 2;
|
||||
|
||||
@ -115,7 +115,7 @@ class ExpandingCircle extends Component {
|
||||
removeFromParent();
|
||||
} else {
|
||||
final opacity = 1 - radius / maxRadius;
|
||||
_paint.color = _baseColor.withValues(alpha: opacity);
|
||||
_paint.color = _baseColor.withOpacity(opacity);
|
||||
_paint.strokeWidth = _outerRadius - _innerRadius;
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ game.add(
|
||||
ParticleSystemComponent(
|
||||
particle: CircleParticle(
|
||||
radius: game.size.x / 2,
|
||||
paint: Paint()..color = Colors.red.withValues(alpha: .5),
|
||||
paint: Paint()..color = Colors.red.withOpacity(.5),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@ -31,7 +31,7 @@ class LapLine extends BodyComponent with ContactCallbacks {
|
||||
@override
|
||||
Body createBody() {
|
||||
paint.color = (isFinish ? GameColors.green.color : GameColors.green.color)
|
||||
..withValues(alpha: 0.5);
|
||||
..withOpacity(0.5);
|
||||
paint
|
||||
..style = PaintingStyle.fill
|
||||
..shader = Gradient.radial(
|
||||
|
||||
@ -20,7 +20,7 @@ class Trail extends Component with HasPaint {
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
paint
|
||||
..color = (tire.paint.color.withValues(alpha: 0.9))
|
||||
..color = (tire.paint.color.withOpacity(0.9))
|
||||
..strokeWidth = 1.0;
|
||||
}
|
||||
|
||||
|
||||
@ -147,7 +147,7 @@ class ExpandingCircle extends CircleComponent {
|
||||
removeFromParent();
|
||||
} else {
|
||||
final opacity = 1 - radius / maxRadius;
|
||||
paint.color = const Color(0xffffffff).withValues(alpha: opacity);
|
||||
paint.color = const Color(0xffffffff).withOpacity(opacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ class TextButton extends ButtonComponent {
|
||||
),
|
||||
buttonDown: RectangleComponent(
|
||||
size: Vector2(200, 100),
|
||||
paint: BasicPalette.orange.withOpacity(0.5).paint(),
|
||||
paint: Paint()..color = BasicPalette.orange.color.withOpacity(0.5),
|
||||
),
|
||||
children: [
|
||||
TextComponent(
|
||||
|
||||
@ -94,8 +94,8 @@ abstract class MyCollidable extends PositionComponent
|
||||
final Vector2 velocity;
|
||||
final delta = Vector2.zero();
|
||||
double angleDelta = 0;
|
||||
final Color _defaultColor = Colors.blue.withValues(alpha: 0.8);
|
||||
final Color _collisionColor = Colors.green.withValues(alpha: 0.8);
|
||||
final Color _defaultColor = Colors.blue.withOpacity(0.8);
|
||||
final Color _collisionColor = Colors.green.withOpacity(0.8);
|
||||
late final Paint _dragIndicatorPaint;
|
||||
final ScreenHitbox screenHitbox;
|
||||
ShapeHitbox? hitbox;
|
||||
@ -219,7 +219,7 @@ class CollidableCircle extends MyCollidable {
|
||||
class SnowmanPart extends CircleHitbox {
|
||||
@override
|
||||
final renderShape = true;
|
||||
final startColor = Colors.white.withValues(alpha: 0.8);
|
||||
final startColor = Colors.white.withOpacity(0.8);
|
||||
final Color hitColor;
|
||||
|
||||
SnowmanPart(double radius, Vector2 position, this.hitColor)
|
||||
@ -234,7 +234,7 @@ class SnowmanPart extends CircleHitbox {
|
||||
if (other.hitboxParent is ScreenHitbox) {
|
||||
paint.color = startColor;
|
||||
} else {
|
||||
paint.color = hitColor.withValues(alpha: 0.8);
|
||||
paint.color = hitColor.withOpacity(0.8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ around trying not to hit them.
|
||||
Ray2? ray;
|
||||
Ray2? reflection;
|
||||
Vector2 origin = Vector2(250, 100);
|
||||
Paint paint = Paint()..color = Colors.amber.withValues(alpha: 0.6);
|
||||
Paint paint = Paint()..color = Colors.amber.withOpacity(0.6);
|
||||
final speed = 100;
|
||||
final inertia = 3.0;
|
||||
final safetyDistance = 50;
|
||||
|
||||
@ -28,8 +28,8 @@ with with mouse.
|
||||
Paint tapPaint = Paint();
|
||||
|
||||
final _colorTween = ColorTween(
|
||||
begin: Colors.blue.withValues(alpha: 0.2),
|
||||
end: Colors.red.withValues(alpha: 0.2),
|
||||
begin: Colors.blue.withOpacity(0.2),
|
||||
end: Colors.red.withOpacity(0.2),
|
||||
);
|
||||
|
||||
static const numberOfRays = 2000;
|
||||
|
||||
@ -23,8 +23,8 @@ bounce on will appear.
|
||||
''';
|
||||
|
||||
final _colorTween = ColorTween(
|
||||
begin: Colors.amber.withValues(alpha: 1.0),
|
||||
end: Colors.lightBlueAccent.withValues(alpha: 1.0),
|
||||
begin: Colors.amber.withOpacity(1.0),
|
||||
end: Colors.lightBlueAccent.withOpacity(1.0),
|
||||
);
|
||||
final random = Random();
|
||||
Ray2? ray;
|
||||
|
||||
@ -106,13 +106,13 @@ class SelectableClass extends SpriteComponent {
|
||||
super.size,
|
||||
super.key,
|
||||
super.sprite,
|
||||
}) : super(paint: Paint()..color = Colors.white.withValues(alpha: 0.5));
|
||||
}) : super(paint: Paint()..color = Colors.white.withOpacity(0.5));
|
||||
|
||||
bool _selected = false;
|
||||
bool get selected => _selected;
|
||||
set selected(bool value) {
|
||||
_selected = value;
|
||||
paint = Paint()
|
||||
..color = value ? Colors.white : Colors.white.withValues(alpha: 0.5);
|
||||
..color = value ? Colors.white : Colors.white.withOpacity(0.5);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ class OpacityEffectExample extends FlameGame with TapDetector {
|
||||
|
||||
@override
|
||||
void onTap() {
|
||||
final opacity = sprite.paint.color.a;
|
||||
final opacity = sprite.paint.color.opacity;
|
||||
if (opacity >= 0.5) {
|
||||
sprite.add(OpacityEffect.fadeOut(EffectController(duration: 1)));
|
||||
} else {
|
||||
|
||||
@ -30,7 +30,7 @@ class TapCallbacksSquare extends RectangleComponent with TapCallbacks {
|
||||
position: position ?? Vector2.all(100),
|
||||
size: Vector2.all(100),
|
||||
paint: continuePropagation
|
||||
? (Paint()..color = Colors.green.withValues(alpha: 0.9))
|
||||
? (Paint()..color = Colors.green.withOpacity(0.9))
|
||||
: PaintExtension.random(withAlpha: 0.9, base: 100),
|
||||
);
|
||||
|
||||
|
||||
@ -432,9 +432,7 @@ class ParticlesExample extends FlameGame {
|
||||
renderer: (canvas, particle) {
|
||||
final paint = randomElement(paints);
|
||||
// Override the color to dynamically update opacity
|
||||
paint.color = paint.color.withValues(
|
||||
alpha: 1 - particle.progress,
|
||||
);
|
||||
paint.color = paint.color.withOpacity(1 - particle.progress);
|
||||
|
||||
canvas.drawCircle(
|
||||
Offset.zero,
|
||||
|
||||
@ -13,7 +13,7 @@ class ResizingRectangle extends RectangleComponent {
|
||||
void onGameResize(Vector2 size) {
|
||||
super.onGameResize(size);
|
||||
|
||||
this.size = size * 0.4;
|
||||
this.size = size * .4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -83,15 +83,12 @@ mixin HasPaint<T extends Object> on Component
|
||||
throw ArgumentError('Opacity needs to be between 0 and 1');
|
||||
}
|
||||
|
||||
setColor(
|
||||
getPaint(paintId).color.withValues(alpha: opacity),
|
||||
paintId: paintId,
|
||||
);
|
||||
setColor(getPaint(paintId).color.withOpacity(opacity), paintId: paintId);
|
||||
}
|
||||
|
||||
/// Returns the current opacity.
|
||||
double getOpacity({T? paintId}) {
|
||||
return getPaint(paintId).color.a;
|
||||
return getPaint(paintId).color.opacity;
|
||||
}
|
||||
|
||||
/// Changes the opacity of the paint.
|
||||
@ -103,6 +100,11 @@ mixin HasPaint<T extends Object> on Component
|
||||
setColor(getPaint(paintId).color.withAlpha(alpha), paintId: paintId);
|
||||
}
|
||||
|
||||
/// Returns the current opacity.
|
||||
int getAlpha({T? paintId}) {
|
||||
return getPaint(paintId).color.alpha;
|
||||
}
|
||||
|
||||
/// Shortcut for changing the color of the paint.
|
||||
void setColor(Color color, {T? paintId}) {
|
||||
getPaint(paintId).color = color;
|
||||
@ -116,13 +118,13 @@ mixin HasPaint<T extends Object> on Component
|
||||
}
|
||||
|
||||
@override
|
||||
double get opacity => paint.color.a;
|
||||
double get opacity => paint.color.opacity;
|
||||
|
||||
@override
|
||||
set opacity(double value) {
|
||||
paint.color = paint.color.withValues(alpha: value);
|
||||
paint.color = paint.color.withOpacity(value);
|
||||
for (final paint in _paints.values) {
|
||||
paint.color = paint.color.withValues(alpha: value);
|
||||
paint.color = paint.color.withOpacity(value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,7 +186,7 @@ class _MultiPaintOpacityProvider<T extends Object> implements OpacityProvider {
|
||||
];
|
||||
_layerOpacityRatios = target.paintLayersInternal
|
||||
?.map(
|
||||
(paint) => paint.color.a / maxOpacity,
|
||||
(paint) => paint.color.opacity / maxOpacity,
|
||||
)
|
||||
.toList(growable: false);
|
||||
}
|
||||
@ -204,7 +206,7 @@ class _MultiPaintOpacityProvider<T extends Object> implements OpacityProvider {
|
||||
}
|
||||
if (includeLayers) {
|
||||
target.paintLayersInternal?.forEach(
|
||||
(paint) => maxOpacity = max(paint.color.a, maxOpacity),
|
||||
(paint) => maxOpacity = max(paint.color.opacity, maxOpacity),
|
||||
);
|
||||
}
|
||||
|
||||
@ -224,7 +226,7 @@ class _MultiPaintOpacityProvider<T extends Object> implements OpacityProvider {
|
||||
for (var i = 0; i < (paintLayersInternal?.length ?? 0); ++i) {
|
||||
paintLayersInternal![i].color = paintLayersInternal[i]
|
||||
.color
|
||||
.withValues(alpha: value * _layerOpacityRatios![i]);
|
||||
.withOpacity(value * _layerOpacityRatios![i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,8 +43,8 @@ class ColorEffect extends ComponentEffect<HasPaint> {
|
||||
|
||||
@override
|
||||
void apply(double progress) {
|
||||
final currentColor = color.withValues(
|
||||
alpha: min(max(_tween.transform(progress), 0), 1),
|
||||
final currentColor = color.withOpacity(
|
||||
min(max(_tween.transform(progress), 0), 1),
|
||||
);
|
||||
target.tint(currentColor, paintId: paintId);
|
||||
}
|
||||
|
||||
@ -13,11 +13,11 @@ extension ColorExtension on Color {
|
||||
assert(amount >= 0 && amount <= 1);
|
||||
|
||||
final f = 1 - amount;
|
||||
return Color.from(
|
||||
alpha: a,
|
||||
red: r * f,
|
||||
green: g * f,
|
||||
blue: b * f,
|
||||
return Color.fromARGB(
|
||||
alpha,
|
||||
(red * f).round(),
|
||||
(green * f).round(),
|
||||
(blue * f).round(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -29,11 +29,11 @@ extension ColorExtension on Color {
|
||||
Color brighten(double amount) {
|
||||
assert(amount >= 0 && amount <= 1);
|
||||
|
||||
return Color.from(
|
||||
alpha: a,
|
||||
red: r + (1.0 - r) * amount,
|
||||
blue: b + (1.0 - b) * amount,
|
||||
green: g + (1.0 - g) * amount,
|
||||
return Color.fromARGB(
|
||||
alpha,
|
||||
red + ((255 - red) * amount).round(),
|
||||
green + ((255 - green) * amount).round(),
|
||||
blue + ((255 - blue) * amount).round(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -47,45 +47,48 @@ extension ImageExtension on Image {
|
||||
///
|
||||
/// The [amount] is a double value between 0 and 1.
|
||||
Future<Image> darken(double amount) async {
|
||||
return _transformColorsByAmount(
|
||||
amount,
|
||||
(color, amount) => color.darken(amount),
|
||||
);
|
||||
}
|
||||
|
||||
/// Change each pixel's color to be brighter and return a new [Image].
|
||||
///
|
||||
/// The [amount] is a double value between 0 and 1.
|
||||
Future<Image> brighten(double amount) async {
|
||||
return _transformColorsByAmount(
|
||||
amount,
|
||||
(color, amount) => color.brighten(amount),
|
||||
);
|
||||
}
|
||||
|
||||
Future<Image> _transformColorsByAmount(
|
||||
double amount,
|
||||
Color Function(Color, double) process,
|
||||
) async {
|
||||
assert(amount >= 0 && amount <= 1);
|
||||
|
||||
final pixelData = await pixelsInUint8();
|
||||
final newPixelData = Uint8List(pixelData.length);
|
||||
|
||||
for (var i = 0; i < pixelData.length; i += 4) {
|
||||
final originalColor = Color.fromARGB(
|
||||
final color = Color.fromARGB(
|
||||
pixelData[i + 3],
|
||||
pixelData[i + 0],
|
||||
pixelData[i + 1],
|
||||
pixelData[i + 2],
|
||||
);
|
||||
).darken(amount);
|
||||
|
||||
final color = process(originalColor, amount);
|
||||
newPixelData[i] = color.red;
|
||||
newPixelData[i + 1] = color.green;
|
||||
newPixelData[i + 2] = color.blue;
|
||||
newPixelData[i + 3] = color.alpha;
|
||||
}
|
||||
return fromPixels(newPixelData, width, height);
|
||||
}
|
||||
|
||||
newPixelData[i] = (255 * color.r).round();
|
||||
newPixelData[i + 1] = (255 * color.g).round();
|
||||
newPixelData[i + 2] = (255 * color.b).round();
|
||||
newPixelData[i + 3] = (255 * color.a).round();
|
||||
/// Change each pixel's color to be brighter and return a new [Image].
|
||||
///
|
||||
/// The [amount] is a double value between 0 and 1.
|
||||
Future<Image> brighten(double amount) async {
|
||||
assert(amount >= 0 && amount <= 1);
|
||||
|
||||
final pixelData = await pixelsInUint8();
|
||||
final newPixelData = Uint8List(pixelData.length);
|
||||
|
||||
for (var i = 0; i < pixelData.length; i += 4) {
|
||||
final color = Color.fromARGB(
|
||||
pixelData[i + 3],
|
||||
pixelData[i + 0],
|
||||
pixelData[i + 1],
|
||||
pixelData[i + 2],
|
||||
).brighten(amount);
|
||||
|
||||
newPixelData[i] = color.red;
|
||||
newPixelData[i + 1] = color.green;
|
||||
newPixelData[i + 2] = color.blue;
|
||||
newPixelData[i + 3] = color.alpha;
|
||||
}
|
||||
return fromPixels(newPixelData, width, height);
|
||||
}
|
||||
|
||||
@ -14,10 +14,8 @@ class ShadowProcessor extends LayerProcessor {
|
||||
double opacity = 0.9,
|
||||
Color color = const Color(0xFF000000),
|
||||
}) : _shadowPaint = Paint()
|
||||
..colorFilter = ColorFilter.mode(
|
||||
color.withValues(alpha: opacity),
|
||||
BlendMode.srcATop,
|
||||
);
|
||||
..colorFilter =
|
||||
ColorFilter.mode(color.withOpacity(opacity), BlendMode.srcATop);
|
||||
|
||||
@override
|
||||
void process(Picture pic, Canvas canvas) {
|
||||
|
||||
@ -7,10 +7,6 @@ class PaletteEntry {
|
||||
|
||||
const PaletteEntry(this.color);
|
||||
|
||||
PaletteEntry withOpacity(double opacity) {
|
||||
return PaletteEntry(color.withValues(alpha: opacity));
|
||||
}
|
||||
|
||||
PaletteEntry withAlpha(int alpha) {
|
||||
return PaletteEntry(color.withAlpha(alpha));
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
@ -1,7 +1,6 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame_test/flame_test.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
@ -171,7 +170,7 @@ void main() {
|
||||
final component = _MyComponent();
|
||||
component.makeTransparent();
|
||||
|
||||
expect(component.paint.color.a, 0);
|
||||
expect(component.paint.color.opacity, 0);
|
||||
},
|
||||
);
|
||||
|
||||
@ -183,7 +182,7 @@ void main() {
|
||||
component.makeTransparent(paintId: _MyComponentKeys.background);
|
||||
|
||||
expect(
|
||||
component.getPaint(_MyComponentKeys.background).color.a,
|
||||
component.getPaint(_MyComponentKeys.background).color.opacity,
|
||||
0,
|
||||
);
|
||||
},
|
||||
@ -196,7 +195,7 @@ void main() {
|
||||
component.makeTransparent();
|
||||
component.makeOpaque();
|
||||
|
||||
expect(component.paint.color.a, 1);
|
||||
expect(component.paint.color.opacity, 1);
|
||||
},
|
||||
);
|
||||
|
||||
@ -210,9 +209,9 @@ void main() {
|
||||
);
|
||||
component.makeOpaque(paintId: _MyComponentKeys.background);
|
||||
|
||||
expectDouble(
|
||||
component.getPaint(_MyComponentKeys.background).color.a,
|
||||
1.0,
|
||||
expect(
|
||||
component.getPaint(_MyComponentKeys.background).color.opacity,
|
||||
1,
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -223,7 +222,7 @@ void main() {
|
||||
final component = _MyComponent();
|
||||
component.setOpacity(0.2);
|
||||
|
||||
expectDouble(component.paint.color.a, 0.2);
|
||||
expect(component.paint.color.opacity, 0.2);
|
||||
},
|
||||
);
|
||||
|
||||
@ -234,8 +233,8 @@ void main() {
|
||||
component.setPaint(_MyComponentKeys.background, Paint());
|
||||
component.setOpacity(0.2, paintId: _MyComponentKeys.background);
|
||||
|
||||
expectDouble(
|
||||
component.getPaint(_MyComponentKeys.background).color.a,
|
||||
expect(
|
||||
component.getPaint(_MyComponentKeys.background).color.opacity,
|
||||
0.2,
|
||||
);
|
||||
},
|
||||
|
||||
@ -33,7 +33,7 @@ void main() {
|
||||
OpacityEffect.by(0.4, EffectController(duration: 1)),
|
||||
);
|
||||
game.update(0);
|
||||
expectDouble(component.getOpacity(), 0.2, epsilon: epsilon);
|
||||
expect(component.getOpacity(), 0.2);
|
||||
expect(component.children.length, 1);
|
||||
|
||||
game.update(0.5);
|
||||
@ -55,7 +55,7 @@ void main() {
|
||||
OpacityEffect.to(0.4, EffectController(duration: 1)),
|
||||
);
|
||||
game.update(0);
|
||||
expectDouble(component.getOpacity(), 0.2, epsilon: epsilon);
|
||||
expect(component.getOpacity(), 0.2);
|
||||
expect(component.children.length, 1);
|
||||
|
||||
game.update(0.5);
|
||||
@ -215,12 +215,12 @@ void main() {
|
||||
|
||||
game.update(1);
|
||||
|
||||
expect(component.getPaint('bluePaint').color.a, isZero);
|
||||
expect(component.getPaint('bluePaint').color.opacity, isZero);
|
||||
|
||||
// RGB components shouldn't be affected after opacity effect.
|
||||
expect(component.getPaint('bluePaint').color.b, 1.0);
|
||||
expect(component.getPaint('bluePaint').color.r, isZero);
|
||||
expect(component.getPaint('bluePaint').color.g, isZero);
|
||||
expect(component.getPaint('bluePaint').color.blue, 255);
|
||||
expect(component.getPaint('bluePaint').color.red, isZero);
|
||||
expect(component.getPaint('bluePaint').color.green, isZero);
|
||||
},
|
||||
);
|
||||
|
||||
@ -242,10 +242,10 @@ void main() {
|
||||
game.update(1);
|
||||
|
||||
// All paints should have the same opacity after the effect completes.
|
||||
expect(component.getPaint().color.a, isZero);
|
||||
expect(component.getPaint(_PaintTypes.paint1).color.a, isZero);
|
||||
expect(component.getPaint(_PaintTypes.paint2).color.a, isZero);
|
||||
expect(component.getPaint(_PaintTypes.paint3).color.a, isZero);
|
||||
expect(component.getPaint().color.opacity, isZero);
|
||||
expect(component.getPaint(_PaintTypes.paint1).color.opacity, isZero);
|
||||
expect(component.getPaint(_PaintTypes.paint2).color.opacity, isZero);
|
||||
expect(component.getPaint(_PaintTypes.paint3).color.opacity, isZero);
|
||||
},
|
||||
);
|
||||
|
||||
@ -263,17 +263,17 @@ void main() {
|
||||
..color = BasicPalette.green
|
||||
.paint()
|
||||
.color
|
||||
.withValues(alpha: redInitialOpacity),
|
||||
.withOpacity(redInitialOpacity),
|
||||
_PaintTypes.paint2: BasicPalette.green.paint()
|
||||
..color = BasicPalette.green
|
||||
.paint()
|
||||
.color
|
||||
.withValues(alpha: greenInitialOpacity),
|
||||
.withOpacity(greenInitialOpacity),
|
||||
_PaintTypes.paint3: BasicPalette.blue.paint()
|
||||
..color = BasicPalette.blue
|
||||
.paint()
|
||||
.color
|
||||
.withValues(alpha: blueInitialOpacity),
|
||||
.withOpacity(blueInitialOpacity),
|
||||
},
|
||||
);
|
||||
await game.ensureAdd(component);
|
||||
@ -289,15 +289,15 @@ void main() {
|
||||
game.update(1);
|
||||
|
||||
expectDouble(
|
||||
component.getPaint(_PaintTypes.paint1).color.a,
|
||||
component.getPaint(_PaintTypes.paint1).color.opacity,
|
||||
redInitialOpacity * targetOpacity,
|
||||
);
|
||||
expectDouble(
|
||||
component.getPaint(_PaintTypes.paint2).color.a,
|
||||
component.getPaint(_PaintTypes.paint2).color.opacity,
|
||||
greenInitialOpacity * targetOpacity,
|
||||
);
|
||||
expectDouble(
|
||||
component.getPaint(_PaintTypes.paint3).color.a,
|
||||
component.getPaint(_PaintTypes.paint3).color.opacity,
|
||||
blueInitialOpacity * targetOpacity,
|
||||
);
|
||||
},
|
||||
@ -317,17 +317,17 @@ void main() {
|
||||
..color = BasicPalette.green
|
||||
.paint()
|
||||
.color
|
||||
.withValues(alpha: redInitialOpacity),
|
||||
.withOpacity(redInitialOpacity),
|
||||
_PaintTypes.paint2: BasicPalette.green.paint()
|
||||
..color = BasicPalette.green
|
||||
.paint()
|
||||
.color
|
||||
.withValues(alpha: greenInitialOpacity),
|
||||
.withOpacity(greenInitialOpacity),
|
||||
_PaintTypes.paint3: BasicPalette.blue.paint()
|
||||
..color = BasicPalette.blue
|
||||
.paint()
|
||||
.color
|
||||
.withValues(alpha: blueInitialOpacity),
|
||||
.withOpacity(blueInitialOpacity),
|
||||
},
|
||||
);
|
||||
await game.ensureAdd(component);
|
||||
@ -344,17 +344,17 @@ void main() {
|
||||
game.update(1);
|
||||
|
||||
expectDouble(
|
||||
component.getPaint(_PaintTypes.paint1).color.a,
|
||||
component.getPaint(_PaintTypes.paint1).color.opacity,
|
||||
targetOpacity,
|
||||
);
|
||||
expectDouble(
|
||||
component.getPaint(_PaintTypes.paint2).color.a,
|
||||
component.getPaint(_PaintTypes.paint2).color.opacity,
|
||||
(greenInitialOpacity / redInitialOpacity) * targetOpacity,
|
||||
);
|
||||
|
||||
// Opacity of this paint shouldn't be changed.
|
||||
expectDouble(
|
||||
component.getPaint(_PaintTypes.paint3).color.a,
|
||||
component.getPaint(_PaintTypes.paint3).color.opacity,
|
||||
blueInitialOpacity,
|
||||
);
|
||||
},
|
||||
|
||||
@ -120,12 +120,11 @@ void main() {
|
||||
}
|
||||
|
||||
int _colorBit(int index, Color color) {
|
||||
final value = switch (index % 4) {
|
||||
0 => color.r,
|
||||
1 => color.g,
|
||||
2 => color.b,
|
||||
3 => color.a,
|
||||
return switch (index % 4) {
|
||||
0 => color.red,
|
||||
1 => color.green,
|
||||
2 => color.blue,
|
||||
3 => color.alpha,
|
||||
_ => throw UnimplementedError(),
|
||||
};
|
||||
return (255 * value).round();
|
||||
}
|
||||
|
||||
@ -46,8 +46,9 @@ void main() {
|
||||
// valid inputs are : ccc, CCC, #ccc, #CCC, #c1c1c1, #C1C1C1, c1c1c1,
|
||||
// C1C1C1
|
||||
final color = ColorExtension.random();
|
||||
|
||||
final sixHexColor = '${_hex2(color.r)}${_hex2(color.g)}${_hex2(color.b)}';
|
||||
final sixHexColor = color.red.toRadixString(16).padLeft(2, '0') +
|
||||
color.green.toRadixString(16).padLeft(2, '0') +
|
||||
color.blue.toRadixString(16).padLeft(2, '0');
|
||||
|
||||
// C1C1C1
|
||||
final sixUpperCaseColor = sixHexColor.toUpperCase();
|
||||
@ -80,8 +81,9 @@ void main() {
|
||||
);
|
||||
|
||||
// Let's generate a new color from only 3 digits
|
||||
final threeHexColor =
|
||||
'${_hex1(color.r)}${_hex1(color.g)}${_hex1(color.b)}';
|
||||
final threeHexColor = color.red.toRadixString(16).padLeft(1, '0')[0] +
|
||||
color.green.toRadixString(16).padLeft(1, '0')[0] +
|
||||
color.blue.toRadixString(16).padLeft(1, '0')[0];
|
||||
final threeDigitsColor = ColorExtension.fromRGBHexString(threeHexColor);
|
||||
|
||||
// CCC
|
||||
@ -125,8 +127,10 @@ void main() {
|
||||
// valid inputs are : fccc, FCCC, #fccc, #FCCC, #ffc1c1c1, #FFC1C1C1,
|
||||
// ffc1c1c1, FFC1C1C1
|
||||
var color = ColorExtension.random(rng: r);
|
||||
final sixHexColor = '${_hex2(color.a)}${_hex2(color.r)}'
|
||||
'${_hex2(color.g)}${_hex2(color.b)}';
|
||||
final sixHexColor = color.alpha.toRadixString(16).padLeft(2, '0') +
|
||||
color.red.toRadixString(16).padLeft(2, '0') +
|
||||
color.green.toRadixString(16).padLeft(2, '0') +
|
||||
color.blue.toRadixString(16).padLeft(2, '0');
|
||||
|
||||
// FFC1C1C1
|
||||
final sixUpperCaseColor = sixHexColor.toUpperCase();
|
||||
@ -159,8 +163,10 @@ void main() {
|
||||
);
|
||||
|
||||
// Let's generate a new color from only 3 digits
|
||||
final threeHexColor = '${_hex1(color.a)}${_hex1(color.r)}'
|
||||
'${_hex1(color.g)}${_hex1(color.b)}';
|
||||
final threeHexColor = color.alpha.toRadixString(16).padLeft(1, '0')[0] +
|
||||
color.red.toRadixString(16).padLeft(1, '0')[0] +
|
||||
color.green.toRadixString(16).padLeft(1, '0')[0] +
|
||||
color.blue.toRadixString(16).padLeft(1, '0')[0];
|
||||
color = ColorExtension.fromARGBHexString(threeHexColor);
|
||||
|
||||
// FCCC
|
||||
@ -207,18 +213,10 @@ void main() {
|
||||
// As explained in the documentation
|
||||
// object with the set alpha as [withAlpha]
|
||||
expect(
|
||||
paint.color.a,
|
||||
closeTo(color.a, 10e-6),
|
||||
paint.color.alpha,
|
||||
color.alpha,
|
||||
reason: 'alpha does not have the right value',
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
String _hex2(double v) {
|
||||
return (255 * v).round().toRadixString(16).padLeft(2, '0');
|
||||
}
|
||||
|
||||
String _hex1(double v) {
|
||||
return (255 * v).round().toRadixString(16).padLeft(1, '0')[0];
|
||||
}
|
||||
|
||||
@ -55,7 +55,6 @@ void main() {
|
||||
]);
|
||||
},
|
||||
goldenFile: '../_goldens/sprite_font_renderer_1.png',
|
||||
skip: true,
|
||||
);
|
||||
|
||||
testGolden(
|
||||
@ -117,7 +116,6 @@ void main() {
|
||||
},
|
||||
goldenFile: '../_goldens/sprite_font_renderer_2.png',
|
||||
size: Vector2(200, 140),
|
||||
skip: true,
|
||||
);
|
||||
|
||||
testGolden(
|
||||
@ -219,7 +217,6 @@ void main() {
|
||||
},
|
||||
goldenFile: '../_goldens/sprite_font_renderer_3.png',
|
||||
size: Vector2(200, 70),
|
||||
skip: true,
|
||||
);
|
||||
|
||||
testGolden(
|
||||
@ -266,7 +263,6 @@ void main() {
|
||||
},
|
||||
goldenFile: '../_goldens/sprite_font_renderer_4.png',
|
||||
size: Vector2(200, 130),
|
||||
skip: true,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@ -3,5 +3,10 @@ import 'dart:ui';
|
||||
|
||||
extension ColorExtension on Color {
|
||||
/// Returns a Float32List that represents the color as a vector.
|
||||
Float32List get storage => Float32List.fromList([a, r, g, b]);
|
||||
Float32List get storage => Float32List.fromList([
|
||||
opacity,
|
||||
red.toDouble() / 255,
|
||||
green.toDouble() / 255,
|
||||
blue.toDouble() / 255,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -11,7 +11,6 @@ class ColorTexture extends Texture {
|
||||
ColorTexture(Color color, {int width = 1, int height = 1})
|
||||
: super(
|
||||
Uint32List.fromList(
|
||||
// ignore: deprecated_member_use
|
||||
List.filled(width * height, color.value),
|
||||
).buffer.asByteData(),
|
||||
width: width,
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame/palette.dart';
|
||||
import 'package:flame_isolate_example/terrain/terrain.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Grass extends PositionComponent with Terrain {
|
||||
static final _color = Paint()..color = const Color(0xff567d46);
|
||||
static final _debugColor = BasicPalette.black.withOpacity(0.5).paint();
|
||||
static final _debugColor = Paint()..color = Colors.black.withOpacity(0.5);
|
||||
|
||||
late final _rect = size.toRect();
|
||||
late final _rect2 = Rect.fromCenter(
|
||||
|
||||
@ -16,9 +16,7 @@ class KawabungaSystem extends BaseSystem with UpdateSystem {
|
||||
final textComponent = entity.get<TextComponent>()!;
|
||||
final textRenderer = TextPaint(
|
||||
style: textComponent.style.copyWith(
|
||||
color: textComponent.style.color!.withValues(
|
||||
alpha: 1 - timer.percentage,
|
||||
),
|
||||
color: textComponent.style.color!.withOpacity(1 - timer.percentage),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@ -102,7 +102,6 @@ void main() {
|
||||
},
|
||||
size: Vector2(360, 216),
|
||||
goldenFile: 'goldens/sprite_fusion_render_test.png',
|
||||
skip: true,
|
||||
);
|
||||
|
||||
testGolden(
|
||||
@ -121,7 +120,6 @@ void main() {
|
||||
},
|
||||
size: Vector2(360, 216),
|
||||
goldenFile: 'goldens/sprite_fusion_position_test.png',
|
||||
skip: true,
|
||||
);
|
||||
|
||||
testGolden(
|
||||
@ -140,7 +138,6 @@ void main() {
|
||||
},
|
||||
size: Vector2(360, 216),
|
||||
goldenFile: 'goldens/sprite_fusion_anchor_test.png',
|
||||
skip: true,
|
||||
);
|
||||
|
||||
testGolden(
|
||||
@ -159,7 +156,6 @@ void main() {
|
||||
},
|
||||
size: Vector2(360, 216),
|
||||
goldenFile: 'goldens/sprite_fusion_scale_test.png',
|
||||
skip: true,
|
||||
);
|
||||
|
||||
testGolden(
|
||||
@ -178,7 +174,6 @@ void main() {
|
||||
},
|
||||
size: Vector2(360, 216),
|
||||
goldenFile: 'goldens/sprite_fusion_angle_test.png',
|
||||
skip: true,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 121 KiB After Width: | Height: | Size: 121 KiB |
@ -115,28 +115,24 @@ void main() {
|
||||
expect(atlas2.atlas!.isCloneOf(atlas2.atlas!), isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'packs complex maps with multiple images',
|
||||
() async {
|
||||
final component = await TiledComponent.load(
|
||||
'isometric_plain.tmx',
|
||||
Vector2(128, 74),
|
||||
bundle: bundle,
|
||||
images: Images(bundle: bundle),
|
||||
);
|
||||
test('packs complex maps with multiple images', () async {
|
||||
final component = await TiledComponent.load(
|
||||
'isometric_plain.tmx',
|
||||
Vector2(128, 74),
|
||||
bundle: bundle,
|
||||
images: Images(bundle: bundle),
|
||||
);
|
||||
|
||||
final atlas = TiledAtlas.atlasMap.values.first;
|
||||
expect(
|
||||
await imageToPng(atlas.atlas!),
|
||||
matchesGoldenFile('goldens/larger_atlas.png'),
|
||||
);
|
||||
expect(
|
||||
renderMapToPng(component),
|
||||
matchesGoldenFile('goldens/larger_atlas_component.png'),
|
||||
);
|
||||
},
|
||||
skip: true,
|
||||
);
|
||||
final atlas = TiledAtlas.atlasMap.values.first;
|
||||
expect(
|
||||
await imageToPng(atlas.atlas!),
|
||||
matchesGoldenFile('goldens/larger_atlas.png'),
|
||||
);
|
||||
expect(
|
||||
renderMapToPng(component),
|
||||
matchesGoldenFile('goldens/larger_atlas_component.png'),
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'packs complex maps with multiple images using a custom spacing',
|
||||
@ -162,45 +158,36 @@ void main() {
|
||||
),
|
||||
);
|
||||
},
|
||||
skip: true,
|
||||
);
|
||||
|
||||
test(
|
||||
'can ignore tilesets in the packing',
|
||||
() async {
|
||||
await TiledComponent.load(
|
||||
'isometric_plain.tmx',
|
||||
Vector2(128, 74),
|
||||
bundle: bundle,
|
||||
images: Images(bundle: bundle),
|
||||
tsxPackingFilter: (tileset) => tileset.name != 'isometric_plain_2',
|
||||
);
|
||||
test('can ignore tilesets in the packing', () async {
|
||||
await TiledComponent.load(
|
||||
'isometric_plain.tmx',
|
||||
Vector2(128, 74),
|
||||
bundle: bundle,
|
||||
images: Images(bundle: bundle),
|
||||
tsxPackingFilter: (tileset) => tileset.name != 'isometric_plain_2',
|
||||
);
|
||||
|
||||
final atlas = TiledAtlas.atlasMap.values.first;
|
||||
expect(
|
||||
await imageToPng(atlas.atlas!),
|
||||
matchesGoldenFile('goldens/larger_atlas_with_skipped_tileset.png'),
|
||||
);
|
||||
},
|
||||
skip: true,
|
||||
);
|
||||
final atlas = TiledAtlas.atlasMap.values.first;
|
||||
expect(
|
||||
await imageToPng(atlas.atlas!),
|
||||
matchesGoldenFile('goldens/larger_atlas_with_skipped_tileset.png'),
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'clearing cache',
|
||||
() async {
|
||||
await TiledAtlas.fromTiledMap(
|
||||
simpleMap,
|
||||
images: Images(bundle: bundle),
|
||||
);
|
||||
test('clearing cache', () async {
|
||||
await TiledAtlas.fromTiledMap(
|
||||
simpleMap,
|
||||
images: Images(bundle: bundle),
|
||||
);
|
||||
|
||||
expect(TiledAtlas.atlasMap.isNotEmpty, true);
|
||||
expect(TiledAtlas.atlasMap.isNotEmpty, true);
|
||||
|
||||
TiledAtlas.clearCache();
|
||||
TiledAtlas.clearCache();
|
||||
|
||||
expect(TiledAtlas.atlasMap.isEmpty, true);
|
||||
},
|
||||
skip: true,
|
||||
);
|
||||
expect(TiledAtlas.atlasMap.isEmpty, true);
|
||||
});
|
||||
});
|
||||
|
||||
group('Single tileset map', () {
|
||||
@ -220,44 +207,42 @@ void main() {
|
||||
});
|
||||
|
||||
test(
|
||||
'''Two maps with a same tileset but different tile alignment should be rendered differently''',
|
||||
() async {
|
||||
final components = await Future.wait([
|
||||
TiledComponent.load(
|
||||
'single_tile_map_1.tmx',
|
||||
Vector2(16, 16),
|
||||
bundle: bundle,
|
||||
images: Images(bundle: bundle),
|
||||
),
|
||||
TiledComponent.load(
|
||||
'single_tile_map_2.tmx',
|
||||
Vector2(16, 16),
|
||||
bundle: bundle,
|
||||
images: Images(bundle: bundle),
|
||||
),
|
||||
]);
|
||||
'''Two maps with a same tileset but different tile alignment should be rendered differently''',
|
||||
() async {
|
||||
final components = await Future.wait([
|
||||
TiledComponent.load(
|
||||
'single_tile_map_1.tmx',
|
||||
Vector2(16, 16),
|
||||
bundle: bundle,
|
||||
images: Images(bundle: bundle),
|
||||
),
|
||||
TiledComponent.load(
|
||||
'single_tile_map_2.tmx',
|
||||
Vector2(16, 16),
|
||||
bundle: bundle,
|
||||
images: Images(bundle: bundle),
|
||||
),
|
||||
]);
|
||||
|
||||
final atlas = TiledAtlas.atlasMap.values.first;
|
||||
final imageRendered_1 = renderMapToPng(components[0]);
|
||||
final imageRendered_2 = renderMapToPng(components[1]);
|
||||
final atlas = TiledAtlas.atlasMap.values.first;
|
||||
final imageRendered_1 = renderMapToPng(components[0]);
|
||||
final imageRendered_2 = renderMapToPng(components[1]);
|
||||
|
||||
expect(TiledAtlas.atlasMap.length, 1);
|
||||
expect(
|
||||
await imageToPng(atlas.atlas!),
|
||||
matchesGoldenFile('goldens/single_tile_atlas.png'),
|
||||
);
|
||||
expect(imageRendered_1, isNot(same(imageRendered_2)));
|
||||
expect(
|
||||
imageRendered_1,
|
||||
matchesGoldenFile('goldens/single_tile_map_1.png'),
|
||||
);
|
||||
expect(
|
||||
imageRendered_2,
|
||||
matchesGoldenFile('goldens/single_tile_map_2.png'),
|
||||
);
|
||||
},
|
||||
skip: true,
|
||||
);
|
||||
expect(TiledAtlas.atlasMap.length, 1);
|
||||
expect(
|
||||
await imageToPng(atlas.atlas!),
|
||||
matchesGoldenFile('goldens/single_tile_atlas.png'),
|
||||
);
|
||||
expect(imageRendered_1, isNot(same(imageRendered_2)));
|
||||
expect(
|
||||
imageRendered_1,
|
||||
matchesGoldenFile('goldens/single_tile_map_1.png'),
|
||||
);
|
||||
expect(
|
||||
imageRendered_2,
|
||||
matchesGoldenFile('goldens/single_tile_map_2.png'),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user