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

Int custom(?) property in Tmx file read as float #80

Open
jlaumonier opened this issue Dec 7, 2024 · 2 comments
Open

Int custom(?) property in Tmx file read as float #80

jlaumonier opened this issue Dec 7, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@jlaumonier
Copy link

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 :

        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

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

@Cleptomania
Copy link
Member

Cleptomania commented Dec 9, 2024

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.

@Cleptomania Cleptomania added bug Something isn't working good first issue Good for newcomers labels Dec 9, 2024
@benjamin-kirkbride
Copy link
Collaborator

benjamin-kirkbride commented Dec 9, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants