1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 // The structs in this file relate to *Options.lua files 4 // They are used for Mods and Skirmish AIs for example. 5 // This file is used (at least) by unitsync and the engine 6 7 #ifndef _OPTION_H 8 #define _OPTION_H 9 10 #include "System/FileSystem/VFSModes.h" 11 12 #include <string> 13 #include <vector> 14 #include <set> 15 #include <cfloat> // for FLT_MAX 16 #include <climits> // for INT_MAX 17 18 /** 19 * @brief Available mod/map/ai option types 20 * @sa GetOptionType 21 */ 22 enum OptionType { 23 opt_error = 0, ///< error 24 opt_bool = 1, ///< boolean option 25 opt_list = 2, ///< list option (e.g. combobox) 26 opt_number = 3, ///< numeric option (e.g. spinner / slider) 27 opt_string = 4, ///< string option (e.g. textbox) 28 opt_section = 5 ///< option section (e.g. groupbox) 29 }; 30 31 32 struct OptionListItem { 33 std::string key; 34 std::string name; 35 std::string desc; 36 }; 37 38 39 struct Option { OptionOption40 Option() 41 : typeCode(opt_error) 42 , boolDef(false) 43 , numberDef(0.0f) 44 , numberMin(0.0f) 45 , numberMax(FLT_MAX) 46 , numberStep(1.0f) 47 , stringMaxLen(INT_MAX) 48 {} 49 50 std::string key; 51 std::string scope; 52 std::string name; 53 std::string desc; 54 std::string section; 55 std::string style; 56 57 std::string type; ///< "bool", "number", "string", "list", "section" 58 59 OptionType typeCode; 60 61 bool boolDef; 62 63 float numberDef; 64 float numberMin; 65 float numberMax; 66 float numberStep; ///< aligned to numberDef 67 68 std::string stringDef; 69 int stringMaxLen; 70 71 std::string listDef; 72 std::vector<OptionListItem> list; 73 }; 74 75 std::string option_getDefString(const Option& option); 76 77 void option_parseOptions( 78 std::vector<Option>& options, 79 const std::string& fileName, 80 const std::string& fileModes = SPRING_VFS_RAW, 81 const std::string& accessModes = SPRING_VFS_RAW, 82 std::set<std::string>* optionsSet = NULL); 83 84 void option_parseOptionsLuaString( 85 std::vector<Option>& options, 86 const std::string& optionsLuaString, 87 const std::string& accessModes = SPRING_VFS_RAW, 88 std::set<std::string>* optionsSet = NULL); 89 90 void option_parseMapOptions( 91 std::vector<Option>& options, 92 const std::string& fileName, 93 const std::string& mapName, 94 const std::string& fileModes = SPRING_VFS_RAW, 95 const std::string& accessModes = SPRING_VFS_RAW, 96 std::set<std::string>* optionsSet = NULL); 97 98 #endif // _OPTION_H 99