/** * This class is meant to represent a command type: to create new command * one should extend it, then simply define required sub-commands/options and * parameters in `BuildData()` and use `Execute()` / `ExecuteFor()` to perform * necessary actions when command is executed by a player. * Copyright 2021 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * * Acedia is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License, or * (at your option) any later version. * * Acedia is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Acedia. If not, see . */ class Command extends AcediaObject dependson(Text); /** * Possible errors that can arise when producing `CommandCall` from user input */ enum ErrorType { // No error CET_None, // Bad parser was provided to parse user input // (this should not be possible) CET_BadParser, // Sub-command name was not specified or was incorrect // (this should not be possible) CET_NoSubCommands, // Required param for command / option was not specified CET_NoRequiredParam, CET_NoRequiredParamForOption, // Unknown option key was specified CET_UnknownOption, CET_UnknownShortOption, // Same option appeared twice in one command call CET_RepeatedOption, // Part of user's input could not be interpreted as a part of // command's call CET_UnusedCommandParameters, // In one short option specification (e.g. '-lah') several options // require parameters: this introduces ambiguity and is not allowed CET_MultipleOptionsWithParams, // (For targeted commands only) // Targets are specified incorrectly (or none actually specified) CET_IncorrectTargetList, CET_EmptyTargetList }; /** * Possible types of parameters. */ enum ParameterType { // Parses into `BoolBox` CPT_Boolean, // Parses into `IntBox` CPT_Integer, // Parses into `FloatBox` CPT_Number, // Parses into `Text` CPT_Text, // Special parameter that consumes the rest of the input into `Text` CPT_Remainder, // Parses into `AssociativeArray` CPT_Object, // Parses into `DynamicArray` CPT_Array }; /** * Possible forms a boolean variable can be used as. * Boolean parameter can define it's preferred format, which will be used * for help page generation. */ enum PreferredBooleanFormat { PBF_TrueFalse, PBF_EnableDisable, PBF_OnOff, PBF_YesNo }; // Defines a singular command parameter struct Parameter { // Display name (for the needs of help page displaying) var Text displayName; // Type of value this parameter would store var ParameterType type; // Does it take only a singular value or can it contain several of them, // written in a list var bool allowsList; // Variable name that will be used as a key to store parameter's value var Text variableName; // (For `CPT_Boolean` type variables only) - preferred boolean format, // used in help pages var PreferredBooleanFormat booleanFormat; }; // Defines a sub-command of a this command (specified as // " "). // Using sub-command is not optional, but if none defined // (in `BuildData()`) / specified by the player - an empty (`name.IsEmpty()`) // one is automatically created / used. struct SubCommand { // Cannot be `none` var Text name; // Can be `none` var Text description; var array required; var array optional; }; // Defines command's option (options are specified by "--long" or "-l"). // Options are independent from sub-commands. struct Option { var Text.Character shortName; var Text longName; var Text description; // Option can also have their own parameters var array required; var array optional; }; // Structure that defines what sub-commands and options command has // (and what parameters they take) struct Data { // Default command name that will be used unless Acedia is configured to // do otherwise var protected Text name; // Short summary of what command does (recommended to // keep it to 80 characters) var protected Text summary; var protected array subCommands; var protected array