Major cleanup.

Moved to namespace
Cleanup includes
This commit is contained in:
Antoine Pilote
2021-07-11 18:56:44 -04:00
parent f77bef6b28
commit 0c6ed48bbd
174 changed files with 11772 additions and 11296 deletions

View File

@@ -1,5 +1,4 @@
#pragma once
#include "BaseClass.h"
#include "ClassProperty.h"
#include <string>
#include <vector>

View File

@@ -1,12 +1,15 @@
#pragma once
#include "FGDClass.h"
#include <string>
class FGDSerializer
{
public:
static bool BeginFGDFile(const std::string path);
static bool SerializeClass(FGDClass fgdClass);
static bool SerializeBrush(FGDBrushEntity fgdClass);
static bool EndFGDFile();
};
namespace Nuake {
class FGDSerializer
{
public:
static bool BeginFGDFile(const std::string path);
static bool SerializeClass(FGDClass fgdClass);
static bool SerializeBrush(FGDBrushEntity fgdClass);
static bool EndFGDFile();
};
}

View File

@@ -1,26 +1,28 @@
#include "FGDClass.h"
FGDClass::FGDClass(FGDClassType type, const std::string& name, const std::string& desc)
{
Type = type;
Name = name;
Description = desc;
}
void FGDClass::AddProperty(ClassProperty prop)
{
Properties.push_back(prop);
}
void FGDClass::RemoveProperty(const std::string name)
{
int position = 0;
for (auto& p : Properties)
namespace Nuake {
FGDClass::FGDClass(FGDClassType type, const std::string& name, const std::string& desc)
{
if (p.name == name)
Properties.erase(Properties.begin() + position);
Type = type;
Name = name;
Description = desc;
}
position++;
void FGDClass::AddProperty(ClassProperty prop)
{
Properties.push_back(prop);
}
void FGDClass::RemoveProperty(const std::string name)
{
int position = 0;
for (auto& p : Properties)
{
if (p.name == name)
Properties.erase(Properties.begin() + position);
position++;
}
}
}

View File

@@ -4,56 +4,56 @@
#include <string>
#include <vector>
class FGDBaseEntity
{
public:
std::string Name;
std::vector<ClassProperty> Properties;
};
class FGDBrushEntity : ISerializable
{
public:
std::string Name;
std::string Description;
bool Visible = false;
bool Solid = false;
bool IsTrigger = false;
std::string Script = "";
std::string Class = "";
std::vector<ClassProperty> Properties;
FGDBrushEntity()
namespace Nuake {
class FGDBaseEntity
{
Name = "";
Description = "";
}
public:
std::string Name;
std::vector<ClassProperty> Properties;
};
FGDBrushEntity(const std::string& name)
{
Name = name;
Description = "";
}
json Serialize() override
class FGDBrushEntity : ISerializable
{
BEGIN_SERIALIZE();
public:
std::string Name;
std::string Description;
bool Visible = false;
bool Solid = false;
bool IsTrigger = false;
std::string Script = "";
std::string Class = "";
std::vector<ClassProperty> Properties;
FGDBrushEntity()
{
Name = "";
Description = "";
}
FGDBrushEntity(const std::string& name)
{
Name = name;
Description = "";
}
json Serialize() override
{
BEGIN_SERIALIZE();
SERIALIZE_VAL(Name);
SERIALIZE_VAL(Description);
SERIALIZE_VAL(Visible);
SERIALIZE_VAL(Visible);
SERIALIZE_VAL(Solid);
SERIALIZE_VAL(IsTrigger);
SERIALIZE_VAL(Script);
SERIALIZE_VAL(Class);
END_SERIALIZE();
}
END_SERIALIZE();
}
bool Deserialize(const std::string& str) override
{
BEGIN_DESERIALIZE();
bool Deserialize(const std::string& str) override
{
BEGIN_DESERIALIZE();
Name = j["Name"];
Description = j["Description"];
Visible = j["Visible"];
@@ -61,46 +61,47 @@ public:
IsTrigger = j["IsTrigger"];
Script = j["Script"];
Class = j["Class"];
return true;
}
return true;
}
FGDBaseEntity BaseClass;
};
FGDBaseEntity BaseClass;
};
class FGDPointEntity : ISerializable
{
public:
std::string Name;
std::string Description;
std::string Prefab;
std::vector<ClassProperty> Properties;
FGDBaseEntity BaseClass;
json Serialize() override
class FGDPointEntity : ISerializable
{
BEGIN_SERIALIZE();
public:
std::string Name;
std::string Description;
std::string Prefab;
std::vector<ClassProperty> Properties;
FGDBaseEntity BaseClass;
json Serialize() override
{
BEGIN_SERIALIZE();
SERIALIZE_VAL(Name);
SERIALIZE_VAL(Description);
SERIALIZE_VAL(Prefab);
END_SERIALIZE();
}
END_SERIALIZE();
}
bool Deserialize(const std::string& str) override
{
return true;
}
};
bool Deserialize(const std::string& str) override
{
return true;
}
};
class FGDClass {
public:
FGDClassType Type;
std::string Name;
std::string Description;
std::vector<ClassProperty> Properties;
class FGDClass {
public:
FGDClassType Type;
std::string Name;
std::string Description;
std::vector<ClassProperty> Properties;
FGDClass(FGDClassType type, const std::string& name, const std::string& desc);
FGDClass(FGDClassType type, const std::string& name, const std::string& desc);
void AddProperty(ClassProperty prop);
void RemoveProperty(const std::string name);
};
void AddProperty(ClassProperty prop);
void RemoveProperty(const std::string name);
};
}

