added project loader
This commit is contained in:
@@ -5,9 +5,12 @@
|
||||
#ifndef B_ENGINE_PROJECTMANIFEST_H
|
||||
#define B_ENGINE_PROJECTMANIFEST_H
|
||||
|
||||
struct ProjectManifest
|
||||
{
|
||||
#include <string>
|
||||
|
||||
};
|
||||
typedef struct
|
||||
{
|
||||
std::string name;
|
||||
std::string assetFolder;
|
||||
} ProjectManifest;
|
||||
|
||||
#endif //B_ENGINE_PROJECTMANIFEST_H
|
||||
|
||||
38
src/ProjectManifestFile.cpp
Normal file
38
src/ProjectManifestFile.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by slinky on 5/14/26.
|
||||
//
|
||||
|
||||
#include "ProjectManifestFile.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
std::unique_ptr<ProjectManifest> ProjectManifestFile::load(std::string_view _path) {
|
||||
std::ifstream file;
|
||||
file.open(_path.data(), std::ios::in);
|
||||
if (!file.is_open()) {
|
||||
spdlog::error("failed to open project file {}", _path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << file.rdbuf();
|
||||
|
||||
std::string fileData = ss.str();
|
||||
|
||||
auto data = json::parse(fileData);
|
||||
|
||||
ProjectManifest manifest;
|
||||
manifest.name = data.at("name").get<std::string>();
|
||||
manifest.assetFolder = data.at("assetFolder").get<std::string>();
|
||||
|
||||
return std::make_unique<ProjectManifest>(manifest);
|
||||
}
|
||||
|
||||
bool ProjectManifestFile::save(std::string_view _path, ProjectManifest *_project) {
|
||||
return true;
|
||||
}
|
||||
19
src/ProjectManifestFile.h
Normal file
19
src/ProjectManifestFile.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Created by slinky on 5/14/26.
|
||||
//
|
||||
|
||||
#ifndef B_ENGINE_PROJECTMANIFESTFILE_H
|
||||
#define B_ENGINE_PROJECTMANIFESTFILE_H
|
||||
|
||||
#include <string_view>
|
||||
#include <memory>
|
||||
|
||||
#include "ProjectManifest.h"
|
||||
|
||||
class ProjectManifestFile {
|
||||
public:
|
||||
static std::unique_ptr<ProjectManifest> load(std::string_view _path);
|
||||
static bool save(std::string_view _path, ProjectManifest* _project);
|
||||
};
|
||||
|
||||
#endif //B_ENGINE_PROJECTMANIFESTFILE_H
|
||||
29
src/main.cpp
29
src/main.cpp
@@ -15,6 +15,8 @@
|
||||
#include "FreeCameraController.h"
|
||||
#include "InputManager.h"
|
||||
#include "ModelManager.h"
|
||||
#include "ProjectManifest.h"
|
||||
#include "ProjectManifestFile.h"
|
||||
#include "Scene.h"
|
||||
#include "ShaderManager.h"
|
||||
#include "ShaderProgram.h"
|
||||
@@ -26,6 +28,8 @@
|
||||
#include "ui/UISceneGraph.h"
|
||||
#include "ui/UISceneViewer.h"
|
||||
|
||||
const char* B_ENGINE_VERSION = "v0.0.3";
|
||||
|
||||
GLFWwindow* gWindow = nullptr;
|
||||
int gWindowWidth = 1920;
|
||||
int gWindowHeight = 1080;
|
||||
@@ -37,6 +41,8 @@ float gAspectRatio = 0.f;
|
||||
|
||||
float gMouseSensitivity = 0.1f;
|
||||
|
||||
std::unique_ptr<ProjectManifest> gCurrentProject {nullptr};
|
||||
|
||||
Camera gCamera {};
|
||||
Scene gScene{};
|
||||
EditorContext gEditorCtx{};
|
||||
@@ -58,13 +64,14 @@ void load_default_models();
|
||||
void loop();
|
||||
|
||||
void create_entity(entt::entity parent);
|
||||
void open_project(std::string_view _path);
|
||||
|
||||
auto xAxis = glm::vec3{1.f, 0.f, 0.f};
|
||||
auto yAxis = glm::vec3{0.f, 1.f, 0.f};
|
||||
auto zAxis = glm::vec3{0.f, 0.f, 1.f};
|
||||
|
||||
int main() {
|
||||
spdlog::info("b_engine v0.0.3 start");
|
||||
spdlog::info("b_engine {} start", B_ENGINE_VERSION);
|
||||
|
||||
init_glfw();
|
||||
|
||||
@@ -83,8 +90,9 @@ int main() {
|
||||
load_default_models();
|
||||
|
||||
UIManager::init(gWindow);
|
||||
UIMenuBar* menuBar = UIManager::add_ui_panel<UIMenuBar>("menu_bar");
|
||||
auto* menuBar = UIManager::add_ui_panel<UIMenuBar>("menu_bar");
|
||||
menuBar->create_entity = create_entity;
|
||||
menuBar->open_project = open_project;
|
||||
UIManager::add_ui_panel<UISceneViewer>("scene_viewer");
|
||||
UIManager::add_ui_panel<UISceneGraph>("scene_graph");
|
||||
UIManager::add_ui_panel<UIEntityInspector>("entity_inspector");
|
||||
@@ -142,7 +150,8 @@ void init_glfw()
|
||||
|
||||
void create_main_window()
|
||||
{
|
||||
gWindow = glfwCreateWindow(gWindowWidth, gWindowHeight, "b_engine v0.0.3", nullptr, nullptr);
|
||||
std::string title = fmt::format("b_engine {}", B_ENGINE_VERSION);
|
||||
gWindow = glfwCreateWindow(gWindowWidth, gWindowHeight, title.c_str(), nullptr, nullptr);
|
||||
if (!gWindow) {
|
||||
spdlog::error("failed to create glfw window");
|
||||
std::exit(1);
|
||||
@@ -272,10 +281,12 @@ void loop() {
|
||||
}
|
||||
|
||||
void create_entity(entt::entity parent) {
|
||||
auto entity = gScene.create_game_object(parent);
|
||||
auto& drawable = gScene.attach_component<Components::Drawable>(entity);
|
||||
drawable.model = ModelManager::models["vette"];
|
||||
auto& transform = gScene.fetch_component<Components::Transform>(entity);
|
||||
transform.scale = {0.1, 0.1, 0.1};
|
||||
transform.dirty = true;
|
||||
gScene.create_game_object(parent);
|
||||
}
|
||||
|
||||
void open_project(std::string_view _path) {
|
||||
gCurrentProject = ProjectManifestFile::load(_path);
|
||||
|
||||
const std::string title = fmt::format("project \"{}\" | b_engine {}", gCurrentProject->name, B_ENGINE_VERSION);
|
||||
glfwSetWindowTitle(gWindow, title.c_str());
|
||||
}
|
||||
|
||||
@@ -4,16 +4,34 @@
|
||||
|
||||
#include "UIMenuBar.h"
|
||||
#include "UIManager.h"
|
||||
#include "UISceneGraph.h"
|
||||
|
||||
#include "imgui.h"
|
||||
#include "UISceneGraph.h"
|
||||
|
||||
#include "nfd.h"
|
||||
|
||||
void UIMenuBar::update(EditorContext &context) {
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("New Scene")) {
|
||||
if (ImGui::MenuItem("New Project")) {
|
||||
}
|
||||
if (ImGui::MenuItem("Open Scene")) {
|
||||
if (ImGui::MenuItem("Open Project")) {
|
||||
NFD_Init();
|
||||
|
||||
nfdu8char_t *outPath;
|
||||
nfdu8filteritem_t filters[1] = { { "b_engine project files", "json" } };
|
||||
nfdopendialogu8args_t args = {0};
|
||||
args.filterList = filters;
|
||||
args.filterCount = 1;
|
||||
nfdresult_t result = NFD_OpenDialogU8_With(&outPath, &args);
|
||||
|
||||
if (result == NFD_OKAY && open_project)
|
||||
{
|
||||
open_project(outPath);
|
||||
NFD_FreePathU8(outPath);
|
||||
}
|
||||
|
||||
NFD_Quit();
|
||||
}
|
||||
ImGui::Separator(); // Adds a visual line between sections
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S")) {
|
||||
|
||||
@@ -12,6 +12,7 @@ public:
|
||||
void update(EditorContext &context) override;
|
||||
|
||||
std::function<void(entt::entity)> create_entity;
|
||||
std::function<void(std::string_view path)> open_project;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user