Json and customProperties

Report problems here (or use the built-in feedback dialog in the editor)
Post Reply
dAlex65
Posts: 16
Joined: Tue Feb 19, 2013 8:55 am

Json and customProperties

Post by dAlex65 »

If scene export to json-format, the saved file contains the defined customproperties.
But when load back file to the editor, all customproperties missing.
( The rube-format save-load ok )
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Json and customProperties

Post by iforce2d »

Yes, the .json format does not store all the info necessary to continue editing again. That's why the .rube format exists, and that's why saving to .json is called 'exporting'.

Actually, the custom properties do still exist in the scene after loading a .json into the editor, but they do not appear in the properties panel because there was no info loaded about them. If you set up the custom properties again (in the Scene settings dialog) then the values will show up again.

But ideally, you should consider the export to .json as a one-way process. Some other things change too, the main one is that concave polygons are decomposed into convex polygons that Box2D can use, but there may be other things in future that make a .json not so useful for continuing editing.
dAlex65
Posts: 16
Joined: Tue Feb 19, 2013 8:55 am

Re: Json and customProperties

Post by dAlex65 »

If you set up the custom properties again (in the Scene settings dialog) then the values will show up again.
Yeah, I noticed. But this solution would be very inconvenient, and once the information is there, so why not show it? ;)
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Json and customProperties

Post by iforce2d »

It's inconvenient because it's being used for the wrong purpose, like eating jelly with a knife. The .json contains only the necessary info for loading the scene in your game, and the .rube contains everything you need to continue editing, so choose the appropriate one for what you are doing.

The .json only contains properties that are actually set, so technically the information is not all there. This means that reading in the .json and trying to set up all the custom properties that existed before would not always restore all the properties that existed before anyway.

But as I mentioned earlier, custom properties are just one of many things that is not fully present in the .json. Other information is also lost when loading a .json instead of a .rube, and there may be even more in future. If there is some reason you cannot continue editing from a .rube file, maybe we can think about how to deal with that problem?

(Just in case you haven't seen it, there is a topic in the help which explains how fixtures are different in .rube and .json files: "Using exported data" -> "Difference between saving and exporting")
dAlex65
Posts: 16
Joined: Tue Feb 19, 2013 8:55 am

Re: Json and customProperties

Post by dAlex65 »

I totally understand and accepted your answers.

ps
Just in case maybe better solution if have standalone IMPORT for the Json in file menu, isn't it ?
And R.U.B.E is fantastic, congratulation :!:
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Json and customProperties

Post by iforce2d »

While you can open a .json, this is mainly as a convenience for bringing scenes from the free version, and because it can sometimes be handy to drop a .json into the editor to see what it is, or to copy a body/fixture from it etc.

I think I would rather discourage using .json file for any further uses than these, so an import option is not likely to be implemented. What I might do someday is check if any custom properties exist, and ask the user if they want to automatically set them up to show in the properties panel - but this would be a pretty low priority update.
Post Reply