Jump to content

[1.7.10] Commenting on the JSON (for Configuration)


Abastro

Recommended Posts

How can I add Comments on the JSON file for specific property?

 

I tried to do it using Gson, but I realized that It uses JsonWriter, which cannot print single sentence for commenting.

& I don't want to add new property for the comment.

 

Actually I have already solved this issue with refletion.. I got the Writer field from the JsonWriter which is private.

Is there any better way which I doesn't know? For I doesn't like using Reflection in this way..

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Gson already suppports some comments(like /*, */, //) and ignore them while reading, so I thought writing comments would also be available.

 

So, is there no other way with Gson or anything?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Yes. I want to use it for my unified config system. (for Stellarium)

Since I'd use it not only for text configuration but also for packets & data saving, I prefer JSON forms.

And I just want to add some comments for text config.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

JSON has nothing to do with packets, and to save data either use a normal config file or save it to NBT.

Yes, I know. But NBT is really bad for configuration, and I saw someone using JSON format to send object using packet.

It seems to be portable enough. (Of course I'd write the JSON in bytestream for sending packets)

 

and I said something wrong, the reason that I selected JSON is for the configuration.

Since my configuration have to be dynamic and hierarchical, I cannot use Forge Configuration.

 

Actually I tried to make my own config type, but I realized that it is hard work and It

And then I found that JSON is well suited for my objective.

 

and about hocon, is it accepted as a default library for Minecraft? If not, I think it would be difficult to use it..

Then I'd end up using my current way.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Send me a pm so that I can give you my custom database program as well add how to use it. I am not ready to release the code to the public yet though I will let you use it for this mod.

No. I think it will be much more complicated to use it.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

If you want nested categories you can use "." to specify them when using the Forge Configuration class.

 

Categories:

String category1 = "topCategory.subCategory1";
String category2  "topCategory.subCategory2";

 

What the Forge config file might look like:

{
"topCategory": {
    "subCategory1": {
        # your options
    },
    "subCategory2": {
        " more options
    }
}
}

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Link to comment
Share on other sites

Again, what is wrong with the forge Configuration class?

What I mean by "dynamic", is that I have to find every existing category, and read information from each.

AFAIK Forge Configuration can be hierarchical, but not dynamic.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Maybe I am only remembering the old version of the Forge Configuration..

Anyway it is not hierarchical (only it can be shown as "hierarchical" using dots)

and it cannot be written on bytestream. (+without comments)

 

So it would take much more effort to change my system to use it.

I'd rather end up using reflection to JsonWriter.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

No, it is actually not 'config'.

In fact, It is partially encoded basic information on planets.

 

On File Configuration part, it is encoded to be more readable.

On Bytestream part (for packet), it is encoded to be compressed.

 

+ It has to be sent by packet, since it will modify the world regardless of client configuration.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Can't you just include a readme file with the explanation on how to write the JSON that is what most people do, sounds to me your over complicating your life here. :P

No, It would be a LOT harder to read. Then even I would not know what property means what, for it is very complicated config.

I'd need both readme file and comments, and they might not be enough!

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Can't you just include a readme file with the explanation on how to write the JSON that is what most people do, sounds to me your over complicating your life here. :P

No, It would be a LOT harder to read. Then even I would not know what property means what, for it is very complicated config.

I'd need both readme file and comments, and they might not be enough!

 

Use an XMLSerializer then, XML supports comments <!-- -->

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

Does it support bytestream output, too?

 

Yes you can technically transform anything to bytes, just deserialize it the way you serialized it, the only thing at stake is efficiency.

 

Now the only downside is that I'm not sure XML Serializers support comments when serializing, you'd have to test it out and if not find a LIB that does serialize comments too.

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

And the "Efficiency" is important. + Making XML bytestream writer would just double the effort.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Again: Why do you want to send a config via packets? That seems very strange. It is simple though: Just write whatever config file you chose into a String, like you would when writing to disk. Then send that string.

As I said, it is partially encoded basic information on planets, which can be sent from the Server.

Since server specifies the form of world on client, it has to be sent using packet.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Because I want to make the "configurable" system able to be changed either by GUI or Text.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Since it is deeply related with the world, it has to be sent by packet like world info.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

I would just encode the data as a byte stream and send it, the configuration would just be that encoded data. Why would you need to send the config comments with your configuration? Will the clients be able to edit the config? In that case I would provide a nice gui for that.

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

What I meant was: How is the configuration format related to how you send it with a packet?

Because Forge Configuration always contains the comment, so i cant send it using a packet.

And any non built-in config platforms are really not preferable. (I don't want to import any external library)

 

To Belpois: It does not contains comment on packet. Please read the whole thread...

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

"Because Forge Configuration always contains the comment"

- Wrong, it doesn't (unless I misunderstood)

"i cant send it using a packet"

- You can send everything using packets, you are just looking for easy way.

 

Proper way of doing it would be:

1. Config loads

2. Sets some virtual data, example: (doesn't need that if)

if (conf.containsKey("Generics")) MyVirtualStorageClass.setGenerics(conf.get("Generics").getStringList());

3. And at this point you don't give a damn about config no more - everything is virtual.

4. In your packet you simply MyVirtualStorageClass.getGenerics  (which will return some String array) and write all strings to buffer.

5. On receiver side you read it and put in client-side vitrual storage class or actually anny other kind of storage (file cache).

 

I don't see why you want to send whole config so badly, it'd bebetter to send key info when you login on server and then on client use that info to e.g change sky behaviour (color and shit).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Load all categories and send all of them as string? That doesn't make sense..

and Configuration#containsKey(String) or Configuration#get(String) doesn't seem to exist in forge 1.7.10.

 

Plus there was no method for getting Config String from Configuration class. (As it just uses the File class..)

 

I'd just use my current way with Json.

 

 

I think I got every help that I needed. There was no easier way with Json.

So I want to lock this thread.. how I can lock this thread? Or I cannot?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.