Skip to content

Commit

Permalink
[Editor] Project importer (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabsgc committed Feb 24, 2024
1 parent 9006bca commit 1e7a181
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions Data/Project/default.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion Source/Examples/Editor/TeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ namespace te
SPtr<ProjectImportOptions> options = te_shared_ptr_new<ProjectImportOptions>();
SPtr<MultiResource> multiResourceScene = EditorResManager::Instance().LoadAll(path, options, true);

if (multiResourceScene->Entries.size() == 0 || multiResourceScene->Entries[0].Res.IsLoaded())
if (multiResourceScene->Entries.size() == 0 || !multiResourceScene->Entries[0].Res.IsLoaded())
{
TE_DEBUG("Failed to load the your project at the specified path : " + path);
return false;
Expand Down
39 changes: 39 additions & 0 deletions Source/Plugins/TeProjectImporter/TeProjectImporter.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "TeProjectImporter.h"
#include "Project/TeProject.h"
#include "Importer/TeProjectImportOptions.h"
#include "Utility/TeDataStream.h"

#include <iostream>
#include <filesystem>

namespace te
Expand Down Expand Up @@ -35,6 +37,43 @@ namespace te
{
project = Project::CreatePtr();

nlohmann::json jsonDocument;
FileStream file(filePath);

if (file.Fail())
{
TE_ASSERT_ERROR(false, "Cannot open file: " + filePath);
return nullptr;
}

size_t size = file.Size();

if (size > std::numeric_limits<UINT32>::max())
{
TE_ASSERT_ERROR(false, "File size larger than supported!");
}

uint8_t* data = static_cast<uint8_t*>(te_allocate(static_cast<UINT32>(size) + 1));
memset(data, 0, size);
file.Read(static_cast<char*>((void*)data), static_cast<std::streamsize>(size));
data[size] = (uint8_t)'\0';

String dataStr((char*)data);

#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
try
{
jsonDocument = nlohmann::json::parse(dataStr);
}
catch (...)
{
TE_ASSERT_ERROR(false, "Can't read shader file " + filePath);
}
#else
jsonDocument = nlohmann::json::parse(dataStr);
#endif
te_delete(data);

project->SetName(path.filename().generic_string());
project->SetPath(path.generic_string());
}
Expand Down
1 change: 1 addition & 0 deletions Source/Plugins/TeProjectImporter/TeProjectImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "TeProjectImporterPrerequisites.h"
#include "Importer/TeBaseImporter.h"
#include "Importer/TeImporter.h"
#include "Json/json.h"

namespace te
{
Expand Down

0 comments on commit 1e7a181

Please sign in to comment.