I've run into a weird issue with portraitSprites and fleet Commanders.
1. My Commanders all have the "default_portrait" set as their portraitSprite. Their names are fine, but they don't have portraitSprites set. Why is that? Is there something I needed to do when I generated the Fleets?
2. I'm not sure how to get the male / female-ness of the Commanders. This doesn't seem to be a straightforward thing to evaluate, but I presume if I can convert the JSONArray of male names to check against, I could determine that via a match.
3. I'm really getting confused by JSONArray sub-arrays. I wanted to parse the "portraits" to get a random male/female portrait, but this doesn't work:
private String getPortrait(String factionID){
try {
JSONObject json = Global.getSettings().loadJSON("data/world/factions/" + factionID + ".faction");
JSONArray maleFemale = json.getJSONArray("portraits");
JSONArray male = maleFemale.getJSONArray(0);
JSONArray female = maleFemale.getJSONArray(1);
if(MathUtils.getRandomNumberInRange(0,100f) <= 50f){
JSONObject portraitList = male.toJSONObject(male);
String Name = portraitList.toString((int)MathUtils.getRandomNumberInRange(0,portraitList.length()-1));
return Name;
} else {
JSONObject portraitList = female.toJSONObject(female);
String Name = portraitList.toString((int)MathUtils.getRandomNumberInRange(0,portraitList.length()-1));
return Name;
}
} catch (IOException | JSONException ex) {
return "default_portrait";
}
//return "default_portrait";
}
At this point I'm tempted to dump all of the JSON data into a class as standard string arrays and do this the hard way, lol. But surely this isn't such a nasty problem. I think the main issue here is #1; something is preventing the portraits from being auto-generated...