Skip to content

Commit

Permalink
egm supp (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
fundies committed Aug 7, 2020
1 parent 9f61b89 commit 79a68a7
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 33 deletions.
55 changes: 45 additions & 10 deletions MainWindow.cpp
Expand Up @@ -33,9 +33,13 @@

#include <functional>
#include <unordered_map>
#include <QFile>
#include <sstream>

#undef GetMessage

QList<QString> MainWindow::EnigmaSearchPaths = {QDir::currentPath(), "./enigma-dev", "../enigma-dev", "../RadialGM/Submodules/enigma-dev"};
QFileInfo MainWindow::EnigmaRoot = MainWindow::getEnigmaRoot();
QList<buffers::SystemType> MainWindow::systemCache;
MainWindow *MainWindow::_instance = nullptr;
QScopedPointer<ResourceModelMap> MainWindow::resourceMap;
Expand Down Expand Up @@ -73,15 +77,44 @@ 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!
std::cerr << "Critical: Diagnostics text control does not exist!" << std::endl;
}
}

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<EventData>(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<EventData>(ParseEventFile(ss));
}

egm = egm::EGM(_event_data.get());

ArtManager::Init();

_instance = this;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<buffers::Project> 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) {
Expand All @@ -302,7 +337,7 @@ void MainWindow::openFile(QString fName) {

MainWindow::setWindowTitle(fileInfo.fileName() + " - ENIGMA");
_recentFiles->prependFile(fName);
openProject(std::unique_ptr<buffers::Project>(loadedProject));
openProject(std::move(loadedProject));
}

void MainWindow::openNewProject() {
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions MainWindow.h
Expand Up @@ -10,12 +10,15 @@ class MainWindow;

#include "project.pb.h"
#include "server.pb.h"
#include "event_reader/event_parser.h"
#include "egm.h"

#include <QList>
#include <QMainWindow>
#include <QMdiSubWindow>
#include <QPointer>
#include <QProcess>
#include <QFileInfo>

namespace Ui {
class MainWindow;
Expand All @@ -33,6 +36,9 @@ class MainWindow : public QMainWindow {
~MainWindow();
void openProject(std::unique_ptr<buffers::Project> openedProject);
buffers::Game *Game() const { return this->_project->mutable_game(); }

static QList<QString> EnigmaSearchPaths;
static QFileInfo EnigmaRoot;

signals:
void CurrentConfigChanged(const buffers::resources::Settings &settings);
Expand Down Expand Up @@ -108,11 +114,15 @@ class MainWindow : public QMainWindow {

std::unique_ptr<buffers::Project> _project;
QPointer<RecentFiles> _recentFiles;

std::unique_ptr<EventData> _event_data;
egm::EGM egm;

void openSubWindow(buffers::TreeNode *item);
void readSettings();
void writeSettings();
void setTabbedMode(bool enabled);
static QFileInfo getEnigmaRoot();
};

#endif // MAINWINDOW_H
29 changes: 9 additions & 20 deletions Plugins/ServerPlugin.cpp
@@ -1,4 +1,5 @@
#include "ServerPlugin.h"
#include "MainWindow.h"
#include "Widgets/CodeWidget.h"

#include <QFileDialog>
Expand Down Expand Up @@ -92,8 +93,8 @@ struct ResourceReader : public AsyncReadWorker<Resource> {
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;
Expand Down Expand Up @@ -269,15 +270,14 @@ ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) {
#endif

// look for an executable file that looks like emake in some common directories
QList<QString> searchPaths = {QDir::currentPath(), "./enigma-dev", "../enigma-dev", "../RadialGM/Submodules/enigma-dev"};
#ifndef RGM_DEBUG
QString emakeName = "emake";
#else
QString emakeName = "emake-debug";
#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);
Expand All @@ -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;
Expand All @@ -320,7 +309,7 @@ ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) {
<< "-r"
<< "--quiet"
<< "--enigma-root"
<< enigmaFileInfo.absolutePath();
<< MainWindow::EnigmaRoot.absolutePath();

qDebug() << "Running: " << program << " " << arguments;

Expand Down
2 changes: 0 additions & 2 deletions RadialGM.pro
Expand Up @@ -177,5 +177,3 @@ FORMS += \

RESOURCES += \
images.qrc

DISTFILES +=
2 changes: 1 addition & 1 deletion Submodules/enigma-dev
Submodule enigma-dev updated 134 files
1 change: 1 addition & 0 deletions images.qrc
Expand Up @@ -100,5 +100,6 @@
<file alias="banner.png">Images/banner.png</file>
<file alias="icon.ico">Images/icon.ico</file>
<file alias="transparent.png">Images/transparent.png</file>
<file alias="events.ey">Submodules/enigma-dev/events.ey</file>
</qresource>
</RCC>

0 comments on commit 79a68a7

Please sign in to comment.