Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / fromJSON help

Author
Message
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 3rd Jul 2018 19:17 Edited at: 3rd Jul 2018 19:20
Hi,
I cannot figure out how I will setup AppGameKit types in order to load a the following JSON file:

The file above is a small part of tileset file which has been exported from the Tiled application

The following does not work:
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 4th Jul 2018 08:03 Edited at: 4th Jul 2018 08:17
The types must match the structure of the JSON file. Everything within curly brackets '{}' are objects. Everything in square brackets'[]' are arrays. You don't have any arrays in the JSON file, so don't expect any arrays to be filled in the type (such as your tileproperties field). The string to the left of : is a variable in the type, and everything to the right of : is its value.


Hmm, there seems to be a bug. The nested types are not being read in correctly.
Edit: Found the bug. Seems fromJSON doesn't parse the trailing commas in lines 45 and 51 correctly. Remove them from the JSON file and it works fine.
Edit2: Looks like it is not AppGameKit that is in error. Looking over the JSON specifications, a trailing comma is not allowed, so the bug is in Tiled for adding it.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 4th Jul 2018 09:00
Good job TomToad. Personally I would fix the broken JSON (manually if need be), to make it more programmer friendly with tileproperties as an array of _Property. Drop the "ID" string and instead use the array index to reference the individual tileproperties.
Example:

Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 4th Jul 2018 09:40 Edited at: 4th Jul 2018 09:43
The actual JSON files produced by TILED don't have the issue that you have in the example above. I load them via .fromJSON in a simple function and file in a set of types and that works fine and display the tilemap. This works well and is great for making tilemaps that can be loaded with a nice simple single function.

http://docs.mapeditor.org/en/stable/reference/json-map-format/
There are examples in the documentation above and these load straight in as do files produced by tiled in the export JSON option.

The biggest issue is the tileproperties names aren't defined and thats what is the hardest problem I had...if you use custom properties then you have to make the names of the variables in your property types the same so they get loaded.
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 4th Jul 2018 19:49 Edited at: 4th Jul 2018 19:50
Hi guys,
Thank you for your comments
Quote: " Personally I would fix the broken JSON (manually if need be),"

This is not the best option, since the file produced, may be of a large size and there is the danger to make a mistake.

Quote: "The actual JSON files produced by TILED don't have the issue that you have in the example above"

Please download the attached files. It is a tileset file from Tiled. If you export the tileset in .json format then you will get a file that has the issue.

Attachments

Login to view attachments
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 4th Jul 2018 20:57 Edited at: 4th Jul 2018 21:45
You seem confused...thats a tileset file not a tilemap. You havent posted up a map at all. Att the tileset file does is tell tiled how big each tile is....not how they are laid out or how big the map is or anything!

The tsx is the tileset and is actually XML! It contains no useful information at all and wont produce a TILED map or a json output either. Read the TILED documentation.

The idea is that you use your tiles to make a map (typically saved as .TMX file)...You can then load the map into AppGameKit and display the map.

EDIT:
As a really quick example i created a tileMAP using your tileset. The map is 10,10...small but its only for an example. Then saved it as json and loaded it into AGK


Works great.
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 5th Jul 2018 00:21 Edited at: 5th Jul 2018 00:23
Hi Bengismo,
I mention it from my first post:
Quote: "The file above is a small part of tileset file..."

Tiled gives an option to export the tileset file in .json format. This goal for me is to load a tileset file from the Tiled app using the AGK
In any case thank you for the quick example
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 5th Jul 2018 00:52
Make sure that you have the latest TileD version. Seems this bug was fixed in version 1.1.4 "Fixed exporting of external tilesets to JSON or TSX formats
" The latest version is 1.1.5
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 5th Jul 2018 01:05 Edited at: 5th Jul 2018 01:12
Apologies, i thought you were only loadng the tileset to be able to display a map but if you just want to load the tileset alone then it is possible

It works for me using your tileset file saved as a json



Might be easiest to change some feildnames to get it to do it easily though....I willl leave you to it.
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 5th Jul 2018 05:32
Thank you for the input.
@Bengismo: could you please send me the AppGameKit project and the tilset file in .json format?
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 5th Jul 2018 11:01
@george++, you don't need Bengismo to send you the JSON file if you export it with the latest TileD version. The bug in the file was fixed in 1.1.4. There is, however, a problem between the way TileD exports the information to JSON and the way AppGameKit parses the JSON file. TileD exports each tile's custom properties as its own object, with the name as the tile's index and the value as another object containing all the properties. Since AppGameKit will only parse an object if there is a corresponding field in the type, then you need to create a type with a field for every single tile. A tileset with 10x10 tiles would require 100 fields. This is a bit unwieldy to do, especially if you don't know how big the tileset is going to be in advance.

The solution here would be to remove the tileproperties field from the type and parse the JSON file normally with .fromJSON. Create a field that is an array of properties. You can set the .length of the array after parsing the JSON and set it to Tileset.ImageCount. Then use FindString() to search where the tileproperties begins in the JSON file and manually parse the properties. Using Val(objectname) to convert the "0". "1", etc to indices for the array.

I am out of time, so I can't explain this any better now. I will be home late, but if I get the time, I'll try to come up with some code that should illustrate the process.

Another, maybe simpler solution, would be to edit the JSON file so that the list of objects is instead an array of objects, then you can parse the file normally with .fromJSON.
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 5th Jul 2018 14:14
Thank you TomToad for this detailed guiding. I asked the project from Beginsmo, because I've already use the Tiled v. 1.1.4. I'll try to follow the simpler solution you described at the end of your post.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 5th Jul 2018 15:11
Surely just update your version of tiled to 1.1.5 and it solves the problem like TomToad says

Login to post a reply

Server time is: 2024-04-25 16:38:39
Your offset time is: 2024-04-25 16:38:39