Fractal Softworks Forum

Starsector => Mods => Modding Resources => Topic started by: Trylobot on October 08, 2013, 07:12:31 PM

Title: CharacterCreationPlugin - how to be compatible [0.6.1a]
Post by: Trylobot 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
////////////////////////
}
}

(http://i.imgur.com/oRESKML.gif)