|
|
|
|
@ -16,6 +16,7 @@
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
#include <utils/logger.h>
|
|
|
|
|
#include <utils/uuid.h>
|
|
|
|
|
|
|
|
|
|
// Asset types
|
|
|
|
|
#include "tile_set.h"
|
|
|
|
|
@ -26,7 +27,7 @@ namespace lunarium { namespace editor
|
|
|
|
|
ContentManager* ContentManager::mpInstance = nullptr;
|
|
|
|
|
|
|
|
|
|
ContentManager::ContentManager()
|
|
|
|
|
: mpProject(nullptr), mNextID(0), mpEditor(nullptr)
|
|
|
|
|
: mpProject(nullptr), mpEditor(nullptr)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -87,12 +88,12 @@ namespace lunarium { namespace editor
|
|
|
|
|
return OpRes::Fail("content_meta.json missing Project element");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (p["NextID"].is_null())
|
|
|
|
|
{
|
|
|
|
|
return OpRes::Fail("content_meta.xml missing NextID node");
|
|
|
|
|
}
|
|
|
|
|
// if (p["NextID"].is_null())
|
|
|
|
|
// {
|
|
|
|
|
// return OpRes::Fail("content_meta.xml missing NextID node");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
mNextID = p["NextID"].get<u64>();
|
|
|
|
|
//mNextID = p["NextID"].get<u64>();
|
|
|
|
|
|
|
|
|
|
auto c = p["Contents"];
|
|
|
|
|
|
|
|
|
|
@ -175,7 +176,7 @@ namespace lunarium { namespace editor
|
|
|
|
|
|
|
|
|
|
// Save header info
|
|
|
|
|
p["Name"] = mpProject->GetName();
|
|
|
|
|
p["NextID"] = mNextID;
|
|
|
|
|
//p["NextID"] = mNextID;
|
|
|
|
|
|
|
|
|
|
// Save all assets
|
|
|
|
|
auto& c = p["Contents"];
|
|
|
|
|
@ -218,7 +219,7 @@ namespace lunarium { namespace editor
|
|
|
|
|
mpProject = nullptr;
|
|
|
|
|
FreeAssets();
|
|
|
|
|
mContentFile = "";
|
|
|
|
|
mNextID = 0;
|
|
|
|
|
//mNextID = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentManager::GetAllAssetIDs(std::vector<uint64_t>& container) const
|
|
|
|
|
@ -269,14 +270,15 @@ namespace lunarium { namespace editor
|
|
|
|
|
|
|
|
|
|
OpRes ContentManager::AddGeneratedAsset(EditorAsset* asset, uint64_t& id)
|
|
|
|
|
{
|
|
|
|
|
if (mAssets.find(mNextID) != mAssets.end())
|
|
|
|
|
{
|
|
|
|
|
return OpRes::Fail("Could not import asset, ID collision. ID: %llu", mNextID);
|
|
|
|
|
}
|
|
|
|
|
// if (mAssets.find(mNextID) != mAssets.end())
|
|
|
|
|
// {
|
|
|
|
|
// return OpRes::Fail("Could not import asset, ID collision. ID: %llu", mNextID);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
asset->mAssetDir = mpProject->GetAssetDirectory();
|
|
|
|
|
asset->mID = mNextID;
|
|
|
|
|
mNextID++;
|
|
|
|
|
// asset->mID = mNextID;
|
|
|
|
|
asset->mID = UUID::GetNewID();
|
|
|
|
|
//mNextID++;
|
|
|
|
|
mAssets[asset->mID] = asset;
|
|
|
|
|
id = asset->mID;
|
|
|
|
|
|
|
|
|
|
@ -287,10 +289,10 @@ namespace lunarium { namespace editor
|
|
|
|
|
|
|
|
|
|
OpRes ContentManager::ImportFile(std::filesystem::path file, std::filesystem::path to_location, AssetType type, uint64_t& id)
|
|
|
|
|
{
|
|
|
|
|
if (mAssets.find(mNextID) != mAssets.end())
|
|
|
|
|
{
|
|
|
|
|
return OpRes::Fail("Could not import asset, ID collision. ID: %llu", mNextID);
|
|
|
|
|
}
|
|
|
|
|
// if (mAssets.find(mNextID) != mAssets.end())
|
|
|
|
|
// {
|
|
|
|
|
// return OpRes::Fail("Could not import asset, ID collision. ID: %llu", mNextID);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (std::filesystem::exists(to_location))
|
|
|
|
|
{
|
|
|
|
|
@ -306,8 +308,9 @@ namespace lunarium { namespace editor
|
|
|
|
|
|
|
|
|
|
EditorAsset* pAsset = CreateAsset(type);
|
|
|
|
|
pAsset->mAssetDir = mpProject->GetAssetDirectory();
|
|
|
|
|
pAsset->mID = mNextID;
|
|
|
|
|
mNextID++;
|
|
|
|
|
// pAsset->mID = mNextID;
|
|
|
|
|
pAsset->mID = UUID::GetNewID();
|
|
|
|
|
// mNextID++;
|
|
|
|
|
pAsset->mLocation = mpProject->MakeRelativeToAssets(to_location);
|
|
|
|
|
if (Failed(pAsset->LoadRawFile().LogIfFailed(Editor::LogCat)))
|
|
|
|
|
{
|
|
|
|
|
|