2020-09-13 23:37:55 +01:00
|
|
|
#pragma once
|
2020-04-27 01:38:20 +01:00
|
|
|
#ifndef SCRIPTING_H
|
|
|
|
#define SCRIPTING_H
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "block.h"
|
2022-09-05 17:17:27 +01:00
|
|
|
#include "scriptutility.h"
|
2020-04-27 01:38:20 +01:00
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QJSEngine>
|
|
|
|
|
|
|
|
enum CallbackType {
|
2020-05-03 17:28:02 +01:00
|
|
|
OnProjectOpened,
|
2020-05-08 17:26:23 +01:00
|
|
|
OnProjectClosed,
|
2020-04-27 01:38:20 +01:00
|
|
|
OnBlockChanged,
|
2022-08-29 17:44:17 +01:00
|
|
|
OnBorderMetatileChanged,
|
2021-12-18 01:47:12 +00:00
|
|
|
OnBlockHoverChanged,
|
|
|
|
OnBlockHoverCleared,
|
2020-05-02 22:25:35 +01:00
|
|
|
OnMapOpened,
|
2021-12-09 15:57:37 +00:00
|
|
|
OnMapResized,
|
2022-08-29 17:44:17 +01:00
|
|
|
OnBorderResized,
|
2021-12-10 21:09:06 +00:00
|
|
|
OnMapShifted,
|
2021-11-30 22:24:46 +00:00
|
|
|
OnTilesetUpdated,
|
2021-12-10 21:52:17 +00:00
|
|
|
OnMainTabChanged,
|
|
|
|
OnMapViewTabChanged,
|
2022-08-30 17:53:33 +01:00
|
|
|
OnBorderVisibilityToggled,
|
2020-04-27 01:38:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Scripting
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Scripting(MainWindow *mainWindow);
|
|
|
|
static void init(MainWindow *mainWindow);
|
2022-09-05 04:41:42 +01:00
|
|
|
static void populateGlobalObject(MainWindow *mainWindow);
|
|
|
|
static QJSEngine *getEngine();
|
2023-02-09 18:55:25 +00:00
|
|
|
static void invokeAction(int actionIndex);
|
2020-05-03 17:28:02 +01:00
|
|
|
static void cb_ProjectOpened(QString projectPath);
|
2020-05-08 17:26:23 +01:00
|
|
|
static void cb_ProjectClosed(QString projectPath);
|
2020-04-27 01:38:20 +01:00
|
|
|
static void cb_MetatileChanged(int x, int y, Block prevBlock, Block newBlock);
|
2022-08-29 17:44:17 +01:00
|
|
|
static void cb_BorderMetatileChanged(int x, int y, uint16_t prevMetatileId, uint16_t newMetatileId);
|
2021-12-18 01:47:12 +00:00
|
|
|
static void cb_BlockHoverChanged(int x, int y);
|
|
|
|
static void cb_BlockHoverCleared();
|
2020-05-02 22:25:35 +01:00
|
|
|
static void cb_MapOpened(QString mapName);
|
2021-12-09 15:57:37 +00:00
|
|
|
static void cb_MapResized(int oldWidth, int oldHeight, int newWidth, int newHeight);
|
2022-08-29 17:44:17 +01:00
|
|
|
static void cb_BorderResized(int oldWidth, int oldHeight, int newWidth, int newHeight);
|
2021-12-10 21:09:06 +00:00
|
|
|
static void cb_MapShifted(int xDelta, int yDelta);
|
2021-11-30 22:24:46 +00:00
|
|
|
static void cb_TilesetUpdated(QString tilesetName);
|
2021-12-10 21:52:17 +00:00
|
|
|
static void cb_MainTabChanged(int oldTab, int newTab);
|
|
|
|
static void cb_MapViewTabChanged(int oldTab, int newTab);
|
2022-08-30 17:53:33 +01:00
|
|
|
static void cb_BorderVisibilityToggled(bool visible);
|
2021-11-20 03:32:14 +00:00
|
|
|
static bool tryErrorJS(QJSValue js);
|
2022-09-05 04:41:42 +01:00
|
|
|
static QJSValue fromBlock(Block block);
|
|
|
|
static QJSValue fromTile(Tile tile);
|
|
|
|
static Tile toTile(QJSValue obj);
|
|
|
|
static QJSValue dimensions(int width, int height);
|
|
|
|
static QJSValue position(int x, int y);
|
2024-01-03 17:13:53 +00:00
|
|
|
static const QImage * getImage(const QString &filepath, bool useCache);
|
2022-09-05 04:41:42 +01:00
|
|
|
static QJSValue dialogInput(QJSValue input, bool selectedOk);
|
2020-04-27 01:38:20 +01:00
|
|
|
|
|
|
|
private:
|
2023-02-09 16:28:55 +00:00
|
|
|
MainWindow *mainWindow;
|
2020-04-27 01:38:20 +01:00
|
|
|
QJSEngine *engine;
|
|
|
|
QStringList filepaths;
|
|
|
|
QList<QJSValue> modules;
|
2021-12-07 19:44:40 +00:00
|
|
|
QMap<QString, const QImage*> imageCache;
|
2022-09-05 16:53:30 +01:00
|
|
|
ScriptUtility *scriptUtility;
|
2020-04-27 01:38:20 +01:00
|
|
|
|
|
|
|
void loadModules(QStringList moduleFiles);
|
|
|
|
void invokeCallback(CallbackType type, QJSValueList args);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SCRIPTING_H
|