Adds World Editor Asset

World assets can be created from the AssetBrowser context menu
master
Joey Pollack 4 years ago
parent 5c83a63b3c
commit b49ae6484c

@ -1,5 +1,6 @@
High Importance: High Importance:
☐ AssetBrowser back button does not stop at the asset root directory @high
✔ Editor does not get absolute paths from the file browser - replace with NFD dialogs @critical @done(22-05-20 18:36) ✔ Editor does not get absolute paths from the file browser - replace with NFD dialogs @critical @done(22-05-20 18:36)
✔ The Map Editor does not get the tile maps when a project is opened @high @done (3/3/2022, 2:47:41 PM) ✔ The Map Editor does not get the tile maps when a project is opened @high @done (3/3/2022, 2:47:41 PM)
✔ Tile Set IDs (as opposed to the Asset ID) is not saved or loaded yet @high @done (3/11/2022, 2:10:30 PM) ✔ Tile Set IDs (as opposed to the Asset ID) is not saved or loaded yet @high @done (3/11/2022, 2:10:30 PM)

@ -7,6 +7,10 @@ Build System:
✔ Modify .sh scripts to recognize the noeditor flag @done (1/25/2022, 3:59:23 PM) ✔ Modify .sh scripts to recognize the noeditor flag @done (1/25/2022, 3:59:23 PM)
Core: Core:
☐ Implement generic serializeation system
☐ JSON serializeable base class
☐ JSON implementions should be stubbed out in non-editor builds
☐ Binary serializeable base class
✔ Wrap NFD in an API in the platform module @low @done(22-05-31 15:44) ✔ Wrap NFD in an API in the platform module @low @done(22-05-31 15:44)
Wrapper added to utils - not platform Wrapper added to utils - not platform
✔ Add custom (64 bit?) UUID generator (based on Chreno's UUIDs) @done(22-06-27 13:34) ✔ Add custom (64 bit?) UUID generator (based on Chreno's UUIDs) @done(22-06-27 13:34)
@ -30,6 +34,8 @@ Core:
☐ Move the openGL reference out of the Image class (OpenGL ID) and make the ID more generic ☐ Move the openGL reference out of the Image class (OpenGL ID) and make the ID more generic
☐ Add layer to interface API for setting the Images ID in a generic way ☐ Add layer to interface API for setting the Images ID in a generic way
☐ Implement batch rendering ☐ Implement batch rendering
☐ Allow vertices to be submitted before rendering
☐ Add texture sampler id to the vertex layout
✔ Decide on a font/text rendering system @done (9/7/2021, 1:39:53 PM) ✔ Decide on a font/text rendering system @done (9/7/2021, 1:39:53 PM)
✔ Add FreeType to the project @done (9/7/2021, 2:23:13 PM) ✔ Add FreeType to the project @done (9/7/2021, 2:23:13 PM)
✔ Add a new class for font loading/management and text rendering @done (9/7/2021, 3:57:08 PM) ✔ Add a new class for font loading/management and text rendering @done (9/7/2021, 3:57:08 PM)
@ -60,6 +66,8 @@ Core:
☐ Provide Methods that give access to the C++ code ☐ Provide Methods that give access to the C++ code
ECS: ECS:
✔ Figure out how to serialize Entities @done(22-06-28 14:16)
- Looks like we just need to if check for each component an entity could have...
✔ Research EnTT for the ECS (https://github.com/skypjack/entt/) @done(22-06-01 14:01) ✔ Research EnTT for the ECS (https://github.com/skypjack/entt/) @done(22-06-01 14:01)
✔ Research using ECS with a quadtree (regions may essentially be a quadtree) @done(22-06-01 14:01) ✔ Research using ECS with a quadtree (regions may essentially be a quadtree) @done(22-06-01 14:01)
☐ Use 1 Entt registry with a component that stores the region ID (Index?) ☐ Use 1 Entt registry with a component that stores the region ID (Index?)

@ -0,0 +1,5 @@
☐ Create base classes for serializeable objects
☐ JSON serializeable
☐ Binary serializeable

@ -12,6 +12,7 @@ set(EDITOR_SRC
"panels/properties_view.cpp" "panels/properties_view.cpp"
"contents/content_manager.cpp" "contents/content_manager.cpp"
"contents/editor_asset.cpp" "contents/editor_asset.cpp"
"contents/world.cpp"
"contents/tile_map.cpp" "contents/tile_map.cpp"
"contents/tile_set.cpp" "contents/tile_set.cpp"
"tools/map_editor/map_editor.cpp" "tools/map_editor/map_editor.cpp"

@ -0,0 +1,57 @@
/******************************************************************************
* File - world.h
* Author - Joey Pollack
* Date - 2022/06/28 (y/m/d)
* Mod Date - 2022/06/28 (y/m/d)
* Description - Editor asset for a World object
******************************************************************************/
#include "world.h"
#include <world/world.h>
namespace lunarium { namespace editor
{
World::World(std::filesystem::path name)
: EditorAsset(AssetType::EATYPE_WORLD), mpWorld(new lunarium::World)
{
mLocation = name;
}
World::~World()
{
delete mpWorld;
}
lunarium::World* World::GetWorld()
{
return mpWorld;
}
OpRes World::LoadRawFile()
{
return OpRes::OK();
}
OpRes World::LoadFromJSON(nlohmann::json& node)
{
// TODO: Implement World::LoadFromJSON
// Create the lunarium::World Object here
// Replace the one created in the constructor
return OpRes::OK();
}
OpRes World::SaveToJSON(nlohmann::json& node)
{
// TODO: Implement World::SaveToJSON
// Store the entities UUID - the Entity class will serialize itself
return OpRes::OK();
}
bool World::IsValidNode(nlohmann::json& node)
{
return true;
}
}}

@ -19,6 +19,7 @@
// Asset types // Asset types
#include "tile_set.h" #include "tile_set.h"
#include "world.h"
namespace lunarium { namespace editor namespace lunarium { namespace editor
{ {
@ -118,7 +119,7 @@ namespace lunarium { namespace editor
if (!pAsset) if (!pAsset)
{ {
return OpRes::Fail("Could not create Editor Asset. Unknown type: %n", (int)type); return OpRes::Fail("Could not create Editor Asset. Unknown type: %d", (int)type);
} }
pAsset->mAssetDir = mpProject->GetAssetDirectory(); pAsset->mAssetDir = mpProject->GetAssetDirectory();
@ -354,6 +355,7 @@ namespace lunarium { namespace editor
switch (type) switch (type)
{ {
case AssetType::EATYPE_TILE_SET: return new TileSet(); case AssetType::EATYPE_TILE_SET: return new TileSet();
case AssetType::EATYPE_WORLD: return new editor::World();
default: return nullptr; default: return nullptr;
} }

@ -31,6 +31,7 @@ namespace lunarium { namespace editor
EATYPE_IMAGE, EATYPE_IMAGE,
EATYPE_TILE_SET, EATYPE_TILE_SET,
EATYPE_TILE_MAP, EATYPE_TILE_MAP,
EATYPE_WORLD,
}; };
}} }}

@ -34,18 +34,20 @@ namespace lunarium { namespace editor
private: private:
friend class ContentManager; friend class ContentManager;
AssetType mType; AssetType mType;
uint64_t mID; uint64_t mID;
std::filesystem::path mLocation;
bool mIsTrashed; bool mIsTrashed;
void SetLocation(std::filesystem::path path) { mLocation = path; } protected:
std::filesystem::path mLocation;
protected: protected:
std::filesystem::path mAssetDir; std::filesystem::path mAssetDir;
[[nodiscord]] virtual bool IsValidNode(nlohmann::json& node) = 0; [[nodiscord]] virtual bool IsValidNode(nlohmann::json& node) = 0;
private: // DISABLE COPY
EditorAsset(const EditorAsset&) = delete;
EditorAsset& operator=(const EditorAsset&) = delete;
}; };
}} }}

@ -0,0 +1,52 @@
/******************************************************************************
* File - world.h
* Author - Joey Pollack
* Date - 2022/06/28 (y/m/d)
* Mod Date - 2022/06/28 (y/m/d)
* Description - Editor asset for a World object
******************************************************************************/
#ifndef LUNARIUM_EDITOR_WORLD_H_
#define LUNARIUM_EDITOR_WORLD_H_
#include "editor_asset.h"
#include <filesystem>
namespace lunarium
{
class World;
}
namespace lunarium { namespace editor
{
class World : public EditorAsset
{
public:
World(std::filesystem::path name = "WORLD");
~World();
[[nodiscard]] virtual OpRes LoadRawFile();
[[nodiscard]] virtual OpRes LoadFromJSON(nlohmann::json& node);
[[nodiscard]] virtual OpRes SaveToJSON(nlohmann::json& node);
lunarium::World* GetWorld();
private: // DATA
lunarium::World* mpWorld;
private:
[[nodiscord]] virtual bool IsValidNode(nlohmann::json& node);
private: // DISABLED
World(const World&) = delete;
World& operator=(const World&) = delete;
};
}}
#endif // LUNARIUM_EDITOR_WORLD_H_

@ -119,11 +119,6 @@ namespace editor
} }
} }
uint32_t Editor::GetLogCat() const
{
return LogCat;
}
bool Editor::IsToolOpen(ToolType type) const bool Editor::IsToolOpen(ToolType type) const
{ {
switch (type) switch (type)

@ -49,7 +49,6 @@ namespace lunarium { namespace editor
void OnRender(lunarium::IGraphics* g); void OnRender(lunarium::IGraphics* g);
uint32_t GetLogCat() const;
bool IsToolOpen(ToolType type) const; bool IsToolOpen(ToolType type) const;
void ChangeWorld(lunarium::World* pWorld); void ChangeWorld(lunarium::World* pWorld);
@ -65,14 +64,12 @@ namespace lunarium { namespace editor
const Editor& operator=(const Editor&) = delete; const Editor& operator=(const Editor&) = delete;
private: // Data private: // Data
PanelManager mPanelManager;
lunarium::World* mWorld;
Project mProject; Project mProject;
lunarium::World* mpWorld;
// Tools
MapEditor* mpMapEditor;
// Panels // Panels
PanelManager mPanelManager;
struct struct
{ {
uint32_t AssetBrowser; uint32_t AssetBrowser;
@ -92,6 +89,9 @@ namespace lunarium { namespace editor
bool mDoSaveProject; bool mDoSaveProject;
bool mDoSaveAs; bool mDoSaveAs;
// Tools
MapEditor* mpMapEditor;
// TEST DATA // TEST DATA

@ -10,13 +10,14 @@
#include <core/core.h> #include <core/core.h>
#include <input/input_manager.h> #include <input/input_manager.h>
#include <gui/gui.h> #include <gui/gui.h>
#include <utils/logger.h>
#include <dearimgui/imgui.h> #include <dearimgui/imgui.h>
#include <internal_data/data_manager.h>
#include <editor/editor.h> #include <editor/editor.h>
#include <editor/contents/content_manager.h> #include <editor/contents/content_manager.h>
#include <editor/contents/editor_asset.h> #include <editor/contents/editor_asset.h>
#include <utils/logger.h> #include <editor/contents/world.h>
#include <assets/types/image.h> #include <assets/types/image.h>
#include <internal_data/data_manager.h>
namespace lunarium namespace lunarium
{ {
@ -239,6 +240,16 @@ namespace editor
OpenPopup(PopUp::NEW_FOLDER).LogIfFailed(Editor::LogCat); OpenPopup(PopUp::NEW_FOLDER).LogIfFailed(Editor::LogCat);
} }
if (ImGui::BeginMenu("New Asset"))
{
if (ImGui::MenuItem("New World"))
{
OpenPopup(PopUp::NEW_WORLD).LogIfFailed(Editor::LogCat);
}
ImGui::EndMenu();
}
// TODO: Buttons for creating/importing new assets // TODO: Buttons for creating/importing new assets
ImGui::EndPopup(); ImGui::EndPopup();
} }
@ -265,6 +276,7 @@ namespace editor
void AssetBrowser::DefinePopups() void AssetBrowser::DefinePopups()
{ {
// New Folder
AddPopup(PopUp::NEW_FOLDER, "New Folder Name", [](Panel *p) AddPopup(PopUp::NEW_FOLDER, "New Folder Name", [](Panel *p)
{ {
bool stay_open = true; bool stay_open = true;
@ -286,6 +298,33 @@ namespace editor
} }
return stay_open; return stay_open;
}).LogIfFailed(Editor::LogCat); }).LogIfFailed(Editor::LogCat);
// New World
AddPopup(PopUp::NEW_WORLD, "New World Name", [](Panel *p)
{
bool stay_open = true;
AssetBrowser* ab = (AssetBrowser*)p;
char name_buf[64] = "New World";
ImGui::TextUnformatted("World Name: ");
ImGui::SameLine();
if (ImGui::InputText("##World Name", name_buf, 64, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue))
{
auto assets_dir = ab->mpEditor->GetProject()->MakeRelativeToAssets(ab->mSelectedDir);
EditorAsset* pAsset = new editor::World(assets_dir / name_buf);
u64 id;
ContentManager::GetInstance().AddGeneratedAsset(pAsset, id).LogIfFailed(Editor::LogCat);
stay_open = false;
ImGui::CloseCurrentPopup();
}
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
{
stay_open = false;
ImGui::CloseCurrentPopup();
}
return stay_open;
}).LogIfFailed(Editor::LogCat);
} }

@ -53,6 +53,7 @@ namespace editor
enum PopUp enum PopUp
{ {
NEW_FOLDER, NEW_FOLDER,
NEW_WORLD,
}; };
}; };

@ -24,12 +24,17 @@ namespace lunarium
: Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), : Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
mpEditor(editor), mpEditor(editor),
// TODO: Temp world created here // TODO: Temp world created here
mpWorld(new lunarium::World), mpWorld(nullptr),
mDoNewEntity(false), mpSelectedEntity(nullptr) mDoNewEntity(false), mpSelectedEntity(nullptr)
{ {
AddPopup(PopUp::NEW_ENTITY, "New Entity", [](Panel *p) AddPopup(PopUp::NEW_ENTITY, "New Entity", [](Panel *p)
{ {
WorldTree* pWT = (WorldTree*)p; WorldTree* pWT = (WorldTree*)p;
if (!pWT->mpWorld)
{
return false;
}
char name_buf[64] = "NewEntity"; char name_buf[64] = "NewEntity";
ImGui::TextUnformatted("Entity Name: "); ImGui::TextUnformatted("Entity Name: ");
ImGui::SameLine(); ImGui::SameLine();
@ -64,6 +69,11 @@ namespace lunarium
void WorldTree::DoFrame() void WorldTree::DoFrame()
{ {
Entity *pSelection = nullptr; Entity *pSelection = nullptr;
if (mpWorld)
{
ImGui::SetNextItemOpen(true);
}
if (ImGui::TreeNode("World Root") && mpWorld) if (ImGui::TreeNode("World Root") && mpWorld)
{ {
// List all world entities // List all world entities
@ -119,13 +129,6 @@ namespace lunarium
mpEditor->OnEntitySelect(nullptr); mpEditor->OnEntitySelect(nullptr);
} }
// TODO: Find a way to change this so that OnEntitySelect is not called every frame
// if (pSelection != mpSelectedEntity)
// {
// mpSelectedEntity = pSelection;
// mpEditor->OnEntitySelect(mpSelectedEntity);
// }
DoContextMenu(); DoContextMenu();
} }

@ -43,13 +43,13 @@ namespace lunarium { namespace editor
} }
mpEditor = editor; mpEditor = editor;
if (Failed(mPanelManager.Initialize("Map Editor").LogIfFailed(mpEditor->GetLogCat(), "Map Editor - "))) if (Failed(mPanelManager.Initialize("Map Editor").LogIfFailed(Editor::LogCat, "Map Editor - ")))
{ {
return OpRes::Fail("Could not initialize the panel manager!"); return OpRes::Fail("Could not initialize the panel manager!");
} }
mPanelManager.AddPanel(new MapCanvas(this), mPanels.MapCanvas).LogIfFailed(mpEditor->GetLogCat()); mPanelManager.AddPanel(new MapCanvas(this), mPanels.MapCanvas).LogIfFailed(Editor::LogCat);
mPanelManager.AddPanel(new TileSetView(this), mPanels.TileSetView).LogIfFailed(mpEditor->GetLogCat()); mPanelManager.AddPanel(new TileSetView(this), mPanels.TileSetView).LogIfFailed(Editor::LogCat);
Open(); Open();

@ -39,4 +39,10 @@ namespace lunarium
{ {
return mChildren.size() > 0; return mChildren.size() > 0;
} }
void Entity::AddChild(Entity* pChild)
{
mChildren.push_back(pChild);
}
} }

@ -14,6 +14,11 @@
#include <entt/entt.hpp> #include <entt/entt.hpp>
#include <world/world.h> #include <world/world.h>
namespace nlohmann
{
class json;
}
namespace lunarium namespace lunarium
{ {
class Entity class Entity
@ -65,6 +70,12 @@ namespace lunarium
LUUID GetUUID() const; LUUID GetUUID() const;
bool HasChildren() const; bool HasChildren() const;
void AddChild(Entity* pChild);
// TODO: Move to base class
OpRes SaveToJSON(nlohmann::json& node);
OpRes LoadFromJSON(nlohmann::json& node);
OpRes IsNodeValid(nlohmann::json& node);
private: private:
LUUID mUUID; LUUID mUUID;

@ -56,16 +56,6 @@ namespace lunarium
} }
void World::SetWorldScript(Script* pScript)
{
mpWorldScript = pScript;
}
Script* World::GetWorldScript()
{
return mpWorldScript;
}
entt::registry* World::GetEntityRegistry() entt::registry* World::GetEntityRegistry()
{ {
return &mECSRegistry; return &mECSRegistry;

@ -9,8 +9,8 @@
* in this region and static collision data. * in this region and static collision data.
******************************************************************************/ ******************************************************************************/
#ifndef WORLD_H_ #ifndef LUNARIUM_WORLD_H_
#define WORLD_H_ #define LUNARIUM_WORLD_H_
#include <core/common_defs.h> #include <core/common_defs.h>
#include <core/types.h> #include <core/types.h>
@ -65,9 +65,6 @@ namespace lunarium
Region* GetRegion(Vec2i at); Region* GetRegion(Vec2i at);
bool RemoveRegion(Vec2i at); bool RemoveRegion(Vec2i at);
void SetWorldScript(Script* pScript);
lunarium::Script* GetWorldScript();
entt::registry* GetEntityRegistry(); entt::registry* GetEntityRegistry();
LUUID CreateEntity(); LUUID CreateEntity();
Entity* GetEntity(LUUID id); Entity* GetEntity(LUUID id);
@ -79,7 +76,6 @@ namespace lunarium
private: private:
entt::registry mECSRegistry; entt::registry mECSRegistry;
std::vector<Entity*> mEntities; std::vector<Entity*> mEntities;
lunarium::Script* mpWorldScript;
// TODO: Move these into a TileMap class? // TODO: Move these into a TileMap class?
// This would allow worlds to support non-tile based levels/worlds // This would allow worlds to support non-tile based levels/worlds
@ -95,4 +91,4 @@ namespace lunarium
}; };
} }
#endif // WORLD_H_ #endif // LUNARIUM_WORLD_H_
Loading…
Cancel
Save