Quote from: eri0o on Mon 09/09/2024 15:25:59Anyway, this may take a little bit I will get there, sorry for the wait.
No worries! I've made the fixes for the issues I encountered in my local copy, so they're not showstoppers. (I thought I'd even experiment with forking the repo and trying to submit my edits as pull requests.)
Ultimately I'm hoping to be able to do something like:
// In Player.asc, for a custom "Player" struct
void LoadFromJson(this Player*, JsonParser* json, String path)
{
if(json.KeyExists(path, this.Id))
{
JToken* t = json.Select(path, this.Id);
this.name = t.StringValue("name");
this.age = t.IntValue("age");
this.leftHanded = t.BoolValue("left-handed");
this.hairColor = HexToAgsColor(t.StringValue("hair-color"));
}
}
// In GlobalScript.asc, on startup
bool LoadJsonConfig(String jsonString)
{
JsonParser* json;
// Omitted: parse the string
// Load player config
String path = "players";
for(int i=0; i<playerCount; i++)
player[i].LoadFromJson(json, json.SelectArrayIndex(path,i).path);
// TODO: Load other stuff
// ...
}
(I haven't thought through the precise API, but essentially I want to be able to freely select/search for particular keys within a particular token and its children and read the corresponding values.)