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

SetTile will no longer throw a DuplicateKeyException #802

Merged

Conversation

stallratte
Copy link
Contributor

Optimo found a bug which was caused by the changes a made to the datastructure:

When trying to set a tile which already exists, a DuplicateKeyException is thrown. This is fixed now.

Because of the comment on the method:

sets the tile and updates its tileset. If you change a tiles gid to one in a different Tileset you must call this method or update the TmxLayerTile.tileset manually!

I realized that there were two supported ways to replace a tile before my change:

  1. Nez.Tiled.TmxLayer.SetTile
  2. Get the reference of a TmxLayerTile and directly change Gid and manually update the Tileset if the gid is in a different tileset

The second way is now no longer possible. Using the second way will lead to unwanted behaviour.

Directly changing the TmxLayerTile also made it possible to change the flip flags. I think that's an edge case but I don't want to strip down the functionality for the users of the framework.

To avoid unwanted behaviour, I made the Gid and Flags readonly to force the use of the SetTile-method.
To make it possible again to also change the flags, I added an overloaded SetTile-Method.

Please let me know if these changes are ok.

Best regards,
stallratte

@prime31 prime31 merged commit 01ee231 into prime31:master May 20, 2024
@stallratte stallratte deleted the bugfix/setTile_DuplicateKeyException branch May 22, 2024 17:59
jaschez pushed a commit to jaschez/Nez that referenced this pull request May 30, 2024
* SetTile will no longer throw a DuplicateKeyException

* removed redundant code; immediately return of gid is 0
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

2 participants