Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#26 2017-03-05 21:28:30

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: [Alpha Library] WorldSaver

Updated WorldSaver (and made a few small bugfuxes for WorldArea and ConnectedWorld):

  • Added a new JsonData type, that can be used to more easily load / save json files

  • Use JsonData.FromJson(string json) to get the JsonData from a json string

  • Use JsonData.FromObject(object json) to get the JsonData from an object (only some types are supported)

  • Use JsonData.FromObject(object json) to get the JsonData from an object

  • You can implicitly convert a few supported types to JsonData objects

  • You can explicitly convert the JsonData objects back to their original types

  • Each JsonData has a Type string

  • To convert the JsonData back to a string, use (data).ToString(bool neatified)

  • To convert the JsonData back to an object, use (data).ToObject()

Supported Types

Offline

#27 2017-03-06 01:03:05

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: [Alpha Library] WorldSaver

If you wish to support more objects without extra, I'd suggest JSON.NET. Even in the C# documentation they say JSON.NET is better than their implementation.

Although JSON.NET does work for custom single constructor objects (serializes all public properties and fields), your users would still have to implement JSON.NET themselves for more control (ignore certain fields, include private fields, specify a certain constructor when multiple constructors implemented).

Hope it's of help (sorry I came so late with this one, started using it myself only recently).

Offline

#28 2017-03-06 09:15:34, last edited by LukeM (2017-03-06 09:16:53)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: [Alpha Library] WorldSaver

den3107 wrote:

If you wish to support more objects without extra, I'd suggest JSON.NET. Even in the C# documentation they say JSON.NET is better than their implementation.

Although JSON.NET does work for custom single constructor objects (serializes all public properties and fields), your users would still have to implement JSON.NET themselves for more control (ignore certain fields, include private fields, specify a certain constructor when multiple constructors implemented).

Hope it's of help (sorry I came so late with this one, started using it myself only recently).

I don't really like the JSON deserialisers that deserialise to a user defined object, I prefer it if they are converted to dictionaries and lists (I'm not sure if JSON.net can do this or not).
Also I like to be able to control the whitespace (In pretty much all other deserialisers, they put everything on its own line, but with the world data, I wanted it to format it so you could read (the block arrays) it in a text editor).
Another reason I didn't use a library is that I store the world data differently in this library than I do in JSON, to make the file size smaller, and the library speed faster, so I would have to do a lot of formatting anyway.

I don't think any other library has all these features, so I decided to just make it myself.

Offline

#29 2017-03-06 10:06:31

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: [Alpha Library] WorldSaver

JSON.net does support dicts, lists and arrays, obviously, and objects are basically stored as JSON objects with basically dict-like content.

example

As far as I can see this quickly you can specify whether you want it nicely indented or on a single line, although I couldn't find any method of doing multiple formats in a single object (single line for 2nd dimension of arrays, all the rest indented, what you currently have).
You actually can create your own formatter to write your objects in a different format, or you'd just have to put it into a different object that would match your JSON format before serializing it.

But alright, 't was a suggestion, up to you if you use it or not (can also understand it might seem like too much work to change everything now).

Offline

#30 2017-03-06 16:28:40

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: [Alpha Library] WorldSaver

den3107 wrote:

As far as I can see this quickly you can specify whether you want it nicely indented or on a single line, although I couldn't find any method of doing multiple formats in a single object (single line for 2nd dimension of arrays, all the rest indented, what you currently have).
You actually can create your own formatter to write your objects in a different format, or you'd just have to put it into a different object that would match your JSON format before serializing it.

But alright, 't was a suggestion, up to you if you use it or not (can also understand it might seem like too much work to change everything now).

It probably wouldnt be too hard to change things, but it probably wouldnt be worth the effort, as what im doing now pretty much does everything I need it to do. I might add something to change an arbritrary class to the Dictionary<string, JsonData> format some time, but other than that I think it mostly works already.

Offline

LukeM1488814120649650

Board footer

Powered by FluxBB

[ Started around 1732682637.932 - Generated in 0.062 seconds, 12 queries executed - Memory usage: 1.45 MiB (Peak: 1.56 MiB) ]