mirror of https://github.com/mgba-emu/mgba.git
Qt: Add scripting storage integration
This commit is contained in:
parent
63d96ab712
commit
f3d49527b7
|
@ -20,6 +20,7 @@
|
|||
#include "scripting/ScriptingTextBufferModel.h"
|
||||
|
||||
#include <mgba/script/input.h>
|
||||
#include <mgba/script/storage.h>
|
||||
#include <mgba-util/math.h>
|
||||
#include <mgba-util/string.h>
|
||||
|
||||
|
@ -51,6 +52,9 @@ ScriptingController::ScriptingController(QObject* parent)
|
|||
m_bufferModel = new ScriptingTextBufferModel(this);
|
||||
QObject::connect(m_bufferModel, &ScriptingTextBufferModel::textBufferCreated, this, &ScriptingController::textBufferCreated);
|
||||
|
||||
connect(&m_storageFlush, &QTimer::timeout, this, &ScriptingController::flushStorage);
|
||||
m_storageFlush.setInterval(5);
|
||||
|
||||
mScriptGamepadInit(&m_gamepad);
|
||||
|
||||
init();
|
||||
|
@ -144,6 +148,10 @@ void ScriptingController::runCode(const QString& code) {
|
|||
load(vf, "*prompt");
|
||||
}
|
||||
|
||||
void ScriptingController::flushStorage() {
|
||||
mScriptStorageFlushAll(&m_scriptContext);
|
||||
}
|
||||
|
||||
bool ScriptingController::eventFilter(QObject* obj, QEvent* ev) {
|
||||
event(obj, ev);
|
||||
return false;
|
||||
|
@ -293,6 +301,7 @@ void ScriptingController::detachGamepad() {
|
|||
void ScriptingController::init() {
|
||||
mScriptContextInit(&m_scriptContext);
|
||||
mScriptContextAttachStdlib(&m_scriptContext);
|
||||
mScriptContextAttachStorage(&m_scriptContext);
|
||||
mScriptContextAttachSocket(&m_scriptContext);
|
||||
mScriptContextAttachInput(&m_scriptContext);
|
||||
mScriptContextRegisterEngines(&m_scriptContext);
|
||||
|
@ -308,6 +317,8 @@ void ScriptingController::init() {
|
|||
if (m_engines.count() == 1) {
|
||||
m_activeEngine = *m_engines.begin();
|
||||
}
|
||||
|
||||
m_storageFlush.start();
|
||||
}
|
||||
|
||||
uint32_t ScriptingController::qtToScriptingKey(const QKeyEvent* event) {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
#include <mgba/script/context.h>
|
||||
#include <mgba/script/input.h>
|
||||
|
@ -55,6 +56,8 @@ public slots:
|
|||
void reset();
|
||||
void runCode(const QString& code);
|
||||
|
||||
void flushStorage();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject*, QEvent*) override;
|
||||
|
||||
|
@ -84,6 +87,8 @@ private:
|
|||
|
||||
std::shared_ptr<CoreController> m_controller;
|
||||
InputController* m_inputController = nullptr;
|
||||
|
||||
QTimer m_storageFlush;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue