From da04c38dec79cabdce49d9a96dd9a52b86bf000d Mon Sep 17 00:00:00 2001 From: Anthony Rabine Date: Thu, 28 Aug 2025 22:07:21 +0200 Subject: [PATCH] (wip) compilation of module --- .../interfaces/i_story_manager.h | 2 +- core/story-manager/src/story_page.h | 4 +- core/story-manager/src/story_project.cpp | 4 +- story-editor/src/app/app_controller.cpp | 46 ++++++++++++------- story-editor/src/app/app_controller.h | 7 +-- story-editor/src/docks/emulator_dock.cpp | 2 +- story-editor/src/main_window.cpp | 14 ++++++ 7 files changed, 53 insertions(+), 26 deletions(-) diff --git a/core/story-manager/interfaces/i_story_manager.h b/core/story-manager/interfaces/i_story_manager.h index 5d34576..4419de8 100644 --- a/core/story-manager/interfaces/i_story_manager.h +++ b/core/story-manager/interfaces/i_story_manager.h @@ -46,7 +46,7 @@ public: virtual std::shared_ptr OpenModule(const std::string &uuid) = 0; // Node interaction - virtual void BuildNodes(bool compileonly) = 0; + virtual void CompileNodes(bool compileonly) = 0; virtual void BuildCode(bool compileonly) = 0; virtual void SetExternalSourceFile(const std::string &filename) = 0; virtual void LoadBinaryStory(const std::string &filename) = 0; diff --git a/core/story-manager/src/story_page.h b/core/story-manager/src/story_page.h index 434a245..ff36c4f 100644 --- a/core/story-manager/src/story_page.h +++ b/core/story-manager/src/story_page.h @@ -51,13 +51,13 @@ public: m_nodes.clear(); } - void BuildNodesVariables(AssemblyGenerator &generator) + void CompileNodesVariables(AssemblyGenerator &generator) { std::vector> nodes(m_nodes.begin(), m_nodes.end()); generator.GenerateNodesVariables(nodes); } - void BuildNodes(AssemblyGenerator &generator) + void CompileNodes(AssemblyGenerator &generator) { std::vector> nodes(m_nodes.begin(), m_nodes.end()); std::vector> links(m_links.begin(), m_links.end()); diff --git a/core/story-manager/src/story_project.cpp b/core/story-manager/src/story_project.cpp index a26a83c..33091c6 100644 --- a/core/story-manager/src/story_project.cpp +++ b/core/story-manager/src/story_project.cpp @@ -420,14 +420,14 @@ bool StoryProject::GenerateScript(std::string &codeStr) generator.StartSection(AssemblyGenerator::Section::TEXT); for (const auto & p : m_pages) { - p->BuildNodes(generator); + p->CompileNodes(generator); } // Generate data section generator.StartSection(AssemblyGenerator::Section::DATA); for (const auto & p : m_pages) { - p->BuildNodesVariables(generator); + p->CompileNodesVariables(generator); } generator.GenerateGlobalVariables(); diff --git a/story-editor/src/app/app_controller.cpp b/story-editor/src/app/app_controller.cpp index 96fd30b..9a9bd3a 100644 --- a/story-editor/src/app/app_controller.cpp +++ b/story-editor/src/app/app_controller.cpp @@ -241,22 +241,34 @@ void AppController::ExportStory(const std::string &filename) m_logger.Log("Export story to: " + filename); } -void AppController::BuildNodes(IStoryProject::Type type) +void AppController::CompileNodes(IStoryProject::Type type) { - if (type == IStoryProject::Type::PROJECT_TYPE_STORY && m_story) { - if (m_story->GenerateScript(m_currentCode)) + if (type == IStoryProject::Type::PROJECT_TYPE_STORY && m_story) + { + if (m_story->GenerateScript(m_storyAssembly)) { // La GUI (DebuggerWindow) doit être notifiée de cette mise à jour. - // Au lieu de appeler m_debuggerWindow.SetScript(m_currentCode); directement, + // Au lieu de appeler m_debuggerWindow.SetScript(m_storyAssembly); directement, // AppController pourrait émettre un événement ou un callback. // Pour l'instant, on suppose une notification ou que la GUI tire les données. m_logger.Log("Nodes script generated for story."); Build(true); // Compile seulement par défaut } - } else if (type == IStoryProject::Type::PROJECT_TYPE_MODULE && m_module) { - // Logique de génération de script pour le module - // Similaire à BuildNodes pour le projet principal. - m_logger.Log("Nodes script generated for module."); + else + { + m_logger.Log("Failed to generate script for story.", true); + } + } + else if (type == IStoryProject::Type::PROJECT_TYPE_MODULE && m_module) + { + if (m_module->GenerateScript(m_storyAssembly)) + { + m_logger.Log("Nodes script generated for module."); + } + else + { + m_logger.Log("Failed to generate script for module.", true); + } } } @@ -282,7 +294,7 @@ void AppController::Build(bool compileonly) // La GUI (DebuggerWindow) doit être notifiée pour effacer les erreurs. FIXME // m_debuggerWindow.ClearErrors(); - if (m_story->GenerateBinary(m_currentCode, err)) + if (m_story->GenerateBinary(m_storyAssembly, err)) { m_result.Print(); // Imprime le résultat de l'assemblage (Debug uniquement) @@ -310,11 +322,11 @@ void AppController::Build(bool compileonly) void AppController::BuildCode(std::shared_ptr story, bool compileonly, bool force) { // Note: Dans le code original, BuildCode lisait m_externalSourceFileName. - // Il faut s'assurer que m_currentCode est bien défini avant d'appeler Build. + // Il faut s'assurer que m_storyAssembly est bien défini avant d'appeler Build. if (story) { - m_currentCode = SysLib::ReadFile(story->GetProjectFilePath()); // Simplifié pour l'exemple + m_storyAssembly = SysLib::ReadFile(story->GetProjectFilePath()); // Simplifié pour l'exemple // La GUI (DebuggerWindow) doit être notifiée pour SetScript. - // m_debuggerWindow.SetScript(m_currentCode); + // m_debuggerWindow.SetScript(m_storyAssembly); Build(compileonly); } else { m_logger.Log("No story provided for BuildCode.", true); @@ -324,17 +336,17 @@ void AppController::BuildCode(std::shared_ptr story, bool compileo void AppController::BuildCode(bool compileonly) { - m_currentCode = SysLib::ReadFile(m_externalSourceFileName); - // m_debuggerWindow.SetScript(m_currentCode); // FIXME: GUI event + m_storyAssembly = SysLib::ReadFile(m_externalSourceFileName); + // m_debuggerWindow.SetScript(m_storyAssembly); // FIXME: GUI event Build(compileonly); } -void AppController::BuildNodes(bool compileonly) +void AppController::CompileNodes(bool compileonly) { - if (m_story->GenerateScript(m_currentCode)) + if (m_story->GenerateScript(m_storyAssembly)) { - // m_debuggerWindow.SetScript(m_currentCode); // FIXME: GUI event + // m_debuggerWindow.SetScript(m_storyAssembly); // FIXME: GUI event Build(compileonly); } } diff --git a/story-editor/src/app/app_controller.h b/story-editor/src/app/app_controller.h index 7831bdc..5971d05 100644 --- a/story-editor/src/app/app_controller.h +++ b/story-editor/src/app/app_controller.h @@ -67,7 +67,7 @@ public: void ExportStory(const std::string &filename); std::shared_ptr GetCurrentStory() const { return m_story; } std::shared_ptr GetCurrentModule() const { return m_module; } - void BuildNodes(IStoryProject::Type type); + void CompileNodes(IStoryProject::Type type); void Build(bool compileonly); void BuildCode(std::shared_ptr story, bool compileonly, bool force = false); @@ -86,7 +86,7 @@ public: virtual void Next() override; virtual void Previous() override; virtual std::string VmState() const override; - virtual void BuildNodes(bool compileonly); + virtual void CompileNodes(bool compileonly); virtual void BuildCode(bool compileonly); virtual std::shared_ptr GetCurrentProject() override; @@ -133,7 +133,8 @@ private: chip32_ctx_t m_chip32_ctx; Chip32::Result m_result; DebugContext m_dbg; // Contexte de débogage - std::string m_currentCode; + std::string m_storyAssembly; + std::string m_moduleAssembly; std::string m_externalSourceFileName; std::vector m_recentProjects; diff --git a/story-editor/src/docks/emulator_dock.cpp b/story-editor/src/docks/emulator_dock.cpp index 9e86299..631243e 100644 --- a/story-editor/src/docks/emulator_dock.cpp +++ b/story-editor/src/docks/emulator_dock.cpp @@ -83,7 +83,7 @@ void EmulatorDock::Draw() if (ImGui::Button("Build nodes")) { - m_story.BuildNodes(true); + m_story.CompileNodes(true); } ImGui::SameLine(); if (ImGui::Button("Build code")) diff --git a/story-editor/src/main_window.cpp b/story-editor/src/main_window.cpp index ff1479b..5205274 100644 --- a/story-editor/src/main_window.cpp +++ b/story-editor/src/main_window.cpp @@ -399,6 +399,20 @@ void MainWindow::DrawToolBar(float topPadding) m_appController.StopAudio(); } + if (ImGui::Button(ICON_MDI_HAMMER "##build_project", ImVec2(-1, 50))) { // Le bouton prend toute la largeur de la fenêtre et a une hauteur de 50 pixels + + // Compile story if window focused, otherwise module + if (m_nodeEditorWindow.IsFocused()) + { + m_appController.CompileNodes(IStoryProject::PROJECT_TYPE_STORY); + } + else + { + m_appController.CompileNodes(IStoryProject::PROJECT_TYPE_MODULE); + } + } + + ImGui::GetFont()->Scale = old_size; ImGui::PopFont(); ImGui::PopStyleColor();