Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.95.1a is out! (12/10/21); Blog post: Hyperspace Topography (10/12/22)

Pages: 1 2 [3]

Author Topic: [0.95.1a] WhichMod 1.2.1  (Read 51654 times)

theDragn

  • Commander
  • ***
  • Posts: 245
    • View Profile
Re: [0.95.1a] WhichMod 1.2.1
« Reply #30 on: October 18, 2022, 01:24:59 AM »

Nothing to update here (and hopefully I won't ever have to update this), but I've been asked about how to include mod-identifying descriptions without interfering with WhichMod, so I've got some code for anyone who wants to include it in their mod. This will just add whichmod-style descriptions to ships and weapons from your mod if the user doesn't have whichmod active.

Code
public class YourModPlugin extends BaseModPlugin {
    @Override
    public void onApplicationLoad() {
        SettingsAPI settings = Global.getSettings();
        JSONArray csvData;
        if (settings.getModManager().isModEnabled("whichmod"))
            return;
        try {
            csvData = settings.loadCSV("data/strings/descriptions.csv", "YOUR MOD ID HERE");
        } catch (Exception e) {
            return;
        }

        // try reading each row in descriptions.csv
        for (int i = 0; i < csvData.length(); i++) {
            try {
                JSONObject row = csvData.getJSONObject(i);
                String id = row.getString("id");
                String type = row.getString("type");
                if (!(id == null || type == null || id.equals("") || type.equals(""))) {
                    Description desc;
                    Type descType = Enum.valueOf(Type.class, type);
                    if (descType == Type.SHIP || descType == Type.WEAPON)
                        desc = settings.getDescription(id, descType);
                    else
                        continue;
                    desc.setText1("[YOUR MOD NAME HERE] " + desc.getText1());
                    String prefix;
                }

            } catch (Exception e) {
                //logger.log(Level.INFO, e);
            }
        }
    }
}
Pages: 1 2 [3]