data.scripts.console
Class Console

java.lang.Object
  extended by data.scripts.console.Console
All Implemented Interfaces:
com.fs.starfarer.api.campaign.SpawnPointPlugin

public final class Console
extends java.lang.Object
implements com.fs.starfarer.api.campaign.SpawnPointPlugin

Executes commands and handles console output. Instances hold custom settings.


Field Summary
static java.lang.String COMMAND_PACKAGE
          The package all console commands must be in
static java.lang.String COMMAND_SEPARATOR
          To enter multiple commands at once, separate them with the following
static java.awt.Color CONSOLE_COLOR
          The color of messages posted by showMessage(java.lang.String)
static int DEFAULT_CONSOLE_KEY
          This is the LWJGL constant of the default keyboard key to summon the console
static long INPUT_FRAMERATE
          How often (in milliseconds) between polling the keyboard for input
static int LINE_LENGTH
          How long a line can be before being split by showMessage(java.lang.String)
static int REBIND_KEY
          This is the LWJGL constant of the keyboard key which, combined with shift, rebinds the console
static boolean REQUIRE_DEV_MODE
          Does the console require devMode=true in settings.json to function?
static boolean REQUIRE_RUN_WINDOWED
          Does the console require the game to be run windowed to function?
static java.util.List<java.lang.Integer> RESTRICTED_KEYS
          A list of LWJGL keyboard constants that can't be bound to summon the console
static boolean SHOW_STACK_TRACE_ON_EXCEPTION
          Should we display the entire stack trace when an exception occurs?
 
Constructor Summary
Console()
           
 
Method Summary
 boolean addAlias(java.lang.String alias, java.lang.String command)
          Registers an alias to be used in place of a longer command.
static void addScript(java.lang.String name, com.fs.starfarer.api.Script script)
          Registers a script to be executable with the RunScript command.
 void advance(com.fs.starfarer.api.campaign.SectorAPI sector, com.fs.starfarer.api.campaign.LocationAPI location)
          Automatically called by the game - don't call this manually.
protected  void checkQueue()
          Runs any commands that are queued for execution.
 java.util.List<java.lang.String> getAliases(java.lang.String command)
          Returns all aliases associated with a command
protected static com.fs.starfarer.api.combat.CombatEngineAPI getCombatEngine()
          Returns the CombatEngineAPI used by in-battle commands.
 com.fs.starfarer.api.campaign.LocationAPI getLocation()
          Gets the current LocationAPI this console uses
static com.fs.starfarer.api.Script getScript(java.lang.String name)
          Retrieve a script from RunScript's script storage.
protected
<T> T
getVar(java.lang.String varName, java.lang.Class<T> type)
          Retrieves the value of the variable varName, if any.
protected  java.lang.Class getVarType(java.lang.String varName)
          Get the runtime type of the variable with the supplied name.
protected  boolean hasVar(java.lang.String varName)
          Checks for the existence of a variable with the supplied name.
protected static boolean isInBattle()
          Check if the player is on the battle map.
 java.lang.Object readResolve()
          Automatically called by the JRE - don't call this manually.
 void registerCommand(java.lang.Class commandClass)
          Registers a command with the Console.
protected static void setCombatEngine(com.fs.starfarer.api.combat.CombatEngineAPI engine)
          Sets the CombatEngineAPI used by in-battle commands.
protected static void setInBattle(boolean isInBattle)
          Tells the Console whether to allow battle-only commands or not.
protected  void setVar(java.lang.String varName, java.lang.Object varData)
          Creates/sets a persistent variable that can be accessed by all console commands.
static void showError(java.lang.String preamble, java.lang.Exception ex)
          Displays information to the user about an exception that has occurred.
static void showMessage(java.lang.String message)
          Formats and word-wraps the supplied text, then outputs it to the player.
static void showMessage(java.lang.String preamble, java.lang.String message, boolean indent)
          Formats and word-wraps the supplied text, then outputs it to the player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REQUIRE_DEV_MODE

public static final boolean REQUIRE_DEV_MODE
Does the console require devMode=true in settings.json to function?

See Also:
Constant Field Values

REQUIRE_RUN_WINDOWED

public static final boolean REQUIRE_RUN_WINDOWED
Does the console require the game to be run windowed to function?

See Also:
Constant Field Values

SHOW_STACK_TRACE_ON_EXCEPTION

public static final boolean SHOW_STACK_TRACE_ON_EXCEPTION
Should we display the entire stack trace when an exception occurs?

See Also:
Constant Field Values

COMMAND_PACKAGE

public static final java.lang.String COMMAND_PACKAGE
The package all console commands must be in

See Also:
Constant Field Values

COMMAND_SEPARATOR

public static final java.lang.String COMMAND_SEPARATOR
To enter multiple commands at once, separate them with the following

See Also:
Constant Field Values

CONSOLE_COLOR

public static final java.awt.Color CONSOLE_COLOR
The color of messages posted by showMessage(java.lang.String)


LINE_LENGTH

public static final int LINE_LENGTH
How long a line can be before being split by showMessage(java.lang.String)

See Also:
Constant Field Values

INPUT_FRAMERATE