View File

@@ -3,96 +3,98 @@
#include <src/Core/FileSystem.h>
#include "Engine.h"
FGDFile::FGDFile(const std::string path)
{
this->Path = path;
namespace Nuake {
FGDFile::FGDFile(const std::string path)
{
this->Path = path;
this->BaseEntities = std::vector<FGDBaseEntity>();
this->BrushEntities = std::vector<FGDBrushEntity>();
this->PointEntities = std::vector<FGDPointEntity>();
}
this->BaseEntities = std::vector<FGDBaseEntity>();
this->BrushEntities = std::vector<FGDBrushEntity>();
this->PointEntities = std::vector<FGDPointEntity>();
}
FGDFile::FGDFile()
{
this->Path = "";
this->BaseEntities = std::vector<FGDBaseEntity>();
this->BrushEntities = std::vector<FGDBrushEntity>();
this->PointEntities = std::vector<FGDPointEntity>();
FGDFile::FGDFile()
{
this->Path = "";
this->BaseEntities = std::vector<FGDBaseEntity>();
this->BrushEntities = std::vector<FGDBrushEntity>();
this->PointEntities = std::vector<FGDPointEntity>();
// TODO: Remove this, debugging stuff.
FGDPointEntity newEnt;
newEnt.Name = "Light";
newEnt.Description = "A Nuake PBR light";
this->PointEntities.push_back(newEnt);
}
// TODO: Remove this, debugging stuff.
FGDPointEntity newEnt;
newEnt.Name = "Light";
newEnt.Description = "A Nuake PBR light";
this->PointEntities.push_back(newEnt);
}
bool FGDFile::Save()
{
// Write to file.
FileSystem::BeginWriteFile(FileSystem::Root + Path);
bool FGDFile::Save()
{
// Write to file.
FileSystem::BeginWriteFile(FileSystem::Root + Path);
FileSystem::WriteLine(Serialize().dump(4));
FileSystem::EndWriteFile();
return true;
}
bool FGDFile::SaveAs()
{
return false;
}
void FGDFile::AddClass(FGDClass fgdClass)
{
//this->Classes.push_back(fgdClass);
}
void FGDFile::RemoveClass(const std::string& name)
{
//int idx = 0;
//for (auto& c : Classes)
//{
//if (c.Name == name)
//Classes.erase(Classes.begin() + idx);
//idx++;
//}
}
// Exports the FGD data into an fgd file that Trenchbroom can read.
// Should be exported in the Trenchbroom directory directly. /Games/project_name
bool FGDFile::Export()
{
Ref<Project> project = Engine::GetProject();
std::string path = project->TrenchbroomPath + "games/" + project->Name + "/" + project->Name + ".fgd";
FGDSerializer::BeginFGDFile(path);
for (auto& b : BaseEntities)
{
FileSystem::EndWriteFile();
return true;
}
for (auto& p : PointEntities)
bool FGDFile::SaveAs()
{
return false;
}
for (auto& b : BrushEntities)
void FGDFile::AddClass(FGDClass fgdClass)
{
FGDSerializer::SerializeBrush(b);
//this->Classes.push_back(fgdClass);
}
//for(auto& c : Classes)
// FGDSerializer::SerializeClass(c);
FGDSerializer::EndFGDFile();
void FGDFile::RemoveClass(const std::string& name)
{
//int idx = 0;
//for (auto& c : Classes)
//{
//if (c.Name == name)
//Classes.erase(Classes.begin() + idx);
return true;
}
//idx++;
//}
}
// Exports the FGD data into an fgd file that Trenchbroom can read.
// Should be exported in the Trenchbroom directory directly. /Games/project_name
bool FGDFile::Export()
{
Ref<Project> project = Engine::GetProject();
std::string path = project->TrenchbroomPath + "games/" + project->Name + "/" + project->Name + ".fgd";
FGDSerializer::BeginFGDFile(path);
for (auto& b : BaseEntities)
{
}
for (auto& p : PointEntities)
{
}
for (auto& b : BrushEntities)
{
FGDSerializer::SerializeBrush(b);
}
//for(auto& c : Classes)
// FGDSerializer::SerializeClass(c);
FGDSerializer::EndFGDFile();
return true;
}
}

View File

@@ -4,93 +4,95 @@
#include <string>
#include <vector>
enum class EntityType
{
Brush, Point, Base, None
};
class FGDFile : ISerializable{
public:
std::string Path;
std::vector<FGDPointEntity> PointEntities;
std::vector<FGDBrushEntity> BrushEntities;
std::vector<FGDBaseEntity> BaseEntities;
FGDFile(const std::string path);
FGDFile();
bool Export();
bool Save();
bool SaveAs();
void AddClass(FGDClass fgdClass);
void RemoveClass(const std::string& name);
json Serialize() override
namespace Nuake {
enum class EntityType
{
BEGIN_SERIALIZE();
int i = 0;
for (auto& c : this->BrushEntities)
{
j["BrushEntities"][i] = c.Serialize();
i++;
}
Brush, Point, Base, None
};
i = 0;
for (auto& c : this->PointEntities)
{
j["PointEntities"][i] = c.Serialize();
i++;
}
END_SERIALIZE();
}
class FGDFile : ISerializable {
public:
std::string Path;
bool Deserialize(const std::string& str)
{
BEGIN_DESERIALIZE();
std::vector<FGDPointEntity> PointEntities;
std::vector<FGDBrushEntity> BrushEntities;
std::vector<FGDBaseEntity> BaseEntities;
if (j.contains("BrushEntities"))
FGDFile(const std::string path);
FGDFile();
bool Export();
bool Save();
bool SaveAs();
void AddClass(FGDClass fgdClass);
void RemoveClass(const std::string& name);
json Serialize() override
{
for (auto& brush : j["BrushEntities"])
BEGIN_SERIALIZE();
int i = 0;
for (auto& c : this->BrushEntities)
{
FGDBrushEntity brushEntity = FGDBrushEntity();
brushEntity.Deserialize(brush.dump());
BrushEntities.push_back(brushEntity);
j["BrushEntities"][i] = c.Serialize();
i++;
}
i = 0;
for (auto& c : this->PointEntities)
{
j["PointEntities"][i] = c.Serialize();
i++;
}
END_SERIALIZE();
}
bool Deserialize(const std::string& str)
{
BEGIN_DESERIALIZE();
if (j.contains("BrushEntities"))
{
for (auto& brush : j["BrushEntities"])
{
FGDBrushEntity brushEntity = FGDBrushEntity();
brushEntity.Deserialize(brush.dump());
BrushEntities.push_back(brushEntity);
}
}
if (j.contains("PointEntities"))
{
}
return true;
}
FGDBrushEntity& GetBrushEntity(const std::string& name)
{
for (auto& b : BrushEntities)
{
if (b.Name == name)
return b;
}
}
if (j.contains("PointEntities"))
EntityType GetTypeOfEntity(const std::string& className)
{
for (auto& b : BrushEntities)
{
if (b.Name == className)
return EntityType::Brush;
}
for (auto& p : PointEntities)
{
if (p.Name == className)
return EntityType::Point;
}
return EntityType::None;
}
return true;
}
FGDBrushEntity& GetBrushEntity(const std::string& name)
{
for (auto& b : BrushEntities)
{
if (b.Name == name)
return b;
}
}
EntityType GetTypeOfEntity(const std::string& className)
{
for (auto& b : BrushEntities)
{
if (b.Name == className)
return EntityType::Brush;
}
for (auto& p : PointEntities)
{
if (p.Name == className)
return EntityType::Point;
}
return EntityType::None;
}
};
};
}

