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

feat: Customise grid of NineTileBox #2495

Merged
merged 11 commits into from Apr 19, 2023

Conversation

projectitis
Copy link
Contributor

Description

Edit: Closed/re-created MR after rebase with latest changes on main.

The previous implementation of the NineTileBox calculates identically sized tiles in a 3x3 grid and does not allow the user to customise this. For example, a 60x60 pixel sprite will be cut into 20x20 pixel tiles. This MR allows the user to specify the sizes of the fixed-width and fixed-height rows and columns so that a completely custom grid is possible.

Example with the following sprite and custom grid sizes.
Note that the stretchable row and column are only 1 pixel wide/high in this example.

image

final dialogBubble = NineTileBox.withGrid(
  await Sprite.load(dialogSpriteName),
  leftColumnWidth: 5,
  rightColumnWidth: 4,
  topRowHeight: 4,
  bottomRowHeight: 7,
);

image

Checklist

  • I have followed the [Contributor Guide] when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Please note the visibility of NineTileBox.center (was private) for testing purposes. Added the @visibleForTesting decorator.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Closes #2490

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few comments.
Remember that you don't have to create a new PR to update it with new code, you can just continue to push to the same branch and it will automatically update.

packages/flame/test/nine_tile_box_test.dart Outdated Show resolved Hide resolved
packages/flame/test/nine_tile_box_test.dart Outdated Show resolved Hide resolved
packages/flame/test/nine_tile_box_test.dart Outdated Show resolved Hide resolved
packages/flame/test/nine_tile_box_test.dart Outdated Show resolved Hide resolved
@projectitis
Copy link
Contributor Author

Thanks for the review. Happy to make further changes/improvements.

What's the policy with accepting conversations - do you prefer that the reviewer closes their own conversations, or the contributor closes them once they are addressed in a PR?

I decided to close/redo the previous PR because I was already up to 5 commits. I did this because some repo owners really prefer clean PRs - even though the PR can be squashed before it is merged.

@spydon
Copy link
Member

spydon commented Apr 14, 2023

Thanks for the review. Happy to make further changes/improvements.

Great! I'll ping the others in the team so that they can review too. :)

What's the policy with accepting conversations - do you prefer that the reviewer closes their own conversations, or the contributor closes them once they are addressed in a PR?

Usually the reviewer closes them when they have verified that they are done.

I decided to close/redo the previous PR because I was already up to 5 commits. I did this because some repo owners really prefer clean PRs - even though the PR can be squashed before it is merged.

The amount of commits doesn't matter here because they are squashed into one commit when we merge.

projectitis and others added 3 commits April 15, 2023 10:39
Co-authored-by: Erick <erickzanardoo@gmail.com>
Comment on lines 57 to 60
double leftColumnWidth = 0.0,
double rightColumnWidth = 0.0,
double topRowHeight = 0.0,
double bottomRowHeight = 0.0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about dropping Row and Column from the names? Would it be less clear what they mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I had just left, right, top, bottom but that was confusing as the values here don't work the same as a regular Rect - but I think _Width, _Height will be ok.

What is your preference?

  • leftWidth, rightWidth, topHeight, bottomHeight
  • leftSize, rightSize, topSize, bottomSize

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the top one is slightly clearer, especially since we usually use size described by a Vector2 that represents both width and height.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would border work? columns and rows made me a little confused here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So leftBorderWidth etc? Could work, hard do come up with something super clear here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, border is confusing to me because it suggests it is outside (or surrounds) the NineTileBox. I prefer leftWidth, topHeight etc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with that then, I think those are fine.
Can you add them to the dartdocs too, explaining what each of them do and it'll be even clearer?
You can refer to arguments in the dartdoc with [leftBorderWidth] etc.

Copy link
Member

@renancaraujo renancaraujo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made one of our best APIs even better.

Comment on lines 57 to 60
double leftColumnWidth = 0.0,
double rightColumnWidth = 0.0,
double topRowHeight = 0.0,
double bottomRowHeight = 0.0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would border work? columns and rows made me a little confused here.

Copy link
Member

@erickzanardo erickzanardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, on minor suggestion

final sprite = Sprite(await loadImage('speech-bubble-1.png'));
final nineTileBox = NineTileBox(sprite);

expect(nineTileBox.tileSize, 30);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use matchers here instead of just putting the raw values

Suggested change
expect(nineTileBox.tileSize, 30);
expect(nineTileBox.tileSize, equals(30));

The same suggestion to the other places in this PR

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@spydon
Copy link
Member

spydon commented Apr 19, 2023

Just needs a formatting fix, you can run melos format and it'll sort it out for you.

@spydon spydon enabled auto-merge (squash) April 19, 2023 07:56
@spydon spydon merged commit a25b0a0 into flame-engine:main Apr 19, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set grid on NineTileBox
4 participants