public static final long INPUT_FRAMERATE
How often (in milliseconds) between polling the keyboard for input

See Also:
Constant Field Values

DEFAULT_CONSOLE_KEY

public static final int DEFAULT_CONSOLE_KEY
This is the LWJGL constant of the default keyboard key to summon the console

See Also:
Constant Field Values

REBIND_KEY

public static final int REBIND_KEY
This is the LWJGL constant of the keyboard key which, combined with shift, rebinds the console

See Also:
Constant Field Values

RESTRICTED_KEYS

public static final java.util.List<java.lang.Integer> RESTRICTED_KEYS
A list of LWJGL keyboard constants that can't be bound to summon the console

Constructor Detail

Console

public Console()
Method Detail

readResolve

public java.lang.Object readResolve()
Automatically called by the JRE - don't call this manually.


registerCommand

public void registerCommand(java.lang.Class commandClass)
                     throws java.lang.Exception
Registers a command with the Console. Commands must pass validation, otherwise registration will fail!

Validation consists of the following:
- Checking that there isn't a built-in command with the same name
- Checking that the command's class is in the correct package
- Checking that the command extends BaseCommand

Parameters:
commandClass - the class object of the command to register
Throws:
java.lang.Exception - if the command doesn't pass validation

addAlias

public boolean addAlias(java.lang.String alias,
                        java.lang.String command)
Registers an alias to be used in place of a longer command. Fails if the alias would conflict with an existing command.

Parameters:
alias - the alias (shorthand) for the command
command - the command to replace alias with
Returns:
true if the alias was successfully added, false otherwise

getAliases

public java.util.List<java.lang.String> getAliases(java.lang.String command)
Returns all aliases associated with a command

Parameters:
command - the command to check for aliases of
Returns:
a List of Strings of all aliases for this command

setInBattle

protected static void setInBattle(boolean isInBattle)
Tells the Console whether to allow battle-only commands or not.

Parameters:
isInBattle -

isInBattle

protected static boolean isInBattle()
Check if the player is on the battle map.

Returns:
true if battle-only commands are allowed

setCombatEngine

protected static void setCombatEngine(com.fs.starfarer.api.combat.CombatEngineAPI engine)
Sets the CombatEngineAPI used by in-battle commands.

Parameters:
engine - the active CombatEngineAPI
See Also:
BaseCombatHook

getCombatEngine

protected static com.fs.starfarer.api.combat.CombatEngineAPI getCombatEngine()
Returns the CombatEngineAPI used by in-battle commands.

Returns:
the active CombatEngineAPI

setVar

protected void setVar(java.lang.String varName,
                      java.lang.Object varData)
Creates/sets a persistent variable that can be accessed by all console commands.

Important: ensure you use unique names for your variables to avoid conflict!

Parameters:
varName - the unique key this variable can be retrieved with
varData - the data this variable should hold

getVar

protected <T> T getVar(java.lang.String varName,
                       java.lang.Class<T> type)
Retrieves the value of the variable varName, if any.

Type Parameters:
T -
Parameters:
varName - the name of the variable to retrieve
type - the type to be returned (e.g. Script.class)
Returns:
the data associated with that variable

hasVar

protected boolean hasVar(java.lang.String varName)
Checks for the existence of a variable with the supplied name.

Parameters:
varName - the name of the variable to check
Returns:
true if the variable has been set, false otherwise

getVarType

protected java.lang.Class getVarType(java.lang.String varName)
Get the runtime type of the variable with the supplied name.

Parameters:
varName - the name of the variable to check
Returns:
the Class object for the variable if it exists, null otherwise

getLocation

public com.fs.starfarer.api.campaign.LocationAPI getLocation()
Gets the current LocationAPI this console uses

Returns:
the last location this campaign's advance() occurred in

checkQueue

protected void checkQueue()
Runs any commands that are queued for execution.


addScript

public static void addScript(java.lang.String name,
                             com.fs.starfarer.api.Script script)
Registers a script to be executable with the RunScript command.

Parameters:
name - The name of the script (for retrieval)
script - The script to be added

getScript

public static com.fs.starfarer.api.Script getScript(java.lang.String name)
Retrieve a script from RunScript's script storage.

Parameters:
name - The name of the script to be retrieved
Returns:
The Script registered with this name, null if none found

showMessage

public static void showMessage(java.lang.String preamble,
                               java.lang.String message,
                               boolean indent)
Formats and word-wraps the supplied text, then outputs it to the player.

Parameters:
preamble - the header for this message, won't be indented
message - the main body of text
indent - whether to indent each line of the main body

showMessage

public static void showMessage(java.lang.String message)
Formats and word-wraps the supplied text, then outputs it to the player.

Parameters:
message - the message to output

showError

public static void showError(java.lang.String preamble,
                             java.lang.Exception ex)
Displays information to the user about an exception that has occurred.

Parameters:
preamble - A short message to be shown before the exception
ex - The exception to display

advance

public void advance(com.fs.starfarer.api.campaign.SectorAPI sector,
                    com.fs.starfarer.api.campaign.LocationAPI location)
Automatically called by the game - don't call this manually.

Specified by:
advance in interface com.fs.starfarer.api.campaign.SpawnPointPlugin