Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make debugCoordinatesPrecision into a variable instead of a getter #2713

Merged
merged 2 commits into from
Sep 8, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/flame/lib/src/components/core/component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ class Component {
/// How many decimal digits to print when displaying coordinates in the
/// debug mode. Setting this to null will suppress all coordinates from
/// the output.
int? get debugCoordinatesPrecision => 0;
int? debugCoordinatesPrecision = 0;

/// A key that can be used to identify this component in the tree.
///
Expand Down
41 changes: 35 additions & 6 deletions packages/flame/test/components/position_component_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ void main() {
..position = Vector2(23, 17)
..size = Vector2.all(10)
..anchor = Anchor.center
..precision = null;
..debugCoordinatesPrecision = null;
final canvas = MockCanvas();
component.renderTree(canvas);
expect(
Expand All @@ -932,6 +932,40 @@ void main() {
..translate(0, 0), // canvas.restore
);
});

test('render without coordinates and then render with coordinates', () {
final component = _MyDebugComponent()
..position = Vector2(23, 17)
..size = Vector2.all(10)
..anchor = Anchor.center
..debugCoordinatesPrecision = null;
final withoutCoordinatesCanvas = MockCanvas();
component.renderTree(withoutCoordinatesCanvas);
expect(
withoutCoordinatesCanvas,
MockCanvas()
..translate(18, 12)
..drawRect(const Rect.fromLTWH(0, 0, 10, 10))
..drawLine(const Offset(5, 3), const Offset(5, 7))
..drawLine(const Offset(3, 5), const Offset(7, 5))
..translate(0, 0), // canvas.restore
);

component.debugCoordinatesPrecision = 0;
final withCoordinatesCanvas = MockCanvas();
component.renderTree(withCoordinatesCanvas);
expect(
withCoordinatesCanvas,
MockCanvas()
..translate(18, 12)
..drawRect(const Rect.fromLTWH(0, 0, 10, 10))
..drawLine(const Offset(5, 3), const Offset(5, 7))
..drawLine(const Offset(3, 5), const Offset(7, 5))
..drawParagraph(null, const Offset(-30, -15))
..drawParagraph(null, const Offset(-20, 10))
..translate(0, 0), // canvas.restore
);
});
});

group('Bounding rectangle', () {
Expand Down Expand Up @@ -1003,11 +1037,6 @@ void main() {
class _MyHitboxComponent extends PositionComponent with GestureHitboxes {}

class _MyDebugComponent extends PositionComponent {
int? precision = 0;

@override
bool get debugMode => true;

@override
int? get debugCoordinatesPrecision => precision;
}