View File

@@ -1,96 +1,96 @@
#include "FDGSerializer.h"
#include <src\Core\FileSystem.h>
namespace Nuake {
bool FGDSerializer::BeginFGDFile(const std::string path)
{
FileSystem::BeginWriteFile(path);
return true;
}
bool FGDSerializer::BeginFGDFile(const std::string path)
{
FileSystem::BeginWriteFile(path);
return true;
}
bool FGDSerializer::SerializeClass(FGDClass fgdClass)
{
std::string line = "@";
if (fgdClass.Type == FGDClassType::Point)
line += "PointClass = ";
else if (fgdClass.Type == FGDClassType::Brush)
line += "SolidClass = ";
else // error.
return true;
line += fgdClass.Name + " : \"" + fgdClass.Description + "\"";
bool FGDSerializer::SerializeClass(FGDClass fgdClass)
{
std::string line = "@";
// Exit early
if (fgdClass.Properties.size() == 0)
{
line += " [] \n";
FileSystem::WriteLine(line);
return true;
}
if (fgdClass.Type == FGDClassType::Point)
line += "PointClass = ";
else if (fgdClass.Type == FGDClassType::Brush)
// Properties here.
line += "\n [ \n";
for (auto& p : fgdClass.Properties)
{
// E.g: myProp(integer) : "description"
line += " "; // Tabulation
line += p.name;
line += "(";
if (p.type == ClassPropertyType::Integer)
line += "integer";
line += ") : ";
line += "\"" + p.description + "\"";
line += "\n";
}
line += "]";
FileSystem::WriteLine(line);
return true;
}
bool FGDSerializer::SerializeBrush(FGDBrushEntity fgdClass)
{
std::string line = "@";
line += "SolidClass = ";
else // error.
return true;
line += fgdClass.Name + " : \"" + fgdClass.Description + "\"";
line += fgdClass.Name + " : \"" + fgdClass.Description + "\"";
// Exit early
if (fgdClass.Properties.size() == 0)
{
line += " [] \n";
FileSystem::WriteLine(line);
return true;
}
// Properties here.
line += "\n [ \n";
for (auto& p : fgdClass.Properties)
{
// E.g: myProp(integer) : "description"
line += " "; // Tabulation
line += p.name;
line += "(";
if (p.type == ClassPropertyType::Integer)
line += "integer";
line += ") : ";
line += "\"" + p.description + "\"";
line += "\n";
}
line += "]";
// Exit early
if (fgdClass.Properties.size() == 0)
{
line += " [] \n";
FileSystem::WriteLine(line);
return true;
return false;
}
// Properties here.
line += "\n [ \n";
for (auto& p : fgdClass.Properties)
bool FGDSerializer::EndFGDFile()
{
// E.g: myProp(integer) : "description"
line += " "; // Tabulation
line += p.name;
line += "(";
if (p.type == ClassPropertyType::Integer)
line += "integer";
line += ") : ";
line += "\"" + p.description + "\"";
line += "\n";
FileSystem::EndWriteFile();
return false;
}
line += "]";
FileSystem::WriteLine(line);
return true;
}
bool FGDSerializer::SerializeBrush(FGDBrushEntity fgdClass)
{
std::string line = "@";
line += "SolidClass = ";
line += fgdClass.Name + " : \"" + fgdClass.Description + "\"";
// Exit early
if (fgdClass.Properties.size() == 0)
{
line += " [] \n";
FileSystem::WriteLine(line);
return true;
}
// Properties here.
line += "\n [ \n";
for (auto& p : fgdClass.Properties)
{
// E.g: myProp(integer) : "description"
line += " "; // Tabulation
line += p.name;
line += "(";
if (p.type == ClassPropertyType::Integer)
line += "integer";
line += ") : ";
line += "\"" + p.description + "\"";
line += "\n";
}
line += "]";
FileSystem::WriteLine(line);
return false;
}
bool FGDSerializer::EndFGDFile()
{
FileSystem::EndWriteFile();
return false;
}

View File

@@ -4,138 +4,143 @@
#include <fstream>
#include <streambuf>
#include "../Core/Logger.h"
Project::Project(const std::string Name, const std::string Description, const std::string& FullPath, const std::string& defaultScenePath )
{
this->Name = Name;
this->Description = Description;
this->FullPath = FullPath;
this->TrenchbroomPath = "";
if (defaultScenePath != "")
namespace Nuake
{
Project::Project(const std::string Name, const std::string Description, const std::string& FullPath, const std::string& defaultScenePath)
{
Ref<Scene> scene = CreateRef<Scene>();
scene->Deserialize(defaultScenePath);
this->Name = Name;
this->Description = Description;
this->FullPath = FullPath;
this->TrenchbroomPath = "";
if (defaultScenePath != "")
{
Ref<Scene> scene = CreateRef<Scene>();
scene->Deserialize(defaultScenePath);
}
this->EntityDefinitionsFile = CreateRef<FGDFile>();
SaveAs(FullPath);
}
this->EntityDefinitionsFile = CreateRef<FGDFile>();
Project::Project()
{
this->Name = "";
this->Description = "";
this->FullPath = "";
this->TrenchbroomPath = "";
SaveAs(FullPath);
}
this->EntityDefinitionsFile = CreateRef<FGDFile>();
}
Project::Project()
{
this->Name = "";
this->Description = "";
this->FullPath = "";
this->TrenchbroomPath = "";
void Project::Save()
{
SaveAs(this->FullPath);
}
this->EntityDefinitionsFile = CreateRef<FGDFile>();
}
void Project::SaveAs(const std::string FullPath)
{
json j = Serialize();
std::string serialized_string = j.dump();
void Project::Save()
{
SaveAs(this->FullPath);
}
void Project::SaveAs(const std::string FullPath)
{
json j = Serialize();
std::string serialized_string = j.dump();
// TODO: Use file interface here...
// Write to file.
std::ofstream projectFile;
// TODO: Use file interface here...
// Write to file.
std::ofstream projectFile;
projectFile.open(FullPath);
projectFile << serialized_string;
projectFile.close();
}
projectFile.close();
}
Ref<Project> Project::New(const std::string Name, const std::string Description, const std::string FullPath)
{
if (Name == "")
return nullptr;
Ref<Project> Project::New(const std::string Name, const std::string Description, const std::string FullPath)
{
if (Name == "")
return nullptr;
return CreateRef<Project>(Name, Description, FullPath);
}
return CreateRef<Project>(Name, Description, FullPath);
}
Ref<Project> Project::New()
{
return CreateRef<Project>();
}
Ref<Project> Project::New()
{
return CreateRef<Project>();
}
Ref<Project> Project::Load(std::string path)
{
std::ifstream i(path);
json j;
i >> j;
Ref<Project> Project::Load(std::string path)
{
std::ifstream i(path);
json j;
i >> j;
// validation
std::string projectName = "";
if(!j.contains("ProjectName"))
return nullptr;
// validation
std::string projectName = "";
if (!j.contains("ProjectName"))
return nullptr;
projectName = j["ProjectName"];
projectName = j["ProjectName"];
std::string description = "";
if (j.contains("Description"))
description = j["Description"];
std::string description = "";
if (j.contains("Description"))
description = j["Description"];
return CreateRef<Project>(projectName, description, path);
}
return CreateRef<Project>(projectName, description, path);
}
json Project::Serialize()
{
BEGIN_SERIALIZE();
json Project::Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_VAL(Name);
SERIALIZE_VAL(Description);
SERIALIZE_VAL_LBL("DefaultScene", DefaultScene->Path);
SERIALIZE_VAL_LBL("EntityDefinition", EntityDefinitionsFile->Path);
SERIALIZE_VAL(TrenchbroomPath);
END_SERIALIZE();
END_SERIALIZE();
}
bool Project::Deserialize(const std::string& str)
{
BEGIN_DESERIALIZE();
if (!j.contains("Name") || !j.contains("Description"))
return false;
Name = j["Name"];
Description = j["Description"];
if (j.contains("EntityDefinition"))
{
std::string path = j["EntityDefinition"];
EntityDefinitionsFile = CreateRef<FGDFile>(path);
std::string content = FileSystem::ReadFile(path, false);
EntityDefinitionsFile->Deserialize(content);
}
if (j.contains("TrenchbroomPath"))
{
this->TrenchbroomPath = j["TrenchbroomPath"];
}
DefaultScene = Scene::New();
// Load default scene, a project can have no default scene set.
if (!j.contains("DefaultScene"))
return true;
std::string scenePath = j["DefaultScene"];
if (scenePath == "") // Not set correctly.
return true;
std::string sceneContent = FileSystem::ReadFile(scenePath, false);
if (!DefaultScene->Deserialize(sceneContent))
{
Logger::Log("Error loading scene: " + scenePath, CRITICAL);
return false;
}
DefaultScene->Path = scenePath;
Logger::Log("Successfully loaded scene: " + scenePath);
return true; // Success
}
}
bool Project::Deserialize(const std::string& str)
{
BEGIN_DESERIALIZE();
if (!j.contains("Name") || !j.contains("Description"))
return false;
Name = j["Name"];
Description = j["Description"];
if (j.contains("EntityDefinition"))
{
std::string path = j["EntityDefinition"];
EntityDefinitionsFile = CreateRef<FGDFile>(path);
std::string content = FileSystem::ReadFile(path, false);
EntityDefinitionsFile->Deserialize(content);
}
if (j.contains("TrenchbroomPath"))
{
this->TrenchbroomPath = j["TrenchbroomPath"];
}
DefaultScene = Scene::New();
// Load default scene, a project can have no default scene set.
if (!j.contains("DefaultScene"))
return true;
std::string scenePath = j["DefaultScene"];
if (scenePath == "") // Not set correctly.
return true;
std::string sceneContent = FileSystem::ReadFile(scenePath, false);
if (!DefaultScene->Deserialize(sceneContent))
{
Logger::Log("Error loading scene: " + scenePath, CRITICAL);
return false;
}
DefaultScene->Path = scenePath;
Logger::Log("Successfully loaded scene: " + scenePath);
return true; // Success
}

View File

@@ -6,29 +6,32 @@
#include "FGD/FGDFile.h"
class Project : public ISerializable
namespace Nuake
{
public:
std::string Name;
std::string Description;
std::string FullPath;
class Project : public ISerializable
{
public:
std::string Name;
std::string Description;
std::string FullPath;
// Path of the trenchbroom .exe folder
std::string TrenchbroomPath = "";
// Path of the trenchbroom .exe folder
std::string TrenchbroomPath = "";
Ref<Scene> DefaultScene;
Ref<FGDFile> EntityDefinitionsFile;
Ref<Scene> DefaultScene;
Ref<FGDFile> EntityDefinitionsFile;
Project(const std::string Name, const std::string Description, const std::string& FullPath, const std::string& defaultScenePath = "");
Project();
Project(const std::string Name, const std::string Description, const std::string& FullPath, const std::string& defaultScenePath = "");
Project();
void Save();
void SaveAs(const std::string FullPath);
void Save();
void SaveAs(const std::string FullPath);
static Ref<Project> New(const std::string Name, const std::string Description, const std::string FullPath);
static Ref<Project> New();
static Ref<Project> Load(std::string path);
static Ref<Project> New(const std::string Name, const std::string Description, const std::string FullPath);
static Ref<Project> New();
static Ref<Project> Load(std::string path);
json Serialize() override;
bool Deserialize(const std::string& str) override;
};
json Serialize() override;
bool Deserialize(const std::string& str) override;
};
}