porymap/include/scripting.h

42 lines
1.1 KiB
C
Raw Normal View History

#ifndef SCRIPTING_H
#define SCRIPTING_H
#include "mainwindow.h"
#include "block.h"
#include <QStringList>
#include <QJSEngine>
enum CallbackType {
2020-05-03 17:28:02 +01:00
OnProjectOpened,
OnBlockChanged,
OnMapOpened,
};
class Scripting
{
public:
Scripting(MainWindow *mainWindow);
static QJSValue fromBlock(Block block);
2020-05-01 00:30:24 +01:00
static QJSValue dimensions(int width, int height);
2020-05-03 16:00:56 +01:00
static QJSEngine *getEngine();
static void init(MainWindow *mainWindow);
2020-05-03 17:28:02 +01:00
static void registerAction(QString functionName, QString actionName);
static int numRegisteredActions();
static void invokeAction(QString actionName);
static void cb_ProjectOpened(QString projectPath);
static void cb_MetatileChanged(int x, int y, Block prevBlock, Block newBlock);
static void cb_MapOpened(QString mapName);
private:
QJSEngine *engine;
QStringList filepaths;
QList<QJSValue> modules;
2020-05-03 17:28:02 +01:00
QMap<QString, QString> registeredActions;
void loadModules(QStringList moduleFiles);
void invokeCallback(CallbackType type, QJSValueList args);
};
#endif // SCRIPTING_H