diff --git a/core/src/story_page.h b/core/src/story_page.h index ac7dfd5..61fb6bb 100644 --- a/core/src/story_page.h +++ b/core/src/story_page.h @@ -104,7 +104,7 @@ public: } int OutputsCount(const std::string &nodeId) const -{ + { int count = 0; for (const auto & l : m_links) { diff --git a/core/src/story_project.cpp b/core/src/story_project.cpp index bac1361..8f23062 100644 --- a/core/src/story_project.cpp +++ b/core/src/story_project.cpp @@ -72,6 +72,8 @@ void StoryProject::New(const std::string &uuid, const std::string &library_path) std::filesystem::create_directories(m_assetsPath); + CreatePage(MainUuid()); + m_initialized = true; } @@ -422,7 +424,7 @@ bool StoryProject::Load(ResourceManager &manager) if (j.contains("pages")) { - ModelFromJson(j["pages"]); + ModelFromJson(j); m_initialized = true; } } @@ -433,6 +435,11 @@ bool StoryProject::Load(ResourceManager &manager) std::cout << e.what() << std::endl; } + if (m_pages.size() == 0) + { + CreatePage(MainUuid()); + } + return m_initialized; } diff --git a/core/src/story_project.h b/core/src/story_project.h index 5d601a8..01400ce 100644 --- a/core/src/story_project.h +++ b/core/src/story_project.h @@ -66,6 +66,11 @@ public: StoryNode *m_tree; */ + + std::string MainUuid() const { + return "490745ab-df4d-476d-ae27-027e94b8ee0a"; + } + void New(const std::string &uuid, const std::string &library_path); std::filesystem::path BinaryFileName() const; bool GenerateScript(std::string &codeStr); diff --git a/story-editor/src/importers/pack_archive.cpp b/story-editor/src/importers/pack_archive.cpp index 6347cbb..2a22449 100644 --- a/story-editor/src/importers/pack_archive.cpp +++ b/story-editor/src/importers/pack_archive.cpp @@ -210,7 +210,7 @@ $MyArray DV8 10 ; array of 10 bytes StoryProject proj(m_log); ResourceManager res(m_log); - std::shared_ptr page = proj.CreatePage("main"); + std::shared_ptr page = proj.CreatePage(proj.MainUuid()); proj.New(uuid, outputDir); @@ -396,7 +396,7 @@ bool PackArchive::ConvertJsonStudioToOst(const std::string &basePath, const std: StoryProject proj(m_log); ResourceManager res(m_log); - std::shared_ptr page = proj.CreatePage("main"); + std::shared_ptr page = proj.CreatePage(proj.MainUuid()); if (j.contains("title")) { @@ -428,7 +428,7 @@ bool PackArchive::ConvertJsonStudioToOst(const std::string &basePath, const std: for (const auto & n : j["stageNodes"]) { - auto node = proj.CreateNode("main", "media-node"); + auto node = proj.CreateNode(proj.MainUuid(), "media-node"); if (node) { diff --git a/story-editor/src/node_editor/node_editor_window.cpp b/story-editor/src/node_editor/node_editor_window.cpp index ee18a11..c438753 100644 --- a/story-editor/src/node_editor/node_editor_window.cpp +++ b/story-editor/src/node_editor/node_editor_window.cpp @@ -37,14 +37,14 @@ NodeEditorWindow::~NodeEditorWindow() m_story.reset(); } -static const std::string gMainUuid = "490745ab-df4d-476d-ae27-027e94b8ee0a"; + void NodeEditorWindow::Initialize() { m_pages.clear(); m_callStack.clear(); - m_currentPage = std::make_shared(gMainUuid, "Main"); + m_currentPage = std::make_shared(m_story->MainUuid(), "Main"); m_pages.push_back(m_currentPage); m_callStack.push_back(m_currentPage); diff --git a/story-editor/src/node_editor/node_editor_window.h b/story-editor/src/node_editor/node_editor_window.h index cbe7ad0..b9dde47 100644 --- a/story-editor/src/node_editor/node_editor_window.h +++ b/story-editor/src/node_editor/node_editor_window.h @@ -41,7 +41,7 @@ private: bool m_loaded{false}; - // "main" is the entry point editor context. You always need to create one. + // "MainUuid" is the entry point editor context. You always need to create one. // Then each function can have its own editor context, for example if you want to create multiple graphs. // the key is main, or the UUID of the function std::list> m_pages; diff --git a/story-editor/src/resources_window.cpp b/story-editor/src/resources_window.cpp index d55fd2c..7f5f97f 100644 --- a/story-editor/src/resources_window.cpp +++ b/story-editor/src/resources_window.cpp @@ -29,7 +29,7 @@ void ResourcesWindow::ChooseFile() m_showImportDialog = false; // open Dialog Simple IGFD::FileDialogConfig config; - config.path = "."; + config.path = m_story.BuildFullAssetsPath(""); config.countSelectionMax = 1; config.sidePaneWidth = 350.0f; config.flags = ImGuiFileDialogFlags_Modal; @@ -50,7 +50,18 @@ void ResourcesWindow::ChooseFile() std::filesystem::path p(filePathName); std::filesystem::path p2 = m_story.BuildFullAssetsPath( p.filename().generic_string()); - std::filesystem::copy(p, p2, std::filesystem::copy_options::overwrite_existing); + + bool allowCopy = true; + // On ne copie pas le fichier sur lui-même + if (std::filesystem::exists(p) && std::filesystem::exists(p2)) + { + allowCopy = !std::filesystem::equivalent(p, p2); + } + + if (allowCopy) + { + std::filesystem::copy(p, p2, std::filesystem::copy_options::overwrite_existing); + } auto res = std::make_shared();