Skip to content

Commit

Permalink
feat/inital: Add support for FGD file format (both Valve and Teamspen…
Browse files Browse the repository at this point in the history
… Unified FGD)
  • Loading branch information
Trico-Everfire committed Apr 9, 2024
1 parent eb0f543 commit 8b00593
Show file tree
Hide file tree
Showing 11 changed files with 10,909 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(SOURCEPP_USE_DMXPP "Build dmxpp library" ON)
option(SOURCEPP_USE_STUDIOMODELPP "Build studiomodelpp library" ON)
option(SOURCEPP_USE_VMFPP "Build vmfpp library" ON)
option(SOURCEPP_USE_FGDPP "Build fgdpp library" ON)
option(SOURCEPP_BUILD_TESTS "Build tests for enabled libraries" OFF)

option(SLOME_UNIFIED_FGD "Unified FDD are FGD Alterations made by TeamSpen's HammerAddons.
[https://github.com/TeamSpen210/HammerAddons/wiki/Unified-FGD]
and is fully backwards compatible with Valve's FGD standard." OFF)


if(SOURCEPP_USE_FGDPP AND FGDPP_UNIFIED_FGD)
add_definitions(-DFGDPP_UNIFIED_FGD)
endif ()

# BufferStream
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/thirdparty/bufferstream")
Expand Down Expand Up @@ -89,6 +98,14 @@ if(SOURCEPP_USE_VMFPP)
"${CMAKE_CURRENT_SOURCE_DIR}/src/vmfpp/vmfpp.cpp")
endif()

# fgdpp
if(SOURCEPP_USE_FGDPP)
add_pretty_parser(fgdpp SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/include/fgdpp/structs/entityproperties.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/fgdpp/fgdpp.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/fgdpp/fgdpp.cpp")
endif ()


# Tests, part 2
if(SOURCEPP_BUILD_TESTS)
Expand Down
177 changes: 177 additions & 0 deletions include/fgdpp/structs/entityproperties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@

#include <string_view>
#include <vector>

namespace fgdpp
{

enum ParseError {
NO_ERROR = 0,
TOKENIZATION_ERROR,
INVALID_DEFINITION,
INVALID_EQUALS,
INVALID_OPEN_BRACE,
INVALID_CLOSE_BRACE,
INVALID_OPEN_BRACKET,
INVALID_CLOSE_BRACKET,
INVALID_OPEN_PARENTHESIS,
INVALID_CLOSE_PARENTHESIS,
INVALID_COMMA,
INVALID_STRING,
INVALID_PLUS,
INVALID_LITERAL,
INVALID_COLUMN,
INVALID_NUMBER,
FAILED_TO_OPEN,
PREMATURE_EOF,
};

struct Range {
int start;
int end;
};

struct ParsingError
{
enum ParseError err;
int line;
Range span;

};

#ifdef FGDPP_UNIFIED_FGD
struct TagList
{
std::vector<std::string_view> tags;
};
#endif

struct ClassProperty
{
std::vector<std::string_view> properties;
};

struct ClassProperties
{
std::string_view name;
std::vector<ClassProperty> classProperties;
};

enum EntityIOPropertyType
{
t_string = 0,
t_integer,
t_float,
t_bool,
t_void,
t_script,
t_vector,
t_target_destination,
t_color255,
t_custom,

};

struct Choice
{
std::string_view value;
std::string_view displayName;
#ifdef FGDPP_UNIFIED_FGD
TagList tagList;
#endif
};

struct Flag
{
int value;
bool checked;
std::string_view displayName;
#ifdef FGDPP_UNIFIED_FGD
TagList tagList;
#endif
};

struct EntityProperties
{
std::string_view propertyName;
std::string_view type;
std::string_view displayName; // The following 3 are optional and may be empty as a result.
std::string_view defaultValue;
std::vector<std::string_view> propertyDescription;
bool readOnly;
bool reportable;

#ifdef FGDPP_UNIFIED_FGD
TagList tagList;
#endif

int choiceCount; // This is a special case if the EntityPropertyType is t_choices
std::vector<Choice> choices;

int flagCount; // This is a special case if the EntityPropertyType is t_flags
std::vector<Flag> flags;

};

enum IO
{
INPUT = 0,
OUTPUT,
};

struct InputOutput
{
std::string_view name;
std::vector<std::string_view> description;
IO putType;
std::string_view stringType;
EntityIOPropertyType type;
#ifdef FGDPP_UNIFIED_FGD
TagList tagList;
#endif

};
#ifdef FGDPP_UNIFIED_FGD
struct EntityResource
{
std::string_view key;
std::string_view value;
TagList tagList;
};
#endif

struct Entity
{
std::string_view type;
std::vector<ClassProperties> classProperties;
std::string_view entityName;
std::vector<std::string_view> entityDescription;
std::vector<EntityProperties> entityProperties;
std::vector<InputOutput> inputOutput;
#ifdef FGDPP_UNIFIED_FGD
std::vector<EntityResource> resources;
#endif
};

struct AutoVisGroupChild
{
std::string_view name;
std::vector<std::string_view> children;
};

struct AutoVIsGroup
{
std::string_view name;
struct std::vector<AutoVisGroupChild> children;
};

struct FGDFile
{
Range mapSize{0,0};
std::vector<Entity> entities;
std::vector<std::string_view> materialExclusions;
std::vector<std::string_view> includes;
std::vector<AutoVIsGroup> autoVisGroups;
};

}
24 changes: 24 additions & 0 deletions test/fgdpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <gtest/gtest.h>

#include <fgdpp/fgdpp.h>

#include "Helpers.h"

using namespace fgdpp;

TEST(fgdpp, parseBasePortal2) {
FGDParser* fgdFile = new FGDParser(ASSET_ROOT "fgdpp/portal2.fgd", true);
ASSERT_TRUE(fgdFile);
ASSERT_TRUE(fgdFile->parseError.err == NO_ERROR);
}

//adds support for Spen's Unified FGD format changes.
#ifdef FGDPP_UNIFIED_FGD
TEST(fgdpp, parseUnifiedFGD) {

FGDParser* fgdFile = new FGDParser(ASSET_ROOT "fgdpp/unified/game_ui.fgd", true);
ASSERT_TRUE(fgdFile);
std::cout << fgdFile->parseError.err << std::endl;
ASSERT_TRUE(fgdFile->parseError.err == NO_ERROR);
}
#endif
Loading

0 comments on commit 8b00593

Please sign in to comment.