|  | 
| 1 | 1 | #pragma once | 
| 2 | 2 | 
 | 
|  | 3 | +#include <list> | 
| 3 | 4 | #include <string> | 
| 4 | 5 | #include <string_view> | 
|  | 6 | +#include <unordered_map> | 
| 5 | 7 | #include <vector> | 
| 6 | 8 | 
 | 
| 7 |  | -#include "structs/EntityProperties.h" | 
|  | 9 | +#include <sourcepp/math/Vector.h> | 
|  | 10 | + | 
|  | 11 | +class BufferStream; | 
|  | 12 | +class BufferStreamReadOnly; | 
| 8 | 13 | 
 | 
| 9 | 14 | namespace fgdpp { | 
| 10 | 15 | 
 | 
| 11 | 16 | class FGD { | 
| 12 |  | -	std::string rawFGDFile; | 
| 13 |  | - | 
| 14 |  | -	//TOKENIZER | 
| 15 | 17 | public: | 
| 16 |  | -	enum TokenType { | 
| 17 |  | -		COMMENT = 0,       // // | 
| 18 |  | -		DEFINITION,        // @something | 
| 19 |  | -		EQUALS,            // = | 
| 20 |  | -		OPEN_BRACE,        // { | 
| 21 |  | -		CLOSE_BRACE,       // } | 
| 22 |  | -		OPEN_BRACKET,      // [ | 
| 23 |  | -		CLOSE_BRACKET,     // ] | 
| 24 |  | -		OPEN_PARENTHESIS,  // ( | 
| 25 |  | -		CLOSE_PARENTHESIS, // ) | 
| 26 |  | -		COMMA,             // , | 
| 27 |  | -		STRING,            // "something" | 
| 28 |  | -		PLUS,              // + | 
| 29 |  | -		LITERAL,           // anything that isn't any of the other tokens. | 
| 30 |  | -		COLUMN,            // : | 
| 31 |  | -		NUMBER,            // numbers -200000 ... 0 ... 2000000 | 
|  | 18 | +	struct Entity { | 
|  | 19 | +		struct ClassProperty { | 
|  | 20 | +			std::string_view name; | 
|  | 21 | +			std::string_view arguments; | 
|  | 22 | +		}; | 
|  | 23 | + | 
|  | 24 | +		struct Field { | 
|  | 25 | +			std::string_view name; | 
|  | 26 | +			std::string_view valueType; | 
|  | 27 | +			std::string_view displayName; | 
|  | 28 | +			std::string_view valueDefault; | 
|  | 29 | +			std::string_view description; | 
|  | 30 | +		}; | 
|  | 31 | + | 
|  | 32 | +		struct FieldChoices { | 
|  | 33 | +			struct Choice { | 
|  | 34 | +				std::string_view value; | 
|  | 35 | +				std::string_view displayName; | 
|  | 36 | +			}; | 
|  | 37 | + | 
|  | 38 | +			std::string_view name; | 
|  | 39 | +			std::string_view displayName; | 
|  | 40 | +			std::string_view valueDefault; | 
|  | 41 | +			std::string_view description; | 
|  | 42 | +			std::vector<Choice> choices; | 
|  | 43 | +		}; | 
|  | 44 | + | 
|  | 45 | +		struct FieldFlags { | 
|  | 46 | +			struct Flag { | 
|  | 47 | +				std::string_view value; | 
|  | 48 | +				std::string_view displayName; | 
|  | 49 | +				std::string_view enabledByDefault; | 
|  | 50 | +				std::string_view description; | 
|  | 51 | +			}; | 
|  | 52 | + | 
|  | 53 | +			std::string_view name; | 
|  | 54 | +			std::vector<Flag> flags; | 
|  | 55 | +		}; | 
|  | 56 | + | 
|  | 57 | +		struct IO { | 
|  | 58 | +			std::string_view name; | 
|  | 59 | +			std::string_view valueType; | 
|  | 60 | +			std::string_view description; | 
|  | 61 | +		}; | 
|  | 62 | + | 
|  | 63 | +		std::string_view classType; | 
|  | 64 | +		std::vector<ClassProperty> classProperties; | 
|  | 65 | + | 
|  | 66 | +		std::string_view description; | 
|  | 67 | + | 
|  | 68 | +		std::vector<Field> fields; | 
|  | 69 | +		std::vector<FieldChoices> fieldsWithChoices; | 
|  | 70 | +		std::vector<FieldFlags> fieldsWithFlags; | 
|  | 71 | +		std::vector<IO> inputs; | 
|  | 72 | +		std::vector<IO> outputs; | 
| 32 | 73 | 	}; | 
| 33 | 74 | 
 | 
| 34 |  | -	struct Token { | 
| 35 |  | -		TokenType type; | 
| 36 |  | -		Range range; | 
| 37 |  | -		std::string_view string; | 
| 38 |  | -		int line; | 
| 39 |  | -		ParseError associatedError; | 
|  | 75 | +	struct AutoVisGroup { | 
|  | 76 | +		std::string_view parentName; | 
|  | 77 | +		std::string_view name; | 
|  | 78 | +		std::vector<std::string_view> entities; | 
| 40 | 79 | 	}; | 
| 41 | 80 | 
 | 
| 42 |  | -	std::vector<Token> tokenList; | 
|  | 81 | +	FGD() = default; | 
| 43 | 82 | 
 | 
| 44 |  | -public: | 
| 45 |  | -	FGD(std::string_view path, bool parseIncludes); | 
|  | 83 | +	explicit FGD(const std::string& fgdPath); | 
| 46 | 84 | 
 | 
| 47 |  | -private: | 
| 48 |  | -	bool TokenizeFile(); | 
|  | 85 | +	/** | 
|  | 86 | +	 * Can be called multiple times in succession to load multiple FGD files. | 
|  | 87 | +	 * The FGD file data will be merged with previously loaded data. | 
|  | 88 | +	 * @param fgdPath The path to the FGD to load | 
|  | 89 | +	 */ | 
|  | 90 | +	void load(const std::string& fgdPath); | 
| 49 | 91 | 
 | 
| 50 |  | -	//PARSER. | 
| 51 |  | -public: | 
| 52 |  | -	FGDFile FGDFileContents; | 
| 53 |  | -	ParsingError parseError{ParseError::NO_ERROR, 0, {0, 0}}; | 
|  | 92 | +	[[nodiscard]] int getVersion() const; | 
|  | 93 | + | 
|  | 94 | +	[[nodiscard]] sourcepp::math::Vec2i getMapSize() const; | 
|  | 95 | + | 
|  | 96 | +	[[nodiscard]] const std::unordered_map<std::string_view, Entity>& getEntities() const; | 
|  | 97 | + | 
|  | 98 | +	[[nodiscard]] const std::vector<std::string_view>& getMaterialExclusionDirs() const; | 
|  | 99 | + | 
|  | 100 | +	[[nodiscard]] const std::vector<AutoVisGroup>& getAutoVisGroups() const; | 
|  | 101 | + | 
|  | 102 | +	explicit operator bool() const; | 
|  | 103 | + | 
|  | 104 | +private: | 
|  | 105 | +	void readEntities(BufferStreamReadOnly& stream, const std::string& path, std::vector<std::string>& seenPaths); | 
| 54 | 106 | 
 | 
| 55 |  | -	bool ParseFile(); | 
|  | 107 | +	std::list<std::string> backingData; | 
| 56 | 108 | 
 | 
| 57 |  | -#ifdef FGDPP_UNIFIED_FGD | 
| 58 |  | -	bool TagListDelimiter(std::vector<Token>::const_iterator& iter, TagList& tagList); | 
| 59 |  | -#endif | 
|  | 109 | +	int version = 0; | 
|  | 110 | +	sourcepp::math::Vec2i mapSize{}; | 
|  | 111 | +	std::unordered_map<std::string_view, Entity> entities; | 
|  | 112 | +	std::vector<std::string_view> materialExclusionDirs; | 
|  | 113 | +	std::vector<AutoVisGroup> autoVisGroups; | 
| 60 | 114 | }; | 
| 61 | 115 | 
 | 
| 62 | 116 | } // namespace fgdpp | 
0 commit comments