New project generation working
parent
9e6a15d08f
commit
fda2264251
@ -0,0 +1,72 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - project.cpp
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2021/11/09 (y/m/d)
|
||||||
|
* Mod Date - 2021/11/09 (y/m/d)
|
||||||
|
* Description - Manage data for a game project
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "project.h"
|
||||||
|
|
||||||
|
#include <pugixml.hpp>
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
Project::Project()
|
||||||
|
: mIsLoaded(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
OpRes Project::GenerateProject(std::string name, std::filesystem::path location)
|
||||||
|
{
|
||||||
|
if (mIsLoaded)
|
||||||
|
{
|
||||||
|
return OpRes::Fail("A project is already loaded. Unload the current project to generate a new one.");
|
||||||
|
}
|
||||||
|
|
||||||
|
mName = name;
|
||||||
|
mLocation = location;
|
||||||
|
mLocation /= mName;
|
||||||
|
|
||||||
|
if (std::filesystem::exists(mLocation))
|
||||||
|
{
|
||||||
|
return OpRes::Fail("A project with that name (%s) already exists in this location: %s", mName.c_str(), mLocation.string().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::create_directory(mLocation);
|
||||||
|
|
||||||
|
std::filesystem::path proj_doc = mLocation;
|
||||||
|
proj_doc /= std::filesystem::path(mName + ".lproj");
|
||||||
|
|
||||||
|
pugi::xml_document doc;
|
||||||
|
pugi::xml_node proj_node = doc.append_child("Lunarium_Project");
|
||||||
|
proj_node.append_attribute("name").set_value(mName.c_str());
|
||||||
|
//pugi::xml_node name_node = proj_node.append_child("Name");
|
||||||
|
doc.save_file(proj_doc.string().c_str());
|
||||||
|
|
||||||
|
std::filesystem::create_directory(mLocation / std::filesystem::path("engine"));
|
||||||
|
std::filesystem::create_directory(mLocation / std::filesystem::path("contents"));
|
||||||
|
std::filesystem::create_directory(mLocation / std::filesystem::path("contents/assets"));
|
||||||
|
|
||||||
|
mIsLoaded = true;
|
||||||
|
return OpRes::OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Project::IsLoaded() const
|
||||||
|
{
|
||||||
|
return mIsLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpRes Project::LoadProject(std::filesystem::path location)
|
||||||
|
{
|
||||||
|
return OpRes::Fail("Project::LoadProject not implemented yet");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Project::UnloadCurrentProject()
|
||||||
|
{
|
||||||
|
mName = "";
|
||||||
|
mLocation = "";
|
||||||
|
mIsLoaded = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - project.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2021/11/09 (y/m/d)
|
||||||
|
* Mod Date - 2021/11/09 (y/m/d)
|
||||||
|
* Description - Manage data for a game project
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef PROJECT_H_
|
||||||
|
#define PROJECT_H_
|
||||||
|
|
||||||
|
#include <utils/opRes.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
class Scene;
|
||||||
|
class Project
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Project();
|
||||||
|
OpRes GenerateProject(std::string name, std::filesystem::path location);
|
||||||
|
OpRes LoadProject(std::filesystem::path location);
|
||||||
|
void UnloadCurrentProject();
|
||||||
|
|
||||||
|
bool IsLoaded() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool mIsLoaded;
|
||||||
|
std::string mName;
|
||||||
|
std::filesystem::path mLocation;
|
||||||
|
|
||||||
|
std::vector<Scene*> mScenes;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // PROJECT_H_
|
||||||
Loading…
Reference in New Issue