Skip to content

Commit

Permalink
more separation between node UI logic and editor, working Studio form…
Browse files Browse the repository at this point in the history
…at support
  • Loading branch information
arabine committed Apr 24, 2024
1 parent 6c4ffbb commit a6dbc90
Show file tree
Hide file tree
Showing 19 changed files with 536 additions and 340 deletions.
42 changes: 23 additions & 19 deletions story-editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ set(BUILD_SHARED_LIBS TRUE)
set(SDL_STATIC TRUE)
FetchContent_MakeAvailable(sdl3)
include_directories(${sdl3_SOURCE_DIR}/include)
# add_subdirectory(${sdl3_SOURCE_DIR})

# =========================================================================================================================
# SDL3-Image
Expand Down Expand Up @@ -127,20 +128,25 @@ set(SRCS
src/main_window.cpp
src/main_window.h

src/node_editor_window.cpp
src/node_editor_window.h

src/library_window.cpp
src/library_window.h

src/media_node.h
src/media_node.cpp

src/platform_folders.cpp
src/platform_folders.h

src/base_node.h
src/base_node.cpp
src/node_engine/base_node.h
src/node_engine/base_node.cpp
src/node_engine/connection.cpp
src/node_engine/connection.h


src/node_editor/media_node.h
src/node_editor/media_node.cpp
src/node_editor/base_node_widget.h
src/node_editor/base_node_widget.cpp
src/node_editor/node_editor_window.h
src/node_editor/node_editor_window.cpp

src/resources_window.cpp
src/resources_window.h
Expand All @@ -154,9 +160,6 @@ set(SRCS
src/code_editor.cpp
src/code_editor.h

src/connection.cpp
src/connection.h

src/media_converter.cpp
src/media_converter.h

Expand Down Expand Up @@ -234,6 +237,8 @@ target_include_directories(${STORY_EDITOR_PROJECT} PUBLIC

${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/importers
${CMAKE_SOURCE_DIR}/src/node_editor
${CMAKE_SOURCE_DIR}/src/node_engine

../firmware/library
../firmware/chip32
Expand Down Expand Up @@ -271,15 +276,16 @@ target_compile_definitions(${STORY_EDITOR_PROJECT} PUBLIC "$<$<CONFIG:DEBUG>:DEB

target_link_directories(${STORY_EDITOR_PROJECT} PUBLIC ${sdl3_BINARY_DIR} ${curl_BINARY_DIR} ${CMAKE_BINARY_DIR}/libs/SDL_image)


set(SDL2_BIN_DIR ${sdl3_BINARY_DIR})
# On est obligé de passer par une variable pour injecter
# certaines informations à CPACK
set(SDL_BIN_DIR ${sdl3_BINARY_DIR})

if(UNIX)
target_link_libraries(${STORY_EDITOR_PROJECT}
pthread
OpenGL::GL
dl
SDL3
SDL3::SDL3
SDL3_image
libcurl_static
OpenSSL::SSL OpenSSL::Crypto
Expand Down Expand Up @@ -313,21 +319,19 @@ install_files("." FILES "${CMAKE_SOURCE_DIR}/LICENSE")
install_files("." FILES "${CMAKE_SOURCE_DIR}/tools/imgui.ini")

if(WIN32)
install_files("." FILES "${SDL2_BIN_DIR}/SDL2.dll")
install_files("." FILES "${SDL_BIN_DIR}/SDL3.dll")
install_files("." FILES "/usr/lib/gcc/x86_64-w64-mingw32/10-posix/libstdc++-6.dll")
install_files("." FILES "/usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll")
install_files("." FILES "/usr/lib/gcc/x86_64-w64-mingw32/10-posix/libgcc_s_seh-1.dll")
endif()

# Personnaliser l'icône pour les installateurs Windows
if(WIN32)
set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/story-editor-logo.ico")
# Personnaliser l'icône pour les installateurs Windows
set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/story-editor-logo.ico")
endif()

if (APPLE)
set(CPACK_GENERATOR "DragNDrop")
set(MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/bundle.plist.in)
install_files("." FILES "${SDL2_BIN_DIR}/libSDL2-2.0.0.dylib")
install_files("." FILES "${SDL_BIN_DIR}/libSDL2-2.0.0.dylib")
endif()

include(CPack)
4 changes: 2 additions & 2 deletions story-editor/src/i_story_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class IStoryManager

// Node interaction
virtual void Build() = 0;
virtual std::list<std::shared_ptr<Connection>> GetNodeConnections(unsigned long nodeId) = 0;
virtual std::string GetNodeEntryLabel(unsigned long nodeId) = 0;
virtual std::list<std::shared_ptr<Connection>> GetNodeConnections(const std::string &nodeId) = 0;
virtual std::string GetNodeEntryLabel(const std::string &nodeId) = 0;
virtual void Play() = 0;
virtual void Ok() = 0;
virtual void Pause() = 0;
Expand Down
131 changes: 126 additions & 5 deletions story-editor/src/importers/pack_archive.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#include "pack_archive.h"
#include "ni_parser.h"
#include "json.hpp"
#include "serializers.h"

#include <iostream>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <filesystem>


#include "pack_archive.h"
#include "ni_parser.h"
#include "json.hpp"
#include "serializers.h"
#include "story_project.h"
#include "resource_manager.h"
#include "uuid.h"

PackArchive::PackArchive()
{

Expand Down Expand Up @@ -411,6 +415,123 @@ std::string PackArchive::OpenImage(const std::string &fileName)
return f;
}

bool PackArchive::ImportStudioFormat(const std::string &fileName, const std::string &outputDir)
{
auto uuid = UUID().String();
std::string basePath = outputDir + "/" + uuid;
Unzip(fileName, basePath);

try
{

// STUDIO format
std::ifstream f(basePath + "/story.json");
nlohmann::json j = nlohmann::json::parse(f);
StoryProject proj;
ResourceManager res;
nlohmann::json model;

if (j.contains("title"))
{
proj.New(uuid, outputDir);
proj.SetName(j["title"].get<std::string>());

// Create resources, scan asset files
std::filesystem::path directoryPath(basePath + "/assets");
if (std::filesystem::exists(directoryPath) && std::filesystem::is_directory(directoryPath))
{
for (const auto& entry : std::filesystem::directory_iterator(directoryPath))
{
if (std::filesystem::is_regular_file(entry.path()))
{
// Si c'est un sous-répertoire, récursivement scanner le contenu
auto rData = std::make_shared<Resource>();

rData->file = entry.path().filename();
rData->type = ResourceManager::ExtentionInfo(entry.path().extension(), 1);
rData->format = ResourceManager::ExtentionInfo(entry.path().extension(), 0);
res.Add(rData);
}
}
}

// Key: actionNode, value: Stage UUID
std::map<std::string, std::string> stageActionLink;

nlohmann::json jnodes = nlohmann::json::array();
for (const auto & n : j["stageNodes"])
{
nlohmann::json node;

auto node_uuid = n["uuid"].get<std::string>();
node["uuid"] = node_uuid;
node["type"] = "media-node";
node["position"] = n["position"];

nlohmann::json internalData;
auto img = n["image"];
internalData["image"] = img.is_string() ? img.get<std::string>() : "";
auto audio = n["audio"];
internalData["sound"] = audio.is_string() ? audio.get<std::string>() : "";

node["internal-data"] = internalData;

stageActionLink[n["okTransition"]["actionNode"]] = node_uuid;
/*
"okTransition":{
"actionNode":"19d7328f-d0d2-4443-a7a2-25270dafe52c",
"optionIndex":0
},
*/

jnodes.push_back(node);
}

model["nodes"] = jnodes;

nlohmann::json connections = nlohmann::json::array();

for (const auto & n : j["actionNodes"])
{
std::string action_node_uuid = n["id"].get<std::string>(); // le champs est "id" et non pas "uuid", pénible

if (stageActionLink.count(action_node_uuid) > 0)
{

int i = 0;
for (const auto & m : n["options"])
{
nlohmann::json c;

c["outNodeId"] = stageActionLink[action_node_uuid];
c["outPortIndex"] = i;
c["inNodeId"] = m; // On prend le stage node;
c["inPortIndex"] = 0;

i++;
connections.push_back(c);
}
}
else
{
std::cout << "ActionNode UUID not found" << std::endl;
}
}

model["connections"] = connections;

// Save on disk
proj.Save(model, res);
}
}
catch(std::exception &e)
{
std::cout << e.what() << std::endl;
}

return false;
}

std::string PackArchive::GetImage(const std::string &fileName)
{
//"C8B39950DE174EAA8E852A07FC468267/rf/000/05FB5530"
Expand Down
3 changes: 3 additions & 0 deletions story-editor/src/importers/pack_archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class PackArchive

bool Load(const std::string &filePath);
std::string OpenImage(const std::string &fileName);

bool ImportStudioFormat(const std::string &fileName, const std::string &outputDir);

std::string CurrentImage();
std::string CurrentSound();
std::string CurrentSoundName();
Expand Down
Loading

0 comments on commit a6dbc90

Please sign in to comment.