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:
// Project: TileProperties ...test
// Created: 2018-06-16
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "TileProperties" )
SetWindowSize( 300, 450, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 100, 100 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetClearColor(255,255,255)
SetBorderColor(255,255,255)
gosub Setup_Variables
SetPrintColor(0,0,0)
SetPrintSize(15)
do
` Print some variables to make sure they populated correctly from the JSON string.
print(mytiles.columns)
print(mytiles.image)
print(mytiles.tileproperties.length)
for t = 0 to mytiles.tileproperties.length
f1$ = mytiles.tileproperties[t].field1
f2$ = mytiles.tileproperties[t].field2
f3$ = mytiles.tileproperties[t].field3
print(f1$+", "+f2$+", "+f3$)
next t
if GetRawLastKey() = 27 then goto exit_routine
Sync()
loop
Setup_Variables:
type _Property
field1 as string
field2 as string
field3 as string
endtype
type _TileSet
columns as integer
image as string
imageheight as integer
imagewidth as integer
margin as integer
name as string
spacing as integer
tilecount as integer
tileheight as integer
tileproperties as _Property[]
tilewidth as integer
_type as string
endtype
json$ = '{ "columns":10,'
json$ = json$ + ' "image":"tileset.png",'
json$ = json$ + ' "imageheight":1280,'
json$ = json$ + ' "imagewidth":640,'
json$ = json$ + ' "margin":0,'
json$ = json$ + ' "name":"Tileset",'
json$ = json$ + ' "spacing":0,'
json$ = json$ + ' "tilecount":200,'
json$ = json$ + ' "tileheight":64,'
json$ = json$ + ' "tileproperties":['
json$ = json$ + ' {"field1":"3","field2":"1","field3":"image1.png"},'
json$ = json$ + ' {"field1":"5","field2":"3","field3":"image2.png"}],'
json$ = json$ + ' "tilewidth":64,'
json$ = json$ + ' "type":"tileset"'
json$ = json$ + '}'
mytiles as _TileSet
mytiles.fromJSON( json$ )
return
exit_routine:
// Can display a final ad here, or a closing credits screen etc.
end