Skip to main content

FlixelDebugCommandArgs

View source

class

org.flixelgdx.debug.FlixelDebugCommandArgs

public final class 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[])

public FlixelDebugCommandArgs(String[] args)

Parameters:

NameDescription
argsThe positional argument tokens (must not be null; pass new String[0] for none).

Methods

size()

public int size()

Returns the number of positional arguments.


isEmpty()

public boolean isEmpty()

Returns true if there are no positional arguments.


getString(int)

public String getString(int index)

Returns the raw token at index, or an empty String if the index is out of range.

Parameters:

NameDescription
indexThe zero-based argument index.

Returns: The raw token, or "" if the index is invalid.


getString(int, String)

public String getString(int index, String defaultValue)

Returns the raw token at index, or defaultValue if the index is out of range.

Parameters:

NameDescription
indexThe zero-based argument index.
defaultValueValue to return when the index is invalid.

Returns: The raw token, or defaultValue if the index is invalid.


getInt(int, int)

public int getInt(int index, int defaultValue)

Parses the token at index as an integer, returning defaultValue on a missing argument or a parse failure.

Parameters:

NameDescription
indexThe zero-based argument index.
defaultValueThe value to return on miss or parse error.

Returns: The parsed integer, or defaultValue.


getLong(int, long)

public long getLong(int index, long defaultValue)

Parses the token at index as a long, returning defaultValue on a missing argument or a parse failure.

Parameters:

NameDescription
indexThe zero-based argument index.
defaultValueThe value to return on miss or parse error.

Returns: The parsed long, or defaultValue.


getFloat(int, float)

public float getFloat(int index, float defaultValue)

Parses the token at index as a float, returning defaultValue on a missing argument or a parse failure.

Parameters:

NameDescription
indexThe zero-based argument index.
defaultValueThe value to return on miss or parse error.

Returns: The parsed float, or defaultValue.


getDouble(int, double)

public double getDouble(int index, double defaultValue)

Parses the token at index as a double, returning defaultValue on a missing argument or a parse failure.

Parameters:

NameDescription
indexThe zero-based argument index.
defaultValueThe value to return on miss or parse error.

Returns: The parsed double, or defaultValue.


getBoolean(int, boolean)

public boolean getBoolean(int index, boolean defaultValue)

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:

NameDescription
indexThe zero-based argument index.
defaultValueThe value to return on miss or parse failure.

Returns: The parsed boolean, or defaultValue.


getRawArgs()

public String[] 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.