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: Size for SpriteComponent.fromImage should be nullable #3054

Merged
merged 5 commits into from
Mar 1, 2024
Merged

fix: Size for SpriteComponent.fromImage should be nullable #3054

merged 5 commits into from
Mar 1, 2024

Conversation

fa-fifi
Copy link
Contributor

@fa-fifi fa-fifi commented Feb 28, 2024

Description

I received an assertion error after I set autoResize to true when I am using SpriteComponent.fromImage component. It's kinda weird for me that the message tells me "If size is set, autoResize should be false or size should be null when autoResize is true.'', but the thing is I never set the size for that image yet. Then, I check the code and I found out that the size will never be null anyway, so the autoresize should always be false.

In this PR, I just remove all the fallback value for size, so it would not give an assertion error when size is not being set yet while the autoresize is true.

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.

Breaking Change?

  • No, this PR is not a breaking change.

@@ -72,7 +71,6 @@ class SpriteComponent extends PositionComponent
srcPosition: srcPosition,
srcSize: srcSize,
),
autoResize: autoResize,
paint: paint,
position: position,
size: size ?? srcSize ?? image.size,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think SpriteComponent.fromImage should not explicitly set size as srcSize or image.size. So something like this should be enough.

Suggested change
size: size ?? srcSize ?? image.size,
size: size,

Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for that? Then it'll have a different behavior than the other constructor right? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not really. SpriteComponent.fromImage internally invokes the same constructor.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that makes a lot of sense then!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So... should I commit changes based on @ufrshubham's suggestion?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, please do

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup, commit that change and then autoResize can be left as it was earlier.

Copy link
Collaborator

@ufrshubham ufrshubham left a comment

Choose a reason for hiding this comment

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

@fa-fifi can you update the title and description of the PR to be inline with what it actually does. Also, some tests for SpriteComponent.fromImage would be good.

@fa-fifi fa-fifi changed the title fix: Remove unnecessary autoresize parameter fix: Size for SpriteComponent.fromImage should be nullable Feb 28, 2024
@fa-fifi
Copy link
Contributor Author

fa-fifi commented Feb 28, 2024

I have updated the title and the description for this PR. Feel free to edit them if you think they are not suitable since English is not my mother tongue.

There are some other stuff that I have to focus on rn, so I'll revisit this PR again in the next couple days to update the test cases for SpriteComponent.fromImage. You can help me with test cases if you want.

@spydon spydon enabled auto-merge (squash) March 1, 2024 20:50
@spydon spydon merged commit 2ed71a3 into flame-engine:main Mar 1, 2024
8 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.

None yet

3 participants