Here's an example of how I read the fleet dialogue csv for a reference to how to read .csv files in general:
Spoiler
public class FDialogue_factionTextLoader {
/**
* Spreadsheet data.
*/
// The file directory that contains the dialogue options based upon faction id. Each response dialogue category is optional as a default exists.
private static final String FILE = "data/config/FleetDialogue/factions/FleetDialogue_factionText.csv";
// End file data.
// Column ids in FleetDialogue_factionText.csv.
// Default faction id under "id" column.
private static String DEFAULT_ID = "default";
// Additional faction ids can implement any number of dialogue column ids to provide custom responses for the faction.
// Dialogue column ids.
// Imports faction dialogue matching any dialogue column ids which are defined here.
// Responses for each column are based upon an existing faction id in the "id" column.
// If no faction id exists for a dialogue column, or the corresponding dialogue cell to the faction id is empty, the default response is used instead.
private static String COMMODITY_REQUEST_DESCRIPTION = "commodityRequestDescription";
private static String COMMODITY_SUPPLY_REQUEST_DESCRIPTION = "commoditySupplyRequestDescription";
private static String COMMODITY_FUEL_REQUEST_DESCRIPTION = "commodityFuelRequestDescription";
private static String COMMODITY_DEMAND_DESCRIPTION = "commodityDemandDescription";
private static String COMMODITY_REQUEST_PLAYER_UNKNOWN = "commodityRequestPayerUnknown";
private static String COMMODITY_REQUEST_SUCCESS = "commodityRequestSuccess";
private static String COMMODITY_REQUEST_SUCCESS_FRIENDLY = "commodityRequestSuccessFriendly";
private static String COMMODITY_REQUEST_SUCCESS_EXALTED = "commodityRequestSuccessExalted";
private static String COMMODITY_REQUEST_SUCCESS_SUSPICIOUS = "commodityRequestSuccessSuspicious";
private static String COMMODITY_REQUEST_SUCCESS_ANNOYED = "commodityRequestSuccessAnnoyed";
private static String COMMODITY_REQUEST_SUCCESS_HAVETOPAY = "commodityRequestSuccessHaveToPay";
// End column ids.
/**
* Class data.
*/
// Logger data. For use in troubleshooting logging only.
private static final Logger LOG = Global.getLogger(FDialogue_factionTextLoader.class);
private static final String FACTION_ID_PREFIX = "Faction id: ";
private static final String NO_VALID_DIALOGUE_COLUMN = " - was found in FleetDialogue_factionText.csv, but no valid entry was found for: ";
private static final String VALID_DIALOGUE_COLUMN = " - was found in FleetDialogue_factionText.csv, and a valid entry was found for: ";
private static final String USE_DEFAULT_RESPONSE_FOR_CATEGORY = "Using default dialogue response for: ";
private static final String CUSTOM_FACTION_ID_PREFIX = "Using custom faction: ";
private static final String RESPONSE_CATEGORY_PREFIX = " - dialogue response for: ";
private static final String CUSTOM_FACTION_ID_NOT_FOUND = " - was not found in FleetDialogue_factionText.csv.";
// End Logger data.
private static Map<String, Map> FACTION_DIALOGUE = new HashMap<>();
private static Object CELL_DATA;
public static void readDialogueFile(){
FACTION_DIALOGUE.clear();
// Attempt to read the file row by row and store all factions ids in a map containing a nested map of all possible dialogue responses by faction id.
// Each faction id is the map key to the nested map of possible dialogue implementations for each faction - also contained in a map.
try {
JSONArray StringData = Global.getSettings().getMergedSpreadsheetDataForMod("id", FILE, "fleetdialogue_morro");
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(COMMODITY_REQUEST_DESCRIPTION) != null && !row.getString(COMMODITY_REQUEST_DESCRIPTION).isEmpty()) {
responses.put(COMMODITY_REQUEST_DESCRIPTION, row.getString(COMMODITY_REQUEST_DESCRIPTION));
}
if (row.getString(COMMODITY_SUPPLY_REQUEST_DESCRIPTION) != null && !row.getString(COMMODITY_SUPPLY_REQUEST_DESCRIPTION).isEmpty()) {
responses.put(COMMODITY_SUPPLY_REQUEST_DESCRIPTION, row.getString(COMMODITY_SUPPLY_REQUEST_DESCRIPTION));
}
if (row.getString(COMMODITY_FUEL_REQUEST_DESCRIPTION) != null && !row.getString(COMMODITY_FUEL_REQUEST_DESCRIPTION).isEmpty()) {
responses.put(COMMODITY_FUEL_REQUEST_DESCRIPTION, row.getString(COMMODITY_FUEL_REQUEST_DESCRIPTION));
}
if (row.getString(COMMODITY_DEMAND_DESCRIPTION) != null && !row.getString(COMMODITY_DEMAND_DESCRIPTION).isEmpty()) {
responses.put(COMMODITY_DEMAND_DESCRIPTION, row.getString(COMMODITY_DEMAND_DESCRIPTION));
}
if (row.getString(COMMODITY_REQUEST_PLAYER_UNKNOWN) != null && !row.getString(COMMODITY_REQUEST_PLAYER_UNKNOWN).isEmpty()) {
responses.put(COMMODITY_REQUEST_PLAYER_UNKNOWN, row.getString(COMMODITY_REQUEST_PLAYER_UNKNOWN));
}
if (row.getString(COMMODITY_REQUEST_SUCCESS) != null && !row.getString(COMMODITY_REQUEST_SUCCESS).isEmpty()) {
responses.put(COMMODITY_REQUEST_SUCCESS, row.getString(COMMODITY_REQUEST_SUCCESS));
}
if (row.getString(COMMODITY_REQUEST_SUCCESS_FRIENDLY) != null && !row.getString(COMMODITY_REQUEST_SUCCESS_FRIENDLY).isEmpty()) {
responses.put(COMMODITY_REQUEST_SUCCESS_FRIENDLY, row.getString(COMMODITY_REQUEST_SUCCESS_FRIENDLY));
}
if (row.getString(COMMODITY_REQUEST_SUCCESS_EXALTED) != null && !row.getString(COMMODITY_REQUEST_SUCCESS_EXALTED).isEmpty()) {
responses.put(COMMODITY_REQUEST_SUCCESS_EXALTED, row.getString(COMMODITY_REQUEST_SUCCESS_EXALTED));
}
if (row.getString(COMMODITY_REQUEST_SUCCESS_SUSPICIOUS) != null && !row.getString(COMMODITY_REQUEST_SUCCESS_SUSPICIOUS).isEmpty()) {
responses.put(COMMODITY_REQUEST_SUCCESS_SUSPICIOUS, row.getString(COMMODITY_REQUEST_SUCCESS_SUSPICIOUS));
}
if (row.getString(COMMODITY_REQUEST_SUCCESS_ANNOYED) != null && !row.getString(COMMODITY_REQUEST_SUCCESS_ANNOYED).isEmpty()) {
responses.put(COMMODITY_REQUEST_SUCCESS_ANNOYED, row.getString(COMMODITY_REQUEST_SUCCESS_ANNOYED));
}
if (row.getString(COMMODITY_REQUEST_SUCCESS_HAVETOPAY) != null && !row.getString(COMMODITY_REQUEST_SUCCESS_HAVETOPAY).isEmpty()) {
responses.put(COMMODITY_REQUEST_SUCCESS_HAVETOPAY, row.getString(COMMODITY_REQUEST_SUCCESS_HAVETOPAY));
}
// Add nested map to the faction map under the faction id.
FACTION_DIALOGUE.put(row.getString("id"), responses);
}
}
// Log error if dialogue file cannot be parsed correctly.
} catch (IOException | JSONException ex) {
LOG.error("unable to read " + FILE);
}
}
- this stores all your relevant strings from the file in a map which you can use for whatever you want.
An example entry from the file it's reading (screenshot):
As far as actually adding those strings to descriptions for hulls, I actually doubt that is possible but Alex would have to chime in. I think it is handled on the game load only.
If it's containted in the persistant data, though, then maybe something like:
Spoiler
JSONObject descriptions = (JSONObject) Global.getSector().getPersistentData().get("descriptions");
Object yourID = "hullID";
Object yourType = "SHIP";
Object yourDescription = "description";
Object yourRole = "role";
try {
descriptions.put("id", yourID);
descriptions.put("type", yourType);
descriptions.put("text1", yourDescription);
descriptions.put("text2", yourRole);
} catch (JSONException e) {
LOG.error(e);
}
Global.getSector().getPersistentData().put("descriptions", descriptions);
*Might* work, but it depends upon the format it is kept in and I don't think that is documented anywhere.