diff --git a/docs/tasks/Bugs.todo b/docs/tasks/Bugs.todo index 74461c6..ba33e8f 100644 --- a/docs/tasks/Bugs.todo +++ b/docs/tasks/Bugs.todo @@ -1,5 +1,6 @@ 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) ✔ 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) diff --git a/docs/tasks/core.todo b/docs/tasks/core.todo index 73b4303..6546dfe 100644 --- a/docs/tasks/core.todo +++ b/docs/tasks/core.todo @@ -7,6 +7,10 @@ Build System: ✔ Modify .sh scripts to recognize the noeditor flag @done (1/25/2022, 3:59:23 PM) 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) Wrapper added to utils - not platform ✔ 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 ☐ Add layer to interface API for setting the Images ID in a generic way ☐ 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) ✔ 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) @@ -60,6 +66,8 @@ Core: ☐ Provide Methods that give access to the C++ code 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 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?) diff --git a/docs/tasks/refactoring.todo b/docs/tasks/refactoring.todo new file mode 100644 index 0000000..5ab4b74 --- /dev/null +++ b/docs/tasks/refactoring.todo @@ -0,0 +1,5 @@ + + +☐ Create base classes for serializeable objects + ☐ JSON serializeable + ☐ Binary serializeable \ No newline at end of file diff --git a/src/run_modes/editor/CMakeLists.txt b/src/run_modes/editor/CMakeLists.txt index 419aa7a..3e0d802 100644 --- a/src/run_modes/editor/CMakeLists.txt +++ b/src/run_modes/editor/CMakeLists.txt @@ -12,6 +12,7 @@ set(EDITOR_SRC "panels/properties_view.cpp" "contents/content_manager.cpp" "contents/editor_asset.cpp" +"contents/world.cpp" "contents/tile_map.cpp" "contents/tile_set.cpp" "tools/map_editor/map_editor.cpp" diff --git a/src/run_modes/editor/contents/World.cpp b/src/run_modes/editor/contents/World.cpp new file mode 100644 index 0000000..d1f40fe --- /dev/null +++ b/src/run_modes/editor/contents/World.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 + +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; + } + +}} \ No newline at end of file diff --git a/src/run_modes/editor/contents/content_manager.cpp b/src/run_modes/editor/contents/content_manager.cpp index 480b71e..942cabf 100644 --- a/src/run_modes/editor/contents/content_manager.cpp +++ b/src/run_modes/editor/contents/content_manager.cpp @@ -19,6 +19,7 @@ // Asset types #include "tile_set.h" +#include "world.h" namespace lunarium { namespace editor { @@ -118,7 +119,7 @@ namespace lunarium { namespace editor 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(); @@ -354,6 +355,7 @@ namespace lunarium { namespace editor switch (type) { case AssetType::EATYPE_TILE_SET: return new TileSet(); + case AssetType::EATYPE_WORLD: return new editor::World(); default: return nullptr; } diff --git a/src/run_modes/editor/contents/definitions.h b/src/run_modes/editor/contents/definitions.h index f31610c..2930a9e 100644 --- a/src/run_modes/editor/contents/definitions.h +++ b/src/run_modes/editor/contents/definitions.h @@ -31,6 +31,7 @@ namespace lunarium { namespace editor EATYPE_IMAGE, EATYPE_TILE_SET, EATYPE_TILE_MAP, + EATYPE_WORLD, }; }} diff --git a/src/run_modes/editor/contents/editor_asset.h b/src/run_modes/editor/contents/editor_asset.h index e35c651..fbf963c 100644 --- a/src/run_modes/editor/contents/editor_asset.h +++ b/src/run_modes/editor/contents/editor_asset.h @@ -34,18 +34,20 @@ namespace lunarium { namespace editor private: friend class ContentManager; - AssetType mType; uint64_t mID; - std::filesystem::path mLocation; bool mIsTrashed; - void SetLocation(std::filesystem::path path) { mLocation = path; } + protected: + std::filesystem::path mLocation; protected: std::filesystem::path mAssetDir; - [[nodiscord]] virtual bool IsValidNode(nlohmann::json& node) = 0; + + private: // DISABLE COPY + EditorAsset(const EditorAsset&) = delete; + EditorAsset& operator=(const EditorAsset&) = delete; }; }} diff --git a/src/run_modes/editor/contents/world.h b/src/run_modes/editor/contents/world.h new file mode 100644 index 0000000..3b92629 --- /dev/null +++ b/src/run_modes/editor/contents/world.h @@ -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 + +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_ \ No newline at end of file diff --git a/src/run_modes/editor/editor.cpp b/src/run_modes/editor/editor.cpp index bf35d90..4b5005b 100644 --- a/src/run_modes/editor/editor.cpp +++ b/src/run_modes/editor/editor.cpp @@ -119,11 +119,6 @@ namespace editor } } - uint32_t Editor::GetLogCat() const - { - return LogCat; - } - bool Editor::IsToolOpen(ToolType type) const { switch (type) diff --git a/src/run_modes/editor/editor.h b/src/run_modes/editor/editor.h index aa4bd9d..f302045 100644 --- a/src/run_modes/editor/editor.h +++ b/src/run_modes/editor/editor.h @@ -49,7 +49,6 @@ namespace lunarium { namespace editor void OnRender(lunarium::IGraphics* g); - uint32_t GetLogCat() const; bool IsToolOpen(ToolType type) const; void ChangeWorld(lunarium::World* pWorld); @@ -65,14 +64,12 @@ namespace lunarium { namespace editor const Editor& operator=(const Editor&) = delete; private: // Data - PanelManager mPanelManager; - lunarium::World* mWorld; Project mProject; + lunarium::World* mpWorld; - // Tools - MapEditor* mpMapEditor; // Panels + PanelManager mPanelManager; struct { uint32_t AssetBrowser; @@ -92,6 +89,9 @@ namespace lunarium { namespace editor bool mDoSaveProject; bool mDoSaveAs; + // Tools + MapEditor* mpMapEditor; + // TEST DATA diff --git a/src/run_modes/editor/panels/asset_browser.cpp b/src/run_modes/editor/panels/asset_browser.cpp index 6cd4dbc..8070ef3 100644 --- a/src/run_modes/editor/panels/asset_browser.cpp +++ b/src/run_modes/editor/panels/asset_browser.cpp @@ -10,13 +10,14 @@ #include #include #include +#include #include +#include #include #include #include -#include +#include #include -#include namespace lunarium { @@ -239,6 +240,16 @@ namespace editor 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 ImGui::EndPopup(); } @@ -265,6 +276,7 @@ namespace editor void AssetBrowser::DefinePopups() { + // New Folder AddPopup(PopUp::NEW_FOLDER, "New Folder Name", [](Panel *p) { bool stay_open = true; @@ -286,6 +298,33 @@ namespace editor } return stay_open; }).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); } diff --git a/src/run_modes/editor/panels/asset_browser.h b/src/run_modes/editor/panels/asset_browser.h index e2ab111..0d853c7 100644 --- a/src/run_modes/editor/panels/asset_browser.h +++ b/src/run_modes/editor/panels/asset_browser.h @@ -53,6 +53,7 @@ namespace editor enum PopUp { NEW_FOLDER, + NEW_WORLD, }; }; diff --git a/src/run_modes/editor/panels/world_tree.cpp b/src/run_modes/editor/panels/world_tree.cpp index 6bf5ee1..32c0040 100644 --- a/src/run_modes/editor/panels/world_tree.cpp +++ b/src/run_modes/editor/panels/world_tree.cpp @@ -24,12 +24,17 @@ namespace lunarium : Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), mpEditor(editor), // TODO: Temp world created here - mpWorld(new lunarium::World), + mpWorld(nullptr), mDoNewEntity(false), mpSelectedEntity(nullptr) { AddPopup(PopUp::NEW_ENTITY, "New Entity", [](Panel *p) { WorldTree* pWT = (WorldTree*)p; + if (!pWT->mpWorld) + { + return false; + } + char name_buf[64] = "NewEntity"; ImGui::TextUnformatted("Entity Name: "); ImGui::SameLine(); @@ -64,6 +69,11 @@ namespace lunarium void WorldTree::DoFrame() { Entity *pSelection = nullptr; + if (mpWorld) + { + ImGui::SetNextItemOpen(true); + } + if (ImGui::TreeNode("World Root") && mpWorld) { // List all world entities @@ -119,13 +129,6 @@ namespace lunarium 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(); } diff --git a/src/run_modes/editor/tools/map_editor/map_editor.cpp b/src/run_modes/editor/tools/map_editor/map_editor.cpp index 823aae2..e12cd05 100644 --- a/src/run_modes/editor/tools/map_editor/map_editor.cpp +++ b/src/run_modes/editor/tools/map_editor/map_editor.cpp @@ -43,13 +43,13 @@ namespace lunarium { namespace 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!"); } - mPanelManager.AddPanel(new MapCanvas(this), mPanels.MapCanvas).LogIfFailed(mpEditor->GetLogCat()); - mPanelManager.AddPanel(new TileSetView(this), mPanels.TileSetView).LogIfFailed(mpEditor->GetLogCat()); + mPanelManager.AddPanel(new MapCanvas(this), mPanels.MapCanvas).LogIfFailed(Editor::LogCat); + mPanelManager.AddPanel(new TileSetView(this), mPanels.TileSetView).LogIfFailed(Editor::LogCat); Open(); diff --git a/src/world/entity.cpp b/src/world/entity.cpp index 8243b98..88263be 100644 --- a/src/world/entity.cpp +++ b/src/world/entity.cpp @@ -39,4 +39,10 @@ namespace lunarium { return mChildren.size() > 0; } + + + void Entity::AddChild(Entity* pChild) + { + mChildren.push_back(pChild); + } } \ No newline at end of file diff --git a/src/world/entity.h b/src/world/entity.h index e1ebf4b..116a419 100644 --- a/src/world/entity.h +++ b/src/world/entity.h @@ -14,6 +14,11 @@ #include #include +namespace nlohmann +{ + class json; +} + namespace lunarium { class Entity @@ -65,6 +70,12 @@ namespace lunarium LUUID GetUUID() 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: LUUID mUUID; diff --git a/src/world/world.cpp b/src/world/world.cpp index 74a65f8..918aab7 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -56,16 +56,6 @@ namespace lunarium } - void World::SetWorldScript(Script* pScript) - { - mpWorldScript = pScript; - } - - Script* World::GetWorldScript() - { - return mpWorldScript; - } - entt::registry* World::GetEntityRegistry() { return &mECSRegistry; diff --git a/src/world/world.h b/src/world/world.h index 1bd77a4..05fa4a4 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -9,8 +9,8 @@ * in this region and static collision data. ******************************************************************************/ -#ifndef WORLD_H_ -#define WORLD_H_ +#ifndef LUNARIUM_WORLD_H_ +#define LUNARIUM_WORLD_H_ #include #include @@ -65,9 +65,6 @@ namespace lunarium Region* GetRegion(Vec2i at); bool RemoveRegion(Vec2i at); - void SetWorldScript(Script* pScript); - lunarium::Script* GetWorldScript(); - entt::registry* GetEntityRegistry(); LUUID CreateEntity(); Entity* GetEntity(LUUID id); @@ -79,7 +76,6 @@ namespace lunarium private: entt::registry mECSRegistry; std::vector mEntities; - lunarium::Script* mpWorldScript; // TODO: Move these into a TileMap class? // This would allow worlds to support non-tile based levels/worlds @@ -95,4 +91,4 @@ namespace lunarium }; } -#endif // WORLD_H_ \ No newline at end of file +#endif // LUNARIUM_WORLD_H_ \ No newline at end of file