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

Jsonformat #1868

Merged
merged 11 commits into from Jan 30, 2018

Conversation

Projects
None yet
3 participants
@saeedakhter
Contributor

saeedakhter commented Jan 29, 2018

Addresses issue #1585

This introduces a new json revision (version: 1.2) that is much easier to serialize and de-serialize. For an example of de-serializing the new format in Unity3d, see https://github.com/saeedakhter/TiledJsonUnity3d

Problem:
Tiles were serialized as a map with the tile ID as the key:

"tiles":
    {
     "0": { "image":"necro3_0\/5.png", "imageheight":32, "imagewidth":32 },
     "1": { "image":"necro3_0\/4.png", "imageheight":32, "imagewidth":32 }
    }

In Unity3d, this makes it difficult (impossible?) to use Unity3d's JSON deserialization:
https://docs.unity3d.com/Manual/JSONSerialization.html

Solution (this pull request):
Serialize tiles and properties as a list. If an ID is required, put it inside the list object. Example:

 "tiles":[
        {
         "terrain":[0, 2, 2, 2],
         "tile":0
        }, 
        {
         "properties":[
                {
                 "name":"Prefrab",
                 "type":"string",
                 "value":"Floor*"
                }, 
                {
                 "name":"SortingLayer",
                 "type":"string",
                 "value":"Floor"
                }],
         "terrain":[0, 0, 0, 0],
         "tile":1
        }, 

bjorn added some commits Jan 30, 2018

Reduced code duplication for reading tiles
The format is still mostly the same, so the code for reading all the tile
attributes can be shared.

@bjorn bjorn merged commit 1d9ca3c into bjorn:master Jan 30, 2018

0 of 2 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@bjorn

This comment has been minimized.

Owner

bjorn commented Jan 30, 2018

Thanks a lot for your work on this!

@bitinn

This comment has been minimized.

bitinn commented Feb 28, 2018

Thx for your good work @saeedakhter!

Just wondering @bjorn, does the snapshot build contain this change? I was writing a parser on C# for my specific use-case and realize it would have been much easier with this updated properties field instead of the old tileproperties as I just happen to heavily rely on tileset properties.

@bjorn

This comment has been minimized.

Owner

bjorn commented Feb 28, 2018

@bitinn Yes, the changes are included in the latest snapshot build. The JSON format documentation is also already updated, which means it's now actually time to host explicit "Tiled 1.1" documentation (probably as default) as well to avoid confusion.

@bitinn

This comment has been minimized.

bitinn commented Feb 28, 2018

@bjorn fantastic! and yeah I was reading the doc and realize tileproperties was missing and find my way here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment