Hello All,
Hopefully this project can help everyone get started with the new JSON loading additions. Once you know how it works it's actually pretty quick!
In my demo project it will load in a basic city map. You can replace the loadMap( "CityMap.json" ) and createTileset( "CityMap.png", Map01.tilewidth, 0 ) with DungeonMap.json and DungeonTiles.png respectively for another example map that is of different dimensions, and tilesize (16 pixels instead of 32)
To roughly explain how I am importing the JSON files generated by Pyxel Edit:
~Referencing the PyxelLoader.agc file
JSON consists of data objects and arrays which can then contain their own arrays or data objects. Using AppGameKit types you can replicate the data structure of the JSON file to be imported.
I create types that represent the farthest branches of the JSON file and work backwards. So starting at the tile level, then layers and finally the map info. All in all it took 3 types to represent the Pyxel Edit JSON File. Any arrays are create without size (empty square brackets myArray[]) because the new commands take care of exapnding them appropriately
Once you have laid out the data structure correctly using types the next step is quite quick. I OpenToRead the JSON file, create a memblock from the file and then convert that memblock to a string (learned from Paul that this is substantially quicker than reading in the file line by line). You then declare your type (that matches the JSON data structure) and import your string data (once JSON file) using myType.fromJson(String$).
You can then just use your new type to access any data you need.
e.g. currentMap.layers[0].tiles[0].ID
In my project I have taken it a step further by abstracting the process into functions that return the JSON Data as a type. This just means that everytime i want to import a JSON I do the following:
myMap as tileMapType
myMap = LoadMap(filename$)
So I can have lots of level maps loaded at once, etc etc.
As I said, hopefully this will help people get started. Having these new commands gives us to so many cool tools out there that support JSON format not to mention handling your own data in nice ways. Pyxel Edit was just one tool that came to mind for me.
Any questions just send them through!