editor assets refactored to fit the new project content system design
parent
894580c325
commit
6aef59c7e3
@ -0,0 +1,91 @@
|
||||
/******************************************************************************
|
||||
* File - content_manager.cpp
|
||||
* Author - Joey Pollack
|
||||
* Date - 2022/02/22 (y/m/d)
|
||||
* Mod Date - 2022/02/22 (y/m/d)
|
||||
* Description - Keeps track of all resource files in the project.
|
||||
* Reads/Writes meta-data to the contents_meta.xml file.
|
||||
* Also manages the physical location of each asset file.
|
||||
******************************************************************************/
|
||||
|
||||
#include "content_manager.h"
|
||||
#include "../project.h"
|
||||
#include <pugixml.hpp>
|
||||
|
||||
namespace lunarium { namespace editor
|
||||
{
|
||||
ContentManager* ContentManager::mpInstance = nullptr;
|
||||
|
||||
ContentManager::ContentManager()
|
||||
: mpProject(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ContentManager& ContentManager::GetInstance()
|
||||
{
|
||||
if (!mpInstance)
|
||||
{
|
||||
mpInstance = new ContentManager();
|
||||
}
|
||||
|
||||
return *mpInstance;
|
||||
}
|
||||
|
||||
void ContentManager::FreeInstance()
|
||||
{
|
||||
if (mpInstance)
|
||||
{
|
||||
delete mpInstance;
|
||||
mpInstance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
OpRes ContentManager::Load(Project* project)
|
||||
{
|
||||
mpProject = project;
|
||||
std::filesystem::path root = mpProject->GetRootDirectory();
|
||||
mContentFile = root / "contents/content_meta.xml";
|
||||
|
||||
if (!std::filesystem::exists(mContentFile))
|
||||
{
|
||||
pugi::xml_document doc;
|
||||
pugi::xml_node proj_node = doc.append_child("Contents");
|
||||
if (!doc.save_file(mContentFile.string().c_str()))
|
||||
{
|
||||
return OpRes::Fail("ContentManager could not save file: %s", mContentFile.string().c_str());
|
||||
}
|
||||
|
||||
return OpRes::OK();
|
||||
}
|
||||
|
||||
return OpRes::Fail("ContentManager::Load not implemented");
|
||||
}
|
||||
|
||||
OpRes ContentManager::Save()
|
||||
{
|
||||
return OpRes::Fail("ContentManager::Save not implemented");
|
||||
}
|
||||
|
||||
void ContentManager::Unload()
|
||||
{
|
||||
mpProject = nullptr;
|
||||
mAssets.clear();
|
||||
mContentFile = "";
|
||||
}
|
||||
|
||||
OpRes ContentManager::ImportFile(std::filesystem::path file, AssetType type)
|
||||
{
|
||||
return OpRes::Fail("ContentManager::ImportFile not implemented");
|
||||
}
|
||||
|
||||
void ContentManager::MoveAsset(EditorAsset* asset, std::filesystem::path to)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ContentManager::RenameAsset(EditorAsset* asset, std::string name)
|
||||
{
|
||||
|
||||
}
|
||||
}}
|
||||
@ -0,0 +1,55 @@
|
||||
/******************************************************************************
|
||||
* File - content_manager.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2022/02/22 (y/m/d)
|
||||
* Mod Date - 2022/02/22 (y/m/d)
|
||||
* Description - Keeps track of all resource files in the project.
|
||||
* Reads/Writes meta-data to the contents_meta.xml file.
|
||||
* Also manages the physical location of each asset file.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef CONTENT_MANAGER_H_
|
||||
#define CONTENT_MANAGER_H_
|
||||
|
||||
#include "definitions.h"
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <utils/opRes.h>
|
||||
#include <map>
|
||||
|
||||
namespace lunarium { namespace editor
|
||||
{
|
||||
|
||||
class Project;
|
||||
class EditorAsset;
|
||||
|
||||
class ContentManager
|
||||
{
|
||||
public:
|
||||
|
||||
static ContentManager& GetInstance();
|
||||
static void FreeInstance();
|
||||
|
||||
[[nodiscard]] OpRes Load(Project* project);
|
||||
[[nodiscard]] OpRes Save();
|
||||
void Unload();
|
||||
|
||||
[[nodiscard]] OpRes ImportFile(std::filesystem::path file, AssetType type);
|
||||
void MoveAsset(EditorAsset* asset, std::filesystem::path to);
|
||||
void RenameAsset(EditorAsset* asset, std::string name);
|
||||
|
||||
private:
|
||||
static ContentManager* mpInstance;
|
||||
Project* mpProject;
|
||||
std::filesystem::path mContentFile;
|
||||
std::map<uint64_t, EditorAsset*> mAssets;
|
||||
|
||||
private:
|
||||
ContentManager();
|
||||
ContentManager(ContentManager&) = delete;
|
||||
ContentManager& operator=(const ContentManager&) = delete;
|
||||
|
||||
};
|
||||
}}
|
||||
|
||||
#endif // CONTENT_MANAGER_H_
|
||||
@ -0,0 +1,22 @@
|
||||
/******************************************************************************
|
||||
* File - definitions.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2022/02/24 (y/m/d)
|
||||
* Mod Date - 2022/02/24 (y/m/d)
|
||||
* Description - file for common defintions for the editor content system
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef EDITOR_ASSETS_DEFINITIONS_H_
|
||||
#define EDITOR_ASSETS_DEFINITIONS_H_
|
||||
|
||||
namespace lunarium { namespace editor
|
||||
{
|
||||
enum AssetType
|
||||
{
|
||||
EATYPE_IMAGE,
|
||||
EATYPE_TILE_SET,
|
||||
EATYPE_TILE_MAP,
|
||||
};
|
||||
}}
|
||||
|
||||
#endif // EDITOR_ASSETS_DEFINITIONS_H_
|
||||
@ -0,0 +1,35 @@
|
||||
/******************************************************************************
|
||||
* File - editor_asset.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2022/02/22 (y/m/d)
|
||||
* Mod Date - 2022/02/22 (y/m/d)
|
||||
* Description - Editor assets base class
|
||||
******************************************************************************/
|
||||
|
||||
#include "editor_asset.h"
|
||||
|
||||
namespace lunarium { namespace editor {
|
||||
|
||||
EditorAsset::EditorAsset(AssetType type)
|
||||
: mType(type)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
AssetType EditorAsset::GetType()
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
uint64_t EditorAsset::GetID()
|
||||
{
|
||||
return mID;
|
||||
}
|
||||
|
||||
std::filesystem::path EditorAsset::GetFileLocation()
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
}}
|
||||
@ -0,0 +1,40 @@
|
||||
/******************************************************************************
|
||||
* File - editor_asset.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2022/02/22 (y/m/d)
|
||||
* Mod Date - 2022/02/22 (y/m/d)
|
||||
* Description - Editor assets base class
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef EDITOR_ASSETS_H_
|
||||
#define EDITOR_ASSETS_H_
|
||||
|
||||
#include "definitions.h"
|
||||
#include "content_manager.h"
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace lunarium { namespace editor
|
||||
{
|
||||
|
||||
class EditorAsset
|
||||
{
|
||||
public:
|
||||
EditorAsset(AssetType type);
|
||||
|
||||
AssetType GetType();
|
||||
uint64_t GetID();
|
||||
std::filesystem::path GetFileLocation();
|
||||
|
||||
private:
|
||||
friend class ContentManager;
|
||||
|
||||
AssetType mType;
|
||||
uint64_t mID;
|
||||
std::filesystem::path mLocation;
|
||||
|
||||
protected:
|
||||
};
|
||||
}}
|
||||
|
||||
#endif // EDITOR_ASSETS_H_
|
||||
Loading…
Reference in New Issue