I'm not 100% sure if I understood your question, so hopefully this answer answers some of your questions haha :)
My current approach
I've encountered this problem multiple times, and the method which I'm using right now is creating my own interpreter. Basically I have a file that looks something like this:
[catapult]
setName:catapult,
setType:siege,
addComponent:health,
addComponent:attack,
...
This file contains information that is split into two parts: action:value
and separated by a comma. I then use my own interpreter called ObjectLoader
that reads this file and creates objects. Pseudo code might be something like this:
MyObject myObj = new MyObject();
// Here I read the file and add all action:value pairs to a list.
for(Pair pair : pairs) {
if(pair.getAction().equals("setName")) {
myObj.setName(pair.getValue());
} else if(pair.getAction().equals("addComponent") {
if(pair.getValue().equals("health") {
myObj.getEntity().addComponent(new HealthComponent());
}
} else if(...) {
...
}
}
This can also be applied to creating a stage, perhaps by doing something like this:
[SomeEnemy]
addComponent:health,
...
[SomeStage]
addEnemy:([SomeEnemy], 4), //Create 4 of "SomeEnemy"
...
This is of course not very clean code, and can quickly get very long if you have a lot of different components, for example. With this in mind I've started developing a better method using annotations and reflection, but that's not finished yet.
My previous approach
Previously I used one of the methods you named yourself; JSON. LibGDX already has JSON functionality built into it, using their Json classes (official tutorial). This works very well, and you can customize your serialization using their Json.Serializable
and Json.Serializer<T>
classes. I would suggest this method if you absolutely don't need the functionality of the other method I mentioned. It is also a lot easier to use.
Honorable mention
If you want an alternative to JSON you could look into XML. LibGDX also has built in functionality for this, just like JSON (official tutorial).