Separated call function module, better module support with type
Some checks failed
Build-StoryEditor / build_linux (push) Has been cancelled
Build-StoryEditor / build_win32 (push) Has been cancelled
Deploy-Documentation / deploy (push) Has been cancelled

This commit is contained in:
anthony@rabine.fr 2025-07-16 12:15:00 +02:00
parent 81f7e9343b
commit 8aec974f89
19 changed files with 246 additions and 83 deletions

View file

@ -32,7 +32,7 @@ class IStoryManager
public:
virtual ~IStoryManager() {}
virtual void OpenProject(const std::string &uuid, IStoryManager::ProjectType type) = 0;
virtual void OpenProject(const std::string &uuid) = 0;
virtual void ImportProject(const std::string &fileName, int format) = 0;
virtual void Log(const std::string &txt, bool critical = false) = 0;
virtual void PlaySoundFile(const std::string &fileName) = 0;

View file

@ -17,6 +17,8 @@ public:
virtual ~IStoryProject() {};
virtual std::string GetName() const = 0;
virtual std::list<std::shared_ptr<Connection>> GetNodeConnections(const std::string &nodeId) = 0;
virtual int OutputsCount(const std::string &nodeId) = 0;
virtual StoryOptions GetOptions() = 0;

View file

@ -7,7 +7,8 @@
#include "json.hpp"
// #include "media_node.h"
#include "function_node.h"
#include "call_function_node.h"
#include "module_node.h"
#include "variable_node.h"
#include "operator_node.h"
#include "print_node.h"
@ -15,10 +16,12 @@
#include "story_project.h"
static const std::string OperatorNodeUuid = "0226fdac-8f7a-47d7-8584-b23aceb712ec";
static const std::string FunctionNodeUuid = "02745f38-9b11-49fe-94b1-b2a6b78249fb";
static const std::string CallFunctionNodeUuid = "02745f38-9b11-49fe-94b1-b2a6b78249fb";
static const std::string VariableNodeUuid = "020cca4e-9cdc-47e7-a6a5-53e4c9152ed0";
static const std::string PrintNodeUuid = "02ee27bc-ff1d-4f94-b700-eab55052ad1c";
static const std::string SyscallNodeUuid = "02225cff-4975-400e-8130-41524d8af773";
static const std::string ModuleNodeUuid = "02e4c728-ef72-4003-b7c8-2bee8834a47e";
typedef std::shared_ptr<BaseNode> (*GenericCreator)(const std::string &type);
@ -26,7 +29,6 @@ class NodesFactory
{
public:
NodesFactory(ILogger &log)
: m_log(log)
, m_rootPath("")
@ -34,7 +36,7 @@ public:
// Register node types
// registerNode<MediaNode>("media-node");
registerNode<OperatorNode>(OperatorNodeUuid, nullptr);
registerNode<FunctionNode>(FunctionNodeUuid, nullptr);
registerNode<CallFunctionNode>(CallFunctionNodeUuid, nullptr);
registerNode<VariableNode>(VariableNodeUuid, nullptr);
registerNode<PrintNode>(PrintNodeUuid, nullptr);
registerNode<SyscallNode>(SyscallNodeUuid, nullptr);
@ -62,6 +64,29 @@ public:
}
}
std::shared_ptr<StoryProject> GetModule(const std::string &name)
{
std::shared_ptr<StoryProject> module;
// Scan all function nodes and find the one with that name
for (auto n : m_registry)
{
if (n.first == ModuleNodeUuid)
{
if (n.second.first)
{
// We have a module here, get the name
if (n.second.first->GetName() == name)
{
module = n.second.first;
}
}
}
}
return module;
}
void SetModulesRootDirectory(const std::string &rootPath) {
m_rootPath = rootPath;
}
@ -92,7 +117,7 @@ public:
if (p->IsModule())
{
registerNode<FunctionNode>(FunctionNodeUuid, p);
registerNode<ModuleNode>(ModuleNodeUuid, p);
// For now, function node use only primitives nodes
// FIXME: in the future, allow function node to use other function nodes
// Need a list of required nodes to be registered
@ -118,12 +143,11 @@ private:
};
// UUID is the key, and the value is a function that creates the node
typedef std::map<std::string, std::pair<std::shared_ptr<IStoryProject>, GenericCreator>> Registry;
typedef std::map<std::string, std::pair<std::shared_ptr<StoryProject>, GenericCreator>> Registry;
Registry m_registry;
template<class Derived>
void registerNode(const std::string& uuid, std::shared_ptr<IStoryProject> moduleInfo = nullptr) {
info.creator = ;
m_registry.insert(typename Registry::value_type(uuid, std::make_pair<moduleInfo, Factory<Derived>::create_func>));
void registerNode(const std::string& uuid, std::shared_ptr<StoryProject> moduleInfo) {
m_registry.insert(std::make_pair(uuid, std::make_pair(moduleInfo, Factory<Derived>::create_func)));
}
};

View file

@ -1,17 +1,17 @@
#include "function_node.h"
#include "call_function_node.h"
#include "story_project.h"
#include "connection.h"
#include "sys_lib.h"
FunctionNode::FunctionNode(const std::string &type)
: BaseNode(type, "Function Node")
CallFunctionNode::CallFunctionNode(const std::string &type)
: BaseNode(type, "Call Function Node")
{
nlohmann::json j{ {"function", ""} };
SetInternalData(j);
}
void FunctionNode::Initialize()
void CallFunctionNode::Initialize()
{
nlohmann::json j = GetInternalData();
// m_image = j["image"].get<std::string>();

View file

@ -0,0 +1,19 @@
#pragma once
#include <string>
#include "i_story_manager.h"
#include "base_node.h"
#include "i_script_node.h"
#include "i_story_project.h"
class CallFunctionNode : public BaseNode
{
public:
CallFunctionNode(const std::string &type);
virtual void Initialize() override;
private:
nlohmann::json m_content;
};

View file

@ -0,0 +1,20 @@
#include "module_node.h"
#include "story_project.h"
#include "connection.h"
#include "sys_lib.h"
ModuleNode::ModuleNode(const std::string &type)
: BaseNode(type, "Module Node")
{
nlohmann::json j{ {"module", ""} };
SetInternalData(j);
}
void ModuleNode::Initialize()
{
nlohmann::json j = GetInternalData();
// m_image = j["image"].get<std::string>();
// m_sound = j["sound"].get<std::string>();
}

View file

@ -6,10 +6,10 @@
#include "i_script_node.h"
#include "i_story_project.h"
class FunctionNode : public BaseNode
class ModuleNode : public BaseNode
{
public:
FunctionNode(const std::string &type);
ModuleNode(const std::string &type);
virtual void Initialize() override;

View file

@ -8,13 +8,13 @@
#include "story_project.h"
#include "json.hpp"
// #include "media_node.h"
#include "function_node.h"
#include "variable_node.h"
#include "operator_node.h"
#include "print_node.h"
#include "syscall_node.h"
#include "sys_lib.h"
#include "assembly_generator_chip32.h"
#include "nodes_factory.h"
StoryProject::StoryProject(ILogger &log)
: m_log(log)

View file

@ -16,7 +16,8 @@
#include "story_page.h"
#include "story_options.h"
#include "variable.h"
#include "nodes_factory.h"
class NodesFactory;
struct StoryProject : public IStoryProject
{
@ -65,7 +66,7 @@ public:
std::string GetProjectFilePath() const;
std::string GetWorkingDir() const;
std::string GetName() const { return m_name; }
virtual std::string GetName() const override { return m_name; }
std::string GetUuid() const { return m_uuid; }
std::string GetDescription() const { return m_description; }
uint32_t GetVersion() const { return m_version; }

View file

@ -133,7 +133,8 @@ set(SRCS
# src/node_editor/media_node_widget.cpp
src/node_editor/base_node_widget.cpp
src/node_editor/node_editor_window.cpp
src/node_editor/function_node_widget.cpp
src/node_editor/call_function_node_widget.cpp
src/node_editor/module_node_widget.cpp
src/node_editor/variable_node_widget.cpp
src/node_editor/operator_node_widget.cpp
src/node_editor/print_node_widget.cpp
@ -179,7 +180,8 @@ set(SRCS
../core/story-manager/src/nodes/compare_node.cpp
../core/story-manager/src/nodes/branch_node.cpp
../core/story-manager/src/nodes/variable_node.cpp
../core/story-manager/src/nodes/function_node.cpp
../core/story-manager/src/nodes/call_function_node.cpp
../core/story-manager/src/nodes/module_node.cpp
../core/story-manager/src/nodes/print_node.cpp
../core/story-manager/src/nodes/syscall_node.cpp
../core/story-manager/src/nodes/connection.cpp

View file

@ -9,8 +9,8 @@ Size=400,400
Collapsed=0
[Window][Library Manager]
Pos=628,26
Size=652,268
Pos=796,26
Size=484,268
Collapsed=0
DockId=0x00000003,0
@ -21,32 +21,32 @@ Collapsed=0
DockId=0x00000004,0
[Window][Emulator]
Pos=628,26
Size=652,268
Pos=796,26
Size=484,268
Collapsed=0
DockId=0x00000003,5
[Window][Code viewer]
Pos=628,26
Size=652,268
Pos=796,26
Size=484,268
Collapsed=0
DockId=0x00000003,4
[Window][Resources]
Pos=628,26
Size=652,268
Pos=796,26
Size=484,268
Collapsed=0
DockId=0x00000003,1
[Window][Node editor]
Pos=60,26
Size=566,439
Size=734,439
Collapsed=0
DockId=0x00000001,0
DockId=0x00000001,1
[Window][TOOLBAR]
Pos=76,71
Size=79,42
Size=150,42
Collapsed=0
[Window][Variables]
@ -56,20 +56,20 @@ Collapsed=0
DockId=0x00000005,0
[Window][CPU]
Pos=628,26
Size=652,268
Pos=796,26
Size=484,268
Collapsed=0
DockId=0x00000003,2
[Window][RAM view]
Pos=628,26
Size=652,268
Pos=796,26
Size=484,268
Collapsed=0
DockId=0x00000003,3
[Window][Properties]
Pos=628,296
Size=652,169
Pos=796,296
Size=484,169
Collapsed=0
DockId=0x00000006,0
@ -88,6 +88,18 @@ Pos=381,236
Size=518,248
Collapsed=0
[Window][Module editor]
Pos=60,26
Size=734,439
Collapsed=0
DockId=0x00000001,1
[Window][Story editor]
Pos=60,26
Size=734,439
Collapsed=0
DockId=0x00000001,0
[Table][0x7728942D,5]
RefScale=20
Column 0 Width=44 Sort=0v
@ -110,9 +122,9 @@ Column 2 Width=124
[Docking][Data]
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=60,26 Size=1220,694 Split=Y
DockNode ID=0x00000007 Parent=0x08BD597D SizeRef=1220,439 Split=X
DockNode ID=0x00000001 Parent=0x00000007 SizeRef=820,694 CentralNode=1 Selected=0xBB79A587
DockNode ID=0x00000002 Parent=0x00000007 SizeRef=652,694 Split=Y Selected=0x52EB28B5
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=718,268 Selected=0x30401527
DockNode ID=0x00000001 Parent=0x00000007 SizeRef=734,694 CentralNode=1 Selected=0x93ADCAAB
DockNode ID=0x00000002 Parent=0x00000007 SizeRef=484,694 Split=Y Selected=0x52EB28B5
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=718,268 Selected=0x4B07C626
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=718,169 Selected=0x8C72BEA8
DockNode ID=0x00000008 Parent=0x08BD597D SizeRef=1220,253 Split=X Selected=0xEA83D666
DockNode ID=0x00000004 Parent=0x00000008 SizeRef=610,192 Selected=0xEA83D666

View file

@ -1,13 +1,13 @@
#include <sstream>
#include "function_node_widget.h"
#include "call_function_node_widget.h"
namespace ed = ax::NodeEditor;
#include "IconsMaterialDesignIcons.h"
#include "story_project.h"
#include "uuid.h"
FunctionNodeWidget::FunctionNodeWidget(IStoryManager &manager, std::shared_ptr<BaseNode> node)
CallFunctionNodeWidget::CallFunctionNodeWidget(IStoryManager &manager, std::shared_ptr<BaseNode> node)
: BaseNodeWidget(manager, node)
, m_manager(manager)
{
@ -19,7 +19,7 @@ FunctionNodeWidget::FunctionNodeWidget(IStoryManager &manager, std::shared_ptr<B
m_functionUuid = Uuid().String();
}
void FunctionNodeWidget::Draw()
void CallFunctionNodeWidget::Draw()
{
BaseNodeWidget::FrameStart();
@ -35,13 +35,13 @@ void FunctionNodeWidget::Draw()
}
void FunctionNodeWidget::Initialize()
void CallFunctionNodeWidget::Initialize()
{
BaseNodeWidget::Initialize();
m_functionName = "Function";
}
void FunctionNodeWidget::DrawProperties()
void CallFunctionNodeWidget::DrawProperties()
{

View file

@ -0,0 +1,33 @@
#pragma once
#include <vector>
#include <map>
#include <mutex>
#include <set>
#include "base_node_widget.h"
#include "i_story_manager.h"
#include "i_story_project.h"
#include "call_function_node.h"
#include "gui.h"
#include <imgui_node_editor.h>
class CallFunctionNodeWidget : public BaseNodeWidget
{
public:
CallFunctionNodeWidget(IStoryManager &manager, std::shared_ptr<BaseNode> node);
void Draw() override;
virtual void DrawProperties() override;
virtual void Initialize() override;
private:
IStoryManager &m_manager;
std::shared_ptr<CallFunctionNode> m_callFunctionNode;
std::string m_functionName;
std::string m_functionUuid;
};

View file

@ -0,0 +1,47 @@
#include <sstream>
#include "module_node_widget.h"
namespace ed = ax::NodeEditor;
#include "IconsMaterialDesignIcons.h"
#include "story_project.h"
#include "uuid.h"
ModuleNodeWidget::ModuleNodeWidget(IStoryManager &manager, std::shared_ptr<BaseNode> node)
: BaseNodeWidget(manager, node)
, m_manager(manager)
{
// Create defaut one input and one output
AddInputs(1);
AddOutputs(2);
SetOutPinName(0, "Success");
SetOutPinName(1, "Failure");
}
void ModuleNodeWidget::Draw()
{
BaseNodeWidget::FrameStart();
ImGui::TextUnformatted(m_functionName.c_str());
DrawPins();
BaseNodeWidget::FrameEnd();
}
void ModuleNodeWidget::Initialize()
{
BaseNodeWidget::Initialize();
m_functionName = "Function";
}
void ModuleNodeWidget::DrawProperties()
{
}

View file

@ -12,10 +12,10 @@
#include <imgui_node_editor.h>
class FunctionNodeWidget : public BaseNodeWidget
class ModuleNodeWidget : public BaseNodeWidget
{
public:
FunctionNodeWidget(IStoryManager &manager, std::shared_ptr<BaseNode> node);
ModuleNodeWidget(IStoryManager &manager, std::shared_ptr<BaseNode> node);
void Draw() override;
@ -25,5 +25,5 @@ public:
private:
IStoryManager &m_manager;
std::string m_functionName;
std::string m_functionUuid;
};

View file

@ -10,7 +10,8 @@
#include "IconsFontAwesome5_c.h"
#include "media_node_widget.h"
#include "function_node_widget.h"
#include "call_function_node_widget.h"
#include "module_node_widget.h"
#include "variable_node_widget.h"
#include "operator_node_widget.h"
#include "print_node_widget.h"
@ -26,8 +27,8 @@ if (!(x)) { \
#include "json.hpp"
NodeEditorWindow::NodeEditorWindow(IStoryManager &manager, NodesFactory &factory, IStoryManager::ProjectType type)
: WindowBase(type == IStoryManager::ProjectType::PROJECT_TYPE_STORY ? "Story editor" : "Module editor")
NodeEditorWindow::NodeEditorWindow(IStoryManager &manager, NodesFactory &factory, IStoryProject::Type type)
: WindowBase(type == IStoryProject::Type::PROJECT_TYPE_STORY ? "Story editor" : "Module editor")
, m_manager(manager)
, m_nodesFactory(factory)
, m_editorType(type)
@ -35,7 +36,8 @@ NodeEditorWindow::NodeEditorWindow(IStoryManager &manager, NodesFactory &factory
// registerNode<MediaNodeWidget>("media-node");
registerNode<OperatorNodeWidget>("operator-node");
registerNode<FunctionNodeWidget>("function-node");
registerNode<CallFunctionNodeWidget>("call-function-node");
registerNode<ModuleNodeWidget>("module-node");
registerNode<VariableNodeWidget>("variable-node");
registerNode<PrintNodeWidget>("print-node");
registerNode<SyscallNodeWidget>("syscall-node");

View file

@ -8,6 +8,7 @@
#include "base_node_widget.h"
#include "window_base.h"
#include "i_story_manager.h"
#include "i_story_project.h"
#include "json.hpp"
#include "story_project.h"
#include "node_editor_page.h"
@ -27,7 +28,7 @@ class NodeEditorWindow : public WindowBase
{
public:
NodeEditorWindow(IStoryManager &manager, NodesFactory &factory, IStoryManager::ProjectType type = IStoryManager::ProjectType::PROJECT_TYPE_STORY);
NodeEditorWindow(IStoryManager &manager, NodesFactory &factory, IStoryProject::Type type = IStoryProject::Type::PROJECT_TYPE_STORY);
~NodeEditorWindow();
virtual void Draw() override;
@ -41,7 +42,7 @@ public:
private:
IStoryManager &m_manager;
NodesFactory &m_nodesFactory;
IStoryManager::ProjectType m_editorType{IStoryManager::ProjectType::PROJECT_TYPE_STORY};
IStoryProject::Type m_editorType{IStoryProject::Type::PROJECT_TYPE_STORY};
bool m_loaded{false};

View file

@ -24,13 +24,14 @@
MainWindow::MainWindow()
: m_resources(*this)
, m_nodesFactory(*this)
, m_libraryManager(*this, m_nodesFactory)
, m_emulatorWindow(*this)
, m_debuggerWindow(*this)
, m_cpuWindow(*this)
, m_resourcesWindow(*this)
, m_nodeEditorWindow(*this, m_nodesFactory)
, m_moduleEditorWindow(*this, m_nodesFactory, NodeEditorWindow::EditorType::NODE_EDITOR_MODULE)
, m_moduleEditorWindow(*this, m_nodesFactory, IStoryProject::Type::PROJECT_TYPE_MODULE)
, m_libraryWindow(*this, m_libraryManager)
, m_variablesWindow(*this)
, m_player(*this)
@ -604,7 +605,7 @@ bool MainWindow::ShowQuitConfirm()
// ImGui::SetNextWindowSize(ImVec2(200, 150));
if (ImGui::BeginPopupModal("QuitConfirm", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("Voulez-vous vraiment quitter le logiciel ?");
ImGui::Text("Really qui without saving?");
ImGui::Separator();
if (ImGui::Button("OK", ImVec2(120, 0)))
@ -837,7 +838,7 @@ void MainWindow::ProjectPropertiesPopup()
}
}
void MainWindow::SaveProject(IStoryManager::ProjectType type)
void MainWindow::SaveProject()
{
nlohmann::json model;
m_story->Save(m_resources);
@ -846,7 +847,7 @@ void MainWindow::SaveProject(IStoryManager::ProjectType type)
void MainWindow::OpenProject(const std::string &uuid)
{
CloseProject(IStoryManager::ProjectType::PROJECT_TYPE_STORY);
CloseProject();
m_story = m_libraryManager.GetStory(uuid);
@ -897,15 +898,15 @@ void MainWindow::OpenProject(const std::string &uuid)
void MainWindow::OpenModule(const std::string &uuid)
{
m_story = m_libraryManager.GetModule(uuid);
if (!m_story)
m_module = m_nodesFactory.GetModule(uuid);
if (!m_module)
{
Log("Cannot find module: " + uuid);
}
else if (m_story->Load(m_resources, m_nodesFactory))
else if (m_module->Load(m_resources, m_nodesFactory))
{
Log("Open module success");
m_moduleEditorWindow.Load(m_story);
m_moduleEditorWindow.Load(m_module);
}
else
{
@ -918,7 +919,7 @@ void MainWindow::OpenModule(const std::string &uuid)
void MainWindow::CloseProject(IStoryManager::ProjectType type)
void MainWindow::CloseProject()
{
// FIXME: not sure but if present, we lost some information in the library manager
@ -929,21 +930,9 @@ void MainWindow::CloseProject(IStoryManager::ProjectType type)
// }
m_resources.Clear();
m_nodeEditorWindow.Initialize();
m_nodeEditorWindow.Disable();
if (type == IStoryManager::ProjectType::PROJECT_TYPE_STORY)
{
m_nodeEditorWindow.Initialize();
m_nodeEditorWindow.Disable();
}
else if (type == IStoryManager::ProjectType::PROJECT_TYPE_MODULE)
{
m_moduleEditorWindow.Initialize();
m_moduleEditorWindow.Disable();
}
// FIXME: si un des deux types de projets est encore ouvert, on ne va pas fermer
// le sautres fenêtres de preview
m_emulatorWindow.ClearImage();
m_consoleWindow.ClearLog();
m_debuggerWindow.ClearErrors();
@ -960,6 +949,14 @@ void MainWindow::CloseProject(IStoryManager::ProjectType type)
}
void MainWindow::CloseModule()
{
m_moduleEditorWindow.Initialize();
m_moduleEditorWindow.Disable();
}
void MainWindow::ImportProject(const std::string &filePathName, int format)
{
(void) format;

View file

@ -84,7 +84,8 @@ public:
private:
enum VmEventType { EvNoEvent, EvStep, EvRun, EvOkButton, EvPreviousButton, EvNextButton, EvAudioFinished, EvStop, EvHomeButton};
std::shared_ptr<StoryProject> m_story;
std::shared_ptr<StoryProject> m_story; // Current story
std::shared_ptr<StoryProject> m_module; // Current module
// VM
uint8_t m_rom_data[16*1024];
@ -136,10 +137,12 @@ private:
WebServer m_webServer;
// From IStoryManager (proxy to StoryProject class)
virtual void OpenProject(const std::string &uuid, IStoryManager::ProjectType type) override;
void SaveProject(IStoryManager::ProjectType type);
void CloseProject(IStoryManager::ProjectType type);
virtual void OpenProject(const std::string &uuid) override;
void SaveProject();
void CloseProject();
void OpenModule(const std::string &uuid);
void CloseModule();
// From IStoryManager (proxy to StoryProject class)
virtual void ImportProject(const std::string &filePathName, int format);