FlixelDebugCommandArgs
View sourceclass
org.flixelgdx.debug.FlixelDebugCommandArgs
Lightweight wrapper around the positional arguments passed to a custom debug console command. Provides typed accessors with default values so command handlers can stay free of boilerplate parsing logic.
Each command line is split on whitespace; the first token is the command name and the remaining tokens are wrapped in this object. Tokens are kept as raw String values and parsed lazily when a typed getter is called.
Example
Flixel.debug.registerCommand("setScale", args -> {
String key = args.getString(0, "");
float scale = args.getFloat(1, 1f);
// ... do something with key and scale ...
});
Out-of-range indices return the default value (or an empty String for FlixelDebugCommandArgs.getString(int)). Bad numeric strings also fall back to the default. This keeps commands resilient to typos in the console without throwing.
Constructors
FlixelDebugCommandArgs(String[])
Parameters:
| Name | Description |
|---|---|
args | The positional argument tokens (must not be null; pass new String[0] for none). |
Methods
size()
Returns the number of positional arguments.
isEmpty()
Returns true if there are no positional arguments.
getString(int)
Returns the raw token at index, or an empty String if the index is out of range.
Parameters:
| Name | Description |
|---|---|
index | The zero-based argument index. |
Returns: The raw token, or "" if the index is invalid.
getString(int, String)
Returns the raw token at index, or defaultValue if the index is out of range.
Parameters:
| Name | Description |
|---|---|
index | The zero-based argument index. |
defaultValue | Value to return when the index is invalid. |
Returns: The raw token, or defaultValue if the index is invalid.
getInt(int, int)
Parses the token at index as an integer, returning defaultValue on a missing argument or a parse failure.
Parameters:
| Name | Description |
|---|---|
index | The zero-based argument index. |
defaultValue | The value to return on miss or parse error. |
Returns: The parsed integer, or defaultValue.
getLong(int, long)
Parses the token at index as a long, returning defaultValue on a missing argument or a parse failure.
Parameters:
| Name | Description |
|---|---|
index | The zero-based argument index. |
defaultValue | The value to return on miss or parse error. |
Returns: The parsed long, or defaultValue.
getFloat(int, float)
Parses the token at index as a float, returning defaultValue on a missing argument or a parse failure.
Parameters:
| Name | Description |
|---|---|
index | The zero-based argument index. |
defaultValue | The value to return on miss or parse error. |
Returns: The parsed float, or defaultValue.
getDouble(int, double)
Parses the token at index as a double, returning defaultValue on a missing argument or a parse failure.
Parameters:
| Name | Description |
|---|---|
index | The zero-based argument index. |
defaultValue | The value to return on miss or parse error. |
Returns: The parsed double, or defaultValue.
getBoolean(int, boolean)
Parses the token at index as a boolean. Accepts "true", "false", "1", "0", "yes", "no", "on", and "off" (case-insensitive). Returns defaultValue on a missing argument or unrecognized token.
Parameters:
| Name | Description |
|---|---|
index | The zero-based argument index. |
defaultValue | The value to return on miss or parse failure. |
Returns: The parsed boolean, or defaultValue.
getRawArgs()
Returns the underlying token array. The returned array is shared with this instance and must not be modified. Useful for handlers that want to forward the raw tokens elsewhere.
Returns: The shared backing array of tokens.