*Solved*
Can anyone help getting this file to load correctly? The log shows the issue.Code:
JSONArray StringData = Global.getSettings().getMergedSpreadsheetDataForMod("id", FILE, "fleetdialogue_morro");
for(int i = 0; i < StringData.length(); i++) {
JSONObject row = StringData.getJSONObject(i);
if(row.getString("id")!=null){
// Set up dialogue response map. Response category keys are hardcoded and called in the various get methods implemented below.
// Also checks for missing or empty dialogue responses as a safeguard.
if (row.getString("commodityRequestDescription") != null && !row.getString("commodityRequestDescription").isEmpty()) {
DIALOGUE_RESPONSES.put("commodityRequestDescription", row.getString("commodityRequestDescription"));
}
if (row.getString("commoditySupplyRequestDescription") != null && !row.getString("commoditySupplyRequestDescription").isEmpty()) {
DIALOGUE_RESPONSES.put("commoditySupplyRequestDescription", row.getString("commoditySupplyRequestDescription"));
}
// Add nested map to the faction map under the faction id.
FACTION_DIALOGUE.put(row.getString("id"), DIALOGUE_RESPONSES);
}
}
// This is to test that the information is being loaded correctly.
String defaultCommodityRequestDescription = FACTION_DIALOGUE.get("default").get("commodityRequestDescription").toString();
String defaultCommoditySupplyRequestDescription = FACTION_DIALOGUE.get("default").get("commoditySupplyRequestDescription").toString();
String hegCommodityRequestDescription = FACTION_DIALOGUE.get("hegemony").get("commodityRequestDescription").toString();
String hegCommoditySupplyRequestDescription = FACTION_DIALOGUE.get("hegemony").get("commoditySupplyRequestDescription").toString();
LOG.error("Contents of dialogue map for default: " + defaultCommodityRequestDescription + " " + defaultCommoditySupplyRequestDescription);
LOG.error("Contents of dialogue map for hegemony: " + hegCommodityRequestDescription + " " + hegCommoditySupplyRequestDescription);
File Contents:
id,commodityRequestDescription,commoditySupplyRequestDescription,
default,"After exchanging a few pleasantries, you inform the $personRank that you could use some assistance. The weight of your influence, if any, with $hisOrHer faction is behind the request, as is the military strength of each of your respective forces...","You should see this under default.",
hegemony,"$lordOrLady...$priestOrPriestess...$sorcererOrSorceress","Test",
Log on application start:
11915 [Thread-4] ERROR factions.FDialogue_factionTextLoader - Contents of dialogue map for default: $lordOrLady...$priestOrPriestess...$sorcererOrSorceress Test
11915 [Thread-4] ERROR factions.FDialogue_factionTextLoader - Contents of dialogue map for hegemony: $lordOrLady...$priestOrPriestess...$sorcererOrSorceress Test
*EDIT*
Nvm, I figured it out. I needed to create the map for the responses
each iteration of the loop rather than using a global static map. It reads the file correctly now.
(New code)
for(int i = 0; i < StringData.length(); i++) {
JSONObject row = StringData.getJSONObject(i);
Map<String, String> responses = new HashMap<>();
responses.clear();
if(row.getString("id")!=null){
// Set up dialogue response map. Response category keys are hardcoded and called in the various get methods implemented below.
// Also checks for missing or empty dialogue responses as a safeguard.
if (row.getString("commodityRequestDescription") != null && !row.getString("commodityRequestDescription").isEmpty()) {
responses.put("commodityRequestDescription", row.getString("commodityRequestDescription"));
}
if (row.getString("commoditySupplyRequestDescription") != null && !row.getString("commoditySupplyRequestDescription").isEmpty()) {
responses.put("commoditySupplyRequestDescription", row.getString("commoditySupplyRequestDescription"));
}
// Add nested map to the faction map under the faction id.
FACTION_DIALOGUE.put(row.getString("id"), responses);
}
}