From 3d9b60cb32dd407653a1f09af0a68074cdcd1c5f Mon Sep 17 00:00:00 2001 From: "anthony@rabine.fr" Date: Mon, 30 Dec 2024 15:50:14 +0100 Subject: [PATCH] (WIP) Commercial import --- story-editor/src/code_editor.cpp | 36 +++++++++++---------- story-editor/src/importers/pack_archive.cpp | 29 ++++++++++------- story-editor/src/importers/pack_archive.h | 5 +-- story-editor/src/library_window.cpp | 15 ++++----- story-editor/src/main_window.cpp | 11 +++++-- 5 files changed, 55 insertions(+), 41 deletions(-) diff --git a/story-editor/src/code_editor.cpp b/story-editor/src/code_editor.cpp index 1da9457..a6fc60d 100644 --- a/story-editor/src/code_editor.cpp +++ b/story-editor/src/code_editor.cpp @@ -72,7 +72,7 @@ void CodeEditor::TextViewDraw() CodeEditor::CodeEditor(IStoryManager &project) - : WindowBase("Code editor") + : WindowBase("Code viewer") , m_storyManager(project) { // mEditor.SetReadOnly(false); @@ -109,19 +109,19 @@ void CodeEditor::SetScript(const std::string &txt) { m_text = txt; - m_text = R"( - fdsfds - fds -ffffffffffffffffffffff - ff - fd -feeeee - 21234f -e - fdsfs - )"; +// m_text = R"( +// fdsfds +// fds +// ffffffffffffffffffffff +// ff +// fd +// feeeee +// 21234f +// e +// fdsfs +// )"; - HighlightLine(2); +// HighlightLine(2); } std::string CodeEditor::GetScript() const @@ -139,6 +139,7 @@ void CodeEditor::Draw() // auto cpos = mEditor.GetCursorPosition(); ImGui::SetWindowSize(ImVec2(800, 600), ImGuiCond_FirstUseEver); + /* if (ImGui::BeginMenuBar()) { if (ImGui::BeginMenu("File")) @@ -156,7 +157,7 @@ void CodeEditor::Draw() // if (ImGui::MenuItem("Read-only mode", nullptr, &ro)) // mEditor.SetReadOnly(ro); ImGui::Separator(); -/* + if (ImGui::MenuItem("Undo", "ALT-Backspace", nullptr, !ro && mEditor.CanUndo())) mEditor.Undo(); if (ImGui::MenuItem("Redo", "Ctrl-Y", nullptr, !ro && mEditor.CanRedo())) @@ -172,7 +173,7 @@ void CodeEditor::Draw() mEditor.Delete(); if (ImGui::MenuItem("Paste", "Ctrl-V", nullptr, !ro && ImGui::GetClipboardText() != nullptr)) mEditor.Paste(); - */ + ImGui::Separator(); @@ -181,7 +182,7 @@ void CodeEditor::Draw() ImGui::EndMenu(); } -/* + if (ImGui::BeginMenu("View")) { if (ImGui::MenuItem("Dark palette")) @@ -192,9 +193,10 @@ void CodeEditor::Draw() mEditor.SetPalette(TextEditor::GetRetroBluePalette()); ImGui::EndMenu(); } - */ + ImGui::EndMenuBar(); } + */ // ImGui::Text("%6d/%-6d %6d lines | %s | %s ", cpos.mLine + 1, cpos.mColumn + 1, mEditor.GetTotalLines(), // mEditor.IsOverwrite() ? "Ovr" : "Ins", diff --git a/story-editor/src/importers/pack_archive.cpp b/story-editor/src/importers/pack_archive.cpp index 85b940c..65d607a 100644 --- a/story-editor/src/importers/pack_archive.cpp +++ b/story-editor/src/importers/pack_archive.cpp @@ -156,25 +156,32 @@ std::vector PackArchive::FilesToJson(const std::string &type, const return resList; } -void PackArchive::DecipherAll(const std::string &packFileName, const std::string &parent_dest_dir) +void PackArchive::ImportCommercialFormat(const std::string &packFileName, const std::string &outputDir) { -// return; + auto uuid = Uuid().String(); + std::string basePath = outputDir + "/" + uuid; - Unzip(packFileName, parent_dest_dir); - Load(packFileName); + Unzip(packFileName, basePath); + LoadNiFile(packFileName); - std::string path = mPackName + "/rf"; + std::string path = basePath + "/" + mPackName + "/rf"; for (const auto & entry : std::filesystem::directory_iterator(path)) { - std::cout << entry.path() << std::endl; - DecipherFiles(entry.path().generic_string(), ".bmp"); + if (entry.is_directory()) + { + std::cout << entry.path() << std::endl; + DecipherFiles(entry.path().generic_string(), ".bmp"); + } } - path = mPackName + "/sf"; + path = basePath + "/" + mPackName + "/sf"; for (const auto & entry : std::filesystem::directory_iterator(path)) { - std::cout << entry.path() << std::endl; - DecipherFiles(entry.path().generic_string(), ".mp3"); + if (entry.is_directory()) + { + std::cout << entry.path() << std::endl; + DecipherFiles(entry.path().generic_string(), ".mp3"); + } } nlohmann::json j; @@ -333,7 +340,7 @@ $MyArray DV8 10 ; array of 10 bytes chip32.close(); } -bool PackArchive::Load(const std::string &filePath) +bool PackArchive::LoadNiFile(const std::string &filePath) { bool success = false; mZip.Close(); diff --git a/story-editor/src/importers/pack_archive.h b/story-editor/src/importers/pack_archive.h index fcc1a33..45f57c9 100644 --- a/story-editor/src/importers/pack_archive.h +++ b/story-editor/src/importers/pack_archive.h @@ -13,10 +13,11 @@ class PackArchive public: PackArchive(ILogger &log); - bool Load(const std::string &filePath); + bool LoadNiFile(const std::string &filePath); std::string OpenImage(const std::string &fileName); bool ImportStudioFormat(const std::string &fileName, const std::string &outputDir); + void ImportCommercialFormat(const std::string &packFileName, const std::string &outputDir); std::string CurrentImage(); std::string CurrentSound(); @@ -31,7 +32,7 @@ public: void Next(); void Previous(); void Unzip(const std::string &filePath, const std::string &parent_dest_dir); - void DecipherAll(const std::string &packFileName, const std::string &parent_dest_dir); + bool ConvertJsonStudioToOst(const std::string &basePath, const std::string &uuid, const std::string &outputDir); std::string HexDump(const char *desc, const void *addr, int len); diff --git a/story-editor/src/library_window.cpp b/story-editor/src/library_window.cpp index 1b0013a..d86b588 100644 --- a/story-editor/src/library_window.cpp +++ b/story-editor/src/library_window.cpp @@ -348,8 +348,9 @@ inline void InfosPane(const char *vFilter, IGFDUserDatas vUserDatas, bool *vCant ImGui::Text("Select file format: "); - ImGui::RadioButton("Commercial stories", &formatFilter, 0); ImGui::SameLine(); - ImGui::RadioButton("Studio format", &formatFilter, 1); ImGui::SameLine(); + ImGui::RadioButton("Studio format", &formatFilter, 0); ImGui::SameLine(); + ImGui::RadioButton("Commercial stories", &formatFilter, 1); ImGui::SameLine(); + // ImGui::Checkbox("if not checked you cant validate the dialog", &canValidateDialog); if (vCantContinue) @@ -367,8 +368,6 @@ std::string LibraryWindow::ToLocalStoreFile(const std::string &url) void LibraryWindow::Draw() { - static int importFormat = 0; - WindowBase::BeginDraw(); ImGui::SetWindowSize(ImVec2(626, 744), ImGuiCond_FirstUseEver); @@ -437,7 +436,7 @@ void LibraryWindow::Draw() config.flags = ImGuiFileDialogFlags_Modal; ImGuiFileDialog::Instance()->OpenDialog("ImportStoryDlgKey", "Import story", - ".zip, .json", + ".zip, .json, .pk", config ); } @@ -609,10 +608,8 @@ void LibraryWindow::Draw() std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); std::string filter = ImGuiFileDialog::Instance()->GetCurrentFilter(); - - m_storyManager.ImportProject(filePathName, importFormat); - - // action + // Import "Studio" or "Commercial" format + m_storyManager.ImportProject(filePathName, formatFilter); } // close ImGuiFileDialog::Instance()->Close(); diff --git a/story-editor/src/main_window.cpp b/story-editor/src/main_window.cpp index 7d24699..d5afe96 100644 --- a/story-editor/src/main_window.cpp +++ b/story-editor/src/main_window.cpp @@ -797,7 +797,14 @@ void MainWindow::ImportProject(const std::string &fileName, int format) { PackArchive archive(*this); - archive.ImportStudioFormat(fileName, m_libraryManager.LibraryPath()); + if (format == 0) + { + archive.ImportStudioFormat(fileName, m_libraryManager.LibraryPath()); + } + else + { + archive.ImportCommercialFormat(fileName, m_libraryManager.LibraryPath()); + } } @@ -831,7 +838,7 @@ void MainWindow::CloseProject() m_nodeEditorWindow.Disable(); m_emulatorWindow.Disable(); - // m_codeEditorWindow.Disable(); + m_codeEditorWindow.Disable(); m_resourcesWindow.Disable(); m_PropertiesWindow.Disable(); m_cpuWindow.Disable();