You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I read an int custom property from a TMX file, the result type is float. Is there any reason for that ? I could cast in int in my code but in that case, what the point of setting an int type in Tiled ?
Possible solution
It seems that the following lines in parser/tmx/properties.py cause the problem :
elif type_ == "int" or type_ == "float":
value = float(value_)
I think they could be replaced by
elif type_ == "int":
value = int(value_)
elif type_ == "float":
value = float(value_)
With my few tests, it seems to resolve the problem but one other modification could be useful also in pytiled_parser/properties.py
I’d guess we did this because for most purposes a float in Python can represent an int, but this isn’t technically always true and can lead to problems in some specific edge cases, so we should probably change this.
I’ll probably be working on a 2.2.8 release within the next week or so I should be able to get this into.
If someone wants to submit a PR before I get to it, feel free to do so.
Can we check what Tiled itself does if you try to put a float into an int
property?
This may have been something we did to get around Tiled not actually
enforcing the more narrow type.
On Mon, Dec 9, 2024, 9:25 AM Darren Eberly ***@***.***> wrote:
I’d guess we did this because for most purposes a float in Python can
represent an int, but this isn’t technically always true and can lead to
problems in some specific edge cases, so we should probably change this.
I’ll probably be working on a 2.2.8 release within the next week or so I
should be able to get this into.
—
Reply to this email directly, view it on GitHub
<#80 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZXWBXHIQAVKDSVD5Y44N32EWR6PAVCNFSM6AAAAABTGKWBWCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMRYGEYDMNRQGA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
Problem
For pytiled_parser v.2.2.7,
When I read an int custom property from a TMX file, the result type is float. Is there any reason for that ? I could cast in int in my code but in that case, what the point of setting an int type in Tiled ?
Possible solution
It seems that the following lines in parser/tmx/properties.py cause the problem :
I think they could be replaced by
With my few tests, it seems to resolve the problem but one other modification could be useful also in pytiled_parser/properties.py
Property = Union[float, Path, str, bool, Color]
->Property = Union[float, Path, str, bool, Color, int]
I did not test for Json format.
Thanks for your library
The text was updated successfully, but these errors were encountered: