mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-15 12:38:46 +02:00
expose Sound to ScriptEngine
This commit is contained in:
parent
8cc4a33ad3
commit
845176bbc6
3 changed files with 16 additions and 2 deletions
|
@ -12,7 +12,9 @@
|
|||
|
||||
#include "Sound.h"
|
||||
|
||||
Sound::Sound(const QUrl& sampleURL) {
|
||||
Sound::Sound(const QUrl& sampleURL, QObject* parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
// assume we have a QApplication or QCoreApplication instance and use the
|
||||
// QNetworkAccess manager to grab the raw audio file at the given URL
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class QNetworkReply;
|
|||
class Sound : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Sound(const QUrl& sampleURL);
|
||||
Sound(const QUrl& sampleURL, QObject* parent = 0);
|
||||
|
||||
const QByteArray& getByteArray() { return _byteArray; }
|
||||
private:
|
||||
|
|
|
@ -20,12 +20,20 @@
|
|||
#include <UUID.h>
|
||||
#include <VoxelConstants.h>
|
||||
|
||||
#include <Sound.h>
|
||||
|
||||
#include "ScriptEngine.h"
|
||||
|
||||
int ScriptEngine::_scriptNumber = 1;
|
||||
VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface;
|
||||
ParticlesScriptingInterface ScriptEngine::_particlesScriptingInterface;
|
||||
|
||||
static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* engine) {
|
||||
QUrl soundURL = QUrl(context->argument(0).toString());
|
||||
QScriptValue soundScriptValue = engine->newQObject(new Sound(soundURL), QScriptEngine::ScriptOwnership);
|
||||
|
||||
return soundScriptValue;
|
||||
}
|
||||
|
||||
ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems,
|
||||
const char* scriptMenuName, AbstractMenuInterface* menu,
|
||||
|
@ -101,6 +109,10 @@ void ScriptEngine::run() {
|
|||
QScriptValue particleScripterValue = engine.newQObject(&_particlesScriptingInterface);
|
||||
engine.globalObject().setProperty("Particles", particleScripterValue);
|
||||
|
||||
QScriptValue soundConstructorValue = engine.newFunction(soundConstructor);
|
||||
QScriptValue soundMetaObject = engine.newQMetaObject(&Sound::staticMetaObject, soundConstructorValue);
|
||||
engine.globalObject().setProperty("Sound", soundMetaObject);
|
||||
|
||||
if (_controllerScriptingInterface) {
|
||||
QScriptValue controllerScripterValue = engine.newQObject(_controllerScriptingInterface);
|
||||
engine.globalObject().setProperty("Controller", controllerScripterValue);
|
||||
|
|
Loading…
Reference in a new issue