Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Help Needed With Automatic Portrait Changing  (Read 179 times)

Phoniez

  • Ensign
  • *
  • Posts: 2
    • View Profile
Help Needed With Automatic Portrait Changing
« on: March 05, 2024, 12:56:13 PM »

So, I'm making a mod that lets you give the player and other characters swag portraits (configurable of course), and so far I've managed to make the player alone swag.

However, I'm not really too sure of how I'd go about making characters like Sebestyn swag, as my idea is to use some theoretical listener that is triggered each time a character's sprite is loaded in (whether this is from a fleet encounter or talking to someone on a station), which lets me pull the PersonAPI object corresponding to character that has loaded in, so I could then change the character's sprite as needed in time for the player to see the changed sprite.

But, my main problem is that I have no idea whether this theoretical listener is already in the api somewhere, or If I have to somehow make it myself (as I am very new to starsector modding), so can anyone give some help on what I should do?


Also, if possible, could someone direct me on how I can read mod config data from a json, so I can let the player configure what character portraits are swag or not easily.
Logged

Inventor Raccoon

  • Captain
  • ****
  • Posts: 452
  • Digging through trash for a hydroflux catalyst
    • View Profile
Re: Help Needed With Automatic Portrait Changing
« Reply #1 on: March 05, 2024, 01:47:19 PM »

I think it'd probably be easiest to simply check each swag-able character (via Global.getSector().getImportantPeople().getPerson("sebestyen"), or the easier form of People.getPerson(People.SEBESTYEN) ) when loading a save (do the check and change in your ModPlugin's onGameLoad() function) and apply the new portrait sprite from there

If you do want to run this code when interacting with any given person, then CampaignPlugin has updatePersonFacts() which runs when interacting with a new person (possibly multiple times? I'm not 100% on this) and returns their PersonAPI. Campaign plugins are set in vanilla/mod's data/config/settings.json's "plugins" field.

As for json loading, see Global.getSettings().loadJSON() and Global.getSettings().getMergedJSONForMod() and mods that load json files using it. Histidine's mods often do, such as Nexerelin or Combat Chatter. I find that "figure out how another mod uses this" is the best way to learn the more well-trodden parts of the API.
Logged

Phoniez

  • Ensign
  • *
  • Posts: 2
    • View Profile
Re: Help Needed With Automatic Portrait Changing
« Reply #2 on: March 06, 2024, 01:49:15 PM »

Thanks! Think I'll just go for the simpler option because I'm already manipulating the player's sprite in onGameLoad.
Logged