From 79a68a7b81c5392b7b79b51a50b9f314c7d3ffba Mon Sep 17 00:00:00 2001 From: Greg Williamson Date: Fri, 7 Aug 2020 19:31:40 -0400 Subject: [PATCH] egm supp (#138) --- MainWindow.cpp | 55 ++++++++++++++++++++++++++++++++-------- MainWindow.h | 10 ++++++++ Plugins/ServerPlugin.cpp | 29 +++++++-------------- RadialGM.pro | 2 -- Submodules/enigma-dev | 2 +- images.qrc | 1 + 6 files changed, 66 insertions(+), 33 deletions(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index 0462bf060..8278f8954 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -33,9 +33,13 @@ #include #include +#include +#include #undef GetMessage +QList MainWindow::EnigmaSearchPaths = {QDir::currentPath(), "./enigma-dev", "../enigma-dev", "../RadialGM/Submodules/enigma-dev"}; +QFileInfo MainWindow::EnigmaRoot = MainWindow::getEnigmaRoot(); QList MainWindow::systemCache; MainWindow *MainWindow::_instance = nullptr; QScopedPointer MainWindow::resourceMap; @@ -73,7 +77,7 @@ void diagnosticHandler(QtMsgType type, const QMessageLogContext &context, const std::cerr << msgFormatted.toStdString() << std::endl; - if (diagnosticTextEdit) { + if (diagnosticTextEdit != nullptr) { diagnosticTextEdit->append(msgFormatted); } else { // this should never happen! @@ -81,7 +85,36 @@ void diagnosticHandler(QtMsgType type, const QMessageLogContext &context, const } } -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _ui(new Ui::MainWindow) { +QFileInfo MainWindow::getEnigmaRoot() { + QFileInfo EnigmaRoot; + foreach (auto path, EnigmaSearchPaths) { + const QDir dir(path); + QDir::Filters filters = QDir::Filter::AllEntries; + auto entryList = dir.entryInfoList(QStringList({"ENIGMAsystem"}), filters, QDir::SortFlag::NoSort); + if (!entryList.empty()) { + EnigmaRoot = entryList.first(); + break; + } + } + + return EnigmaRoot; +} + +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _ui(new Ui::MainWindow), _event_data(nullptr), egm(nullptr) { + + if (!EnigmaRoot.filePath().isEmpty()) { + _event_data = std::make_unique(ParseEventFile((EnigmaRoot.absolutePath() + "/events.ey").toStdString())); + } else { + qDebug() << "Error: Failed to locate ENIGMA sources. Loading internal events.ey.\n" << "Search Paths:\n" << MainWindow::EnigmaSearchPaths; + QFile internal_events(":/events.ey"); + internal_events.open(QIODevice::ReadOnly | QFile::Text); + std::stringstream ss; + ss << internal_events.readAll().toStdString(); + _event_data = std::make_unique(ParseEventFile(ss)); + } + + egm = egm::EGM(_event_data.get()); + ArtManager::Init(); _instance = this; @@ -155,7 +188,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _ui(new Ui::MainW openNewProject(); } -MainWindow::~MainWindow() { delete _ui; } +MainWindow::~MainWindow() { diagnosticTextEdit = nullptr; delete _ui; } void MainWindow::setCurrentConfig(const buffers::resources::Settings &settings) { emit _instance->CurrentConfigChanged(settings); @@ -285,13 +318,15 @@ void MainWindow::openFile(QString fName) { QFileInfo fileInfo(fName); const QString suffix = fileInfo.suffix(); - buffers::Project *loadedProject = nullptr; - if (suffix == "gm81" || suffix == "gmk" || suffix == "gm6" || suffix == "gmd") { - loadedProject = gmk::LoadGMK(fName.toStdString()); + std::unique_ptr loadedProject = nullptr; + if (suffix == "egm") { + loadedProject = egm.LoadEGM(fName.toStdString()); + } else if (suffix == "gm81" || suffix == "gmk" || suffix == "gm6" || suffix == "gmd") { + loadedProject = gmk::LoadGMK(fName.toStdString(), _event_data.get()); } else if (suffix == "gmx") { - loadedProject = gmx::LoadGMX(fName.toStdString()); + loadedProject = gmx::LoadGMX(fName.toStdString(), _event_data.get()); } else if (suffix == "yyp") { - loadedProject = yyp::LoadYYP(fName.toStdString()); + loadedProject = yyp::LoadYYP(fName.toStdString(), _event_data.get()); } if (!loadedProject) { @@ -302,7 +337,7 @@ void MainWindow::openFile(QString fName) { MainWindow::setWindowTitle(fileInfo.fileName() + " - ENIGMA"); _recentFiles->prependFile(fName); - openProject(std::unique_ptr(loadedProject)); + openProject(std::move(loadedProject)); } void MainWindow::openNewProject() { @@ -339,7 +374,7 @@ void MainWindow::on_actionNew_triggered() { openNewProject(); } void MainWindow::on_actionOpen_triggered() { const QString &fileName = QFileDialog::getOpenFileName( this, tr("Open Project"), "", - tr("All supported formats (*.yyp *.project.gmx *.gm81 *.gmk *.gm6 *.gmd);;GameMaker: Studio 2 Projects " + tr("All supported formats (*.egm *.yyp *.project.gmx *.gm81 *.gmk *.gm6 *.gmd);;GameMaker: Studio 2 Projects " "(*.yyp);;GameMaker: Studio Projects (*.project.gmx);;Classic " "GameMaker Files (*.gm81 *.gmk *.gm6 *.gmd);;All Files (*)")); if (!fileName.isEmpty()) openFile(fileName); diff --git a/MainWindow.h b/MainWindow.h index 3e057ed73..00c06578c 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -10,12 +10,15 @@ class MainWindow; #include "project.pb.h" #include "server.pb.h" +#include "event_reader/event_parser.h" +#include "egm.h" #include #include #include #include #include +#include namespace Ui { class MainWindow; @@ -33,6 +36,9 @@ class MainWindow : public QMainWindow { ~MainWindow(); void openProject(std::unique_ptr openedProject); buffers::Game *Game() const { return this->_project->mutable_game(); } + + static QList EnigmaSearchPaths; + static QFileInfo EnigmaRoot; signals: void CurrentConfigChanged(const buffers::resources::Settings &settings); @@ -108,11 +114,15 @@ class MainWindow : public QMainWindow { std::unique_ptr _project; QPointer _recentFiles; + + std::unique_ptr _event_data; + egm::EGM egm; void openSubWindow(buffers::TreeNode *item); void readSettings(); void writeSettings(); void setTabbedMode(bool enabled); + static QFileInfo getEnigmaRoot(); }; #endif // MAINWINDOW_H diff --git a/Plugins/ServerPlugin.cpp b/Plugins/ServerPlugin.cpp index 919df2942..3f79ec5e2 100644 --- a/Plugins/ServerPlugin.cpp +++ b/Plugins/ServerPlugin.cpp @@ -1,4 +1,5 @@ #include "ServerPlugin.h" +#include "MainWindow.h" #include "Widgets/CodeWidget.h" #include @@ -92,8 +93,8 @@ struct ResourceReader : public AsyncReadWorker { type = KeywordType::FUNCTION; for (int i = 0; i < resource.overload_count(); ++i) { QString overload = QString::fromStdString(resource.parameters(i)); - const QStringRef signature = QStringRef(&overload, overload.indexOf("(") + 1, overload.lastIndexOf(")")); - CodeWidget::addCalltip(name, signature.toString(), type); + const QString signature = overload.mid(overload.indexOf("(") + 1, overload.lastIndexOf(")")); + CodeWidget::addCalltip(name, signature, type); } } else { if (resource.is_global()) type = KeywordType::GLOBAL; @@ -269,7 +270,6 @@ ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) { #endif // look for an executable file that looks like emake in some common directories - QList searchPaths = {QDir::currentPath(), "./enigma-dev", "../enigma-dev", "../RadialGM/Submodules/enigma-dev"}; #ifndef RGM_DEBUG QString emakeName = "emake"; #else @@ -277,7 +277,7 @@ ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) { #endif QFileInfo emakeFileInfo; - foreach (auto path, searchPaths) { + foreach (auto path, MainWindow::EnigmaSearchPaths) { const QDir dir(path); QDir::Filters filters = QDir::Filter::Executable | QDir::Filter::Files; auto entryList = dir.entryInfoList(QStringList({emakeName, emakeName + ".exe"}), filters, QDir::SortFlag::NoSort); @@ -288,29 +288,18 @@ ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) { } if (emakeFileInfo.filePath().isEmpty()) { - qDebug() << "Error: Failed to locate emake. Compiling and syntax check will not work.\n" << "Search Paths:\n" << searchPaths; + qDebug() << "Error: Failed to locate emake. Compiling and syntax check will not work.\n" << "Search Paths:\n" << MainWindow::EnigmaSearchPaths; return; } - QFileInfo enigmaFileInfo; - foreach (auto path, searchPaths) { - const QDir dir(path); - QDir::Filters filters = QDir::Filter::AllEntries; - auto entryList = dir.entryInfoList(QStringList({"ENIGMAsystem"}), filters, QDir::SortFlag::NoSort); - if (!entryList.empty()) { - enigmaFileInfo = entryList.first(); - break; - } - } - - if (enigmaFileInfo.filePath().isEmpty()) { - qDebug() << "Error: Failed to locate ENIGMA sources. Compiling and syntax check will not work.\n" << "Search Paths:\n" << searchPaths; + if (MainWindow::EnigmaRoot.filePath().isEmpty()) { + qDebug() << "Error: Failed to locate ENIGMA sources. Compiling and syntax check will not work.\n" << "Search Paths:\n" << MainWindow::EnigmaSearchPaths; return; } // use the closest matching emake file we found and launch it in a child process qDebug() << "Using emake exe at: " << emakeFileInfo.absolutePath(); - qDebug() << "Using ENIGMA sources at: " << enigmaFileInfo.absolutePath(); + qDebug() << "Using ENIGMA sources at: " << MainWindow::EnigmaRoot.absolutePath(); process->setWorkingDirectory(emakeFileInfo.absolutePath()); QString program = emakeFileInfo.fileName(); QStringList arguments; @@ -320,7 +309,7 @@ ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) { << "-r" << "--quiet" << "--enigma-root" - << enigmaFileInfo.absolutePath(); + << MainWindow::EnigmaRoot.absolutePath(); qDebug() << "Running: " << program << " " << arguments; diff --git a/RadialGM.pro b/RadialGM.pro index 595d4b070..8ab32769c 100644 --- a/RadialGM.pro +++ b/RadialGM.pro @@ -177,5 +177,3 @@ FORMS += \ RESOURCES += \ images.qrc - -DISTFILES += diff --git a/Submodules/enigma-dev b/Submodules/enigma-dev index 87a7f5657..2e697aa79 160000 --- a/Submodules/enigma-dev +++ b/Submodules/enigma-dev @@ -1 +1 @@ -Subproject commit 87a7f56576b087343752cf8de86880b735c2fbd8 +Subproject commit 2e697aa79c921eab6a3d3dbfdcf597449fc03e2a diff --git a/images.qrc b/images.qrc index 6bd12572a..f2485c3b3 100644 --- a/images.qrc +++ b/images.qrc @@ -100,5 +100,6 @@ Images/banner.png Images/icon.ico Images/transparent.png + Submodules/enigma-dev/events.ey