Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: CharacterCreationPlugin - how to be compatible [0.6.1a]  (Read 8611 times)

Trylobot

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1170
    • View Profile
    • Github profile
CharacterCreationPlugin - how to be compatible [0.6.1a]
« on: October 08, 2013, 07:12:31 PM »

Modders.

As you all know, the current system we use for CharacterCreationPlugin is somewhat unfriendly. Mods generally want to have their own, and there's no easy way to get them to collaborate and both run, so we're basically all fighting.

However, if you put the following code into yours, you can hand off control to another mod's plugin. You want to do this if your mod is part of a compilation, because that way you can maintain a single version of your content. Here's the code.

Note: It's worth mentioning that you shouldn't name your plugin class "CharacterCreationPluginImpl" for the sake of clarity. The game doesn't care what you call it as long as you're in the right package and you implement the plugin API.

Code: java
package data.scripts.plugins;
import java.util.ArrayList;
import java.util.List;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.CargoAPI.CrewXPLevel;
import com.fs.starfarer.api.characters.CharacterCreationPlugin;
import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
import com.fs.starfarer.api.fleet.FleetMemberType;

public class YourModCharacterCreationPlugin implements CharacterCreationPlugin
{
CharacterCreationPlugin handoff_plugin = null;

public YourModCharacterCreationPlugin()
{
// automatic yield of control pass-through in case of conflict:
//   Exerelin
//   Uomoz's Sector: Journey

if( can_be_loaded( "data.scripts.world.ExerelinGen" )
||  can_be_loaded( "data.scripts.UsSModPlugin" ))
{
try
{
handoff_plugin = (CharacterCreationPlugin) Global.getSettings().getScriptClassLoader()
 .loadClass( "data.scripts.plugins.CharacterCreationPluginImpl" )
 .newInstance();
}
catch( ClassNotFoundException e ) {}
catch( InstantiationException e ) {}
catch( IllegalAccessException e ) {}
}
}

public static boolean can_be_loaded( String fullyQualifiedClassName )
{
try
{
Global.getSettings().getScriptClassLoader().loadClass( fullyQualifiedClassName );
return true;
}
catch (ClassNotFoundException ex)
{
return false;
}
}

// ... snip ...

public String getPrompt()
{
if( handoff_plugin != null )
{
return handoff_plugin.getPrompt();
}
////////////////////////
////   YOUR CODE HERE
////////////////////////
}

@SuppressWarnings("unchecked")
public List getResponses()
{
if( handoff_plugin != null )
{
return handoff_plugin.getResponses();
}
////////////////////////
////   YOUR CODE HERE
////////////////////////
}

public void submit(Response response, CharacterCreationData data)
{
if( handoff_plugin != null )
{
handoff_plugin.submit( response, data );
return;
}
////////////////////////
////   YOUR CODE HERE
////////////////////////
}

public void startingShipPicked(String variantId, CharacterCreationData data)
{
if( handoff_plugin != null )
{
handoff_plugin.startingShipPicked( variantId, data );
return;
}
////////////////////////
////   YOUR CODE HERE
////////////////////////
}
}

« Last Edit: October 09, 2013, 09:20:09 AM by Trylobot »
Logged