Browse Source

Add new argument types for JSON and players

This patch adds two more possible argument types for Acedia's commands:
for arbitrary JSON values (argument types for any specific type of value
were already availabler before) and for players type of value (allowing
to specify a list of players with selectors, similar to how one does it
for targeted commands).

This patch does not actually implement parsing of these two arguments,
simply adds a possibility to declare them.
pull/8/head
Anton Tarasenko 2 years ago
parent
commit
40e7bb4b48
  1. 6
      sources/Commands/Command.uc
  2. 116
      sources/Commands/CommandDataBuilder.uc

6
sources/Commands/Command.uc

@ -97,7 +97,11 @@ enum ParameterType
// Parses into `HashTable` // Parses into `HashTable`
CPT_Object, CPT_Object,
// Parses into `ArrayList` // Parses into `ArrayList`
CPT_Array CPT_Array,
// Parses into any JSON value
CPT_JSON,
// Parses into an array of specified players
CPT_PLAYERS
}; };
/** /**

116
sources/Commands/CommandDataBuilder.uc

@ -973,6 +973,122 @@ public final function CommandDataBuilder ParamArrayList(
return self; return self;
} }
/**
* Adds new JSON value parameter (required or optional depends on whether
* `RequireTarget()` call happened) to the currently selected
* sub-command / option.
*
* Only fails if provided `name` is `none`.
*
* @param name Name of the parameter, will be copied
* (as it would appear in the generated help info).
* @param variableName Name of the variable that will store this
* parameter's value in `HashTable` after user's command input
* is parsed. Provided value will be copied.
* If left `none`, - will coincide with `name` parameter.
* @return Returns the caller `CommandDataBuilder` to allow for
* method chaining.
*/
public final function CommandDataBuilder ParamJSON(
BaseText name,
optional BaseText variableName)
{
if (name == none) {
return self;
}
PushParameter(NewParameter(name, CPT_JSON, false, variableName));
return self;
}
/**
* Adds new parameter for list of JSON values (required or optional depends on
* whether `RequireTarget()` call happened) to the currently selected
* sub-command / option.
*
* Only fails if provided `name` is `none`.
*
* @param name Name of the parameter, will be copied
* (as it would appear in the generated help info).
* @param variableName Name of the variable that will store this
* parameter's value in `HashTable` after user's command input
* is parsed. Provided value will be copied.
* If left `none`, - will coincide with `name` parameter.
* @return Returns the caller `CommandDataBuilder` to allow for
* method chaining.
*/
public final function CommandDataBuilder ParamJSONList(
BaseText name,
optional BaseText variableName)
{
if (name == none) {
return self;
}
PushParameter(NewParameter(name, CPT_JSON, true, variableName));
return self;
}
/**
* Adds new players value parameter (required or optional depends on whether
* `RequireTarget()` call happened) to the currently selected
* sub-command / option.
*
* Players parameter is a parameter that allows one to specify a list of
* players through special selectors, the same way one does for
* targeted commands.
*
* Only fails if provided `name` is `none`.
*
* @param name Name of the parameter, will be copied
* (as it would appear in the generated help info).
* @param variableName Name of the variable that will store this
* parameter's value in `HashTable` after user's command input
* is parsed. Provided value will be copied.
* If left `none`, - will coincide with `name` parameter.
* @return Returns the caller `CommandDataBuilder` to allow for
* method chaining.
*/
public final function CommandDataBuilder ParamPlayers(
BaseText name,
optional BaseText variableName)
{
if (name == none) {
return self;
}
PushParameter(NewParameter(name, CPT_PLAYERS, false, variableName));
return self;
}
/**
* Adds new parameter for list of players values (required or optional depends
* on whether `RequireTarget()` call happened) to the currently selected
* sub-command / option.
*
* Players parameter is a parameter that allows one to specify a list of
* players through special selectors, the same way one does for
* targeted commands.
*
* Only fails if provided `name` is `none`.
*
* @param name Name of the parameter, will be copied
* (as it would appear in the generated help info).
* @param variableName Name of the variable that will store this
* parameter's value in `HashTable` after user's command input
* is parsed. Provided value will be copied.
* If left `none`, - will coincide with `name` parameter.
* @return Returns the caller `CommandDataBuilder` to allow for
* method chaining.
*/
public final function CommandDataBuilder ParamPlayersList(
BaseText name,
optional BaseText variableName)
{
if (name == none) {
return self;
}
PushParameter(NewParameter(name, CPT_PLAYERS, true, variableName));
return self;
}
defaultproperties defaultproperties
{ {
errLongNameTooShort = (l=LOG_Error,m="Command `%1` is trying to register an option with a name that is way too short (<2 characters). Option will be discarded: %2") errLongNameTooShort = (l=LOG_Error,m="Command `%1` is trying to register an option with a name that is way too short (<2 characters). Option will be discarded: %2")

Loading…
Cancel
Save