Skip to content

feat: Make Tile return self on self-modifying functions for easier chaining #1284

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

Closed

Conversation

Yanrishatum
Copy link
Contributor

Makes the following h2d.Tile methods return self, to simplify chain calls:
setCenterRatio, flipX, flipY, setPosition, setSize, scaleToSize, scrollDiscrete.

Reasoning: Fairly often I need to create a Bitmap with particular Tile configuration (most often centered), leading to new Bitmap(Res.myTile.toTile().center()), however it's very limiting (only centering) and also creates unnecessary Tile clone. This change allows for easier chain-configuration of such one-off tile loads, i.e. Res.myTile.toTile().scaleToSize(32, 32).setCenterRatio(0, 0.5).flipX().

@ncannasse
Copy link
Member

We don't do that because in Tile, returning a tile value means it's a modified copy and not a self reference. So it's not correct to have methods that are doing side effects but also returning this, it creates confusion.

@ncannasse ncannasse closed this Apr 19, 2025
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.

2 participants