JSON for saving ships
It’s been mostly backend work for me, lately. I’ve evaluated a few different JSON libraries- the plan is to use it to create strings of our complex data types to save within Unity’s PlayerPrefs system.
First I tried JSON Sharp, and I got embarrassingly far into it before realizing the library didn’t come with a parser to turn the JSON strings back into anything. I then looked at JSON.NET but found it to be huge, heavyweight, and had some dependencies in System.LINQ that Unity did not include. So rather than mess with it, I went to find a lightweight library and found LitJSON, which seems pretty good.
So I’ve got the ships saving in a rough fashion. Loading will be a bit more tricky.
Meanwhile, Scott’s been working on some more HUD stuff, and clicking to select things!
JSON seems like a really sensible format. I’ve been messing with JSON parsers a bit this past week when I should have been working on other things. I’ve never been jazzed about XML; I think JSON would be a better fit for the kinds of things I end up doing.
Yeah, XML is about as long-winded as I could ever imagine. I was just happy to find a lightweight solution. Once you format the JSON string, it’s fairly readable:
{
"componentName":"Hull Component",
"connectionID":-1,
"children":[
{
"componentName":"Cockpit A",
"connectionID":0,
"children":[]
},
{
"componentName":"Thorium Engine",
"connectionID":0,
"children":[]
}
]
}
Except when wordpress removes the indentation…