|
|
|
@ -8,15 +8,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "world.h"
|
|
|
|
#include "world.h"
|
|
|
|
#include <LunariumConfig.h>
|
|
|
|
#include <LunariumConfig.h>
|
|
|
|
|
|
|
|
#include <editor/editor.h>
|
|
|
|
#include <world/world.h>
|
|
|
|
#include <world/world.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
|
|
namespace lunarium { namespace editor
|
|
|
|
namespace lunarium { namespace editor
|
|
|
|
{
|
|
|
|
{
|
|
|
|
World::World(std::filesystem::path name)
|
|
|
|
World::World(std::filesystem::path name)
|
|
|
|
: EditorAsset(AssetType::EATYPE_WORLD), mpWorld(new lunarium::World)
|
|
|
|
: EditorAsset(AssetType::EATYPE_WORLD), mpWorld(new lunarium::World)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mLocation = name;
|
|
|
|
mLocation = name.string() + ".wld";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
World::~World()
|
|
|
|
World::~World()
|
|
|
|
@ -29,47 +32,91 @@ namespace lunarium { namespace editor
|
|
|
|
return mpWorld;
|
|
|
|
return mpWorld;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::UnloadWorld()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
delete mpWorld;
|
|
|
|
|
|
|
|
mpWorld = nullptr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OpRes World::LoadWorld()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return LoadRawFile();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OpRes World::LoadRawFile()
|
|
|
|
OpRes World::LoadRawFile()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return OpRes::OK();
|
|
|
|
return OpRes::OK();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OpRes World::Deserialize(nlohmann::json& node)
|
|
|
|
OpRes World::Deserialize(nlohmann::ordered_json& node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO: Implement World::LoadFromJSON
|
|
|
|
|
|
|
|
// Create the lunarium::World Object here
|
|
|
|
|
|
|
|
// Replace the one created in the constructor
|
|
|
|
|
|
|
|
#if !BUILD_NO_EDITOR // Only does this when this is an editor build
|
|
|
|
#if !BUILD_NO_EDITOR // Only does this when this is an editor build
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::filesystem::path file_path = mAssetDir / mLocation;
|
|
|
|
|
|
|
|
std::ifstream ifs = std::ifstream(file_path.string().c_str());
|
|
|
|
|
|
|
|
if (!ifs.is_open())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return OpRes::Fail("Could not open contents file: %s", file_path.string().c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nlohmann::ordered_json world_file;
|
|
|
|
|
|
|
|
ifs >> world_file;
|
|
|
|
|
|
|
|
ifs.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mpWorld)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mpWorld->Deserialize(world_file).LogIfFailed(Editor::LogCat);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return OpRes::OK();
|
|
|
|
return OpRes::OK();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OpRes World::Serialize(nlohmann::json& node)
|
|
|
|
OpRes World::Serialize(nlohmann::ordered_json& node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO: Implement World::SaveToJSON
|
|
|
|
|
|
|
|
// Store the entities UUID - the Entity class will serialize itself
|
|
|
|
|
|
|
|
#if !BUILD_NO_EDITOR // Only does this when this is an editor build
|
|
|
|
#if !BUILD_NO_EDITOR // Only does this when this is an editor build
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nlohmann::ordered_json world_file;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mpWorld)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mpWorld->Serialize(world_file).LogIfFailed(Editor::LogCat);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::filesystem::path file_path = mAssetDir / mLocation;
|
|
|
|
|
|
|
|
std::ofstream ofs = std::ofstream(file_path.string().c_str(), std::ios_base::trunc);
|
|
|
|
|
|
|
|
if (!ofs.is_open())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return OpRes::Fail("Could not save file: %s", file_path.string().c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ofs << std::setw(4) << world_file;
|
|
|
|
|
|
|
|
ofs.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return OpRes::OK();
|
|
|
|
return OpRes::OK();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool World::IsValidNode(nlohmann::json& node)
|
|
|
|
bool World::IsValidNode(nlohmann::ordered_json& node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nlohmann::json World::AsJSON()
|
|
|
|
nlohmann::ordered_json World::AsJSON()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#if !BUILD_NO_EDITOR // Only does this when this is an editor build
|
|
|
|
#if !BUILD_NO_EDITOR // Only does this when this is an editor build
|
|
|
|
nlohmann::json node;
|
|
|
|
nlohmann::ordered_json node;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serialize(node).LogIfFailed(Editor::LogCat);
|
|
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
return node;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
return nlohmann::json();
|
|
|
|
return nlohmann::ordered_json();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
}}
|