Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 66 files). Show all
Unified · Split
| @@ -116,19 +116,12 @@ void ScriptEngine::init() { · 115 unmodified lines | ||
| 116 | 116 | |
| 117 | 117 | // register meta-type for glm::vec3 conversions |
| 118 | 118 | registerMetaTypes(&_engine); |
| 119 | + | |
| 120 | + registerEventTypes(&_engine); | |
| 119 | 121 | qScriptRegisterMetaType(&_engine, ParticlePropertiesToScriptValue, ParticlePropertiesFromScriptValue); |
| 120 | 122 | qScriptRegisterMetaType(&_engine, ParticleIDtoScriptValue, ParticleIDfromScriptValue); |
| 121 | 123 | qScriptRegisterSequenceMetaType<QVector<ParticleID> >(&_engine); |
| 122 | 124 | |
| 123 | − QScriptValue agentValue = _engine.newQObject(this); | |
| 124 | − _engine.globalObject().setProperty("Agent", agentValue); | |
| 125 | − | |
| 126 | − QScriptValue voxelScripterValue = _engine.newQObject(&_voxelsScriptingInterface); | |
| 127 | − _engine.globalObject().setProperty("Voxels", voxelScripterValue); | |
| 128 | − | |
| 129 | − QScriptValue particleScripterValue = _engine.newQObject(&_particlesScriptingInterface); | |
| 130 | − _engine.globalObject().setProperty("Particles", particleScripterValue); | |
| 131 | − | |
| 132 | 125 | QScriptValue soundConstructorValue = _engine.newFunction(soundConstructor); |
| 133 | 126 | QScriptValue soundMetaObject = _engine.newQMetaObject(&Sound::staticMetaObject, soundConstructorValue); |
| 134 | 127 | _engine.globalObject().setProperty("Sound", soundMetaObject); |
| @@ -136,15 +129,14 @@ void ScriptEngine::init() { · 1 unmodified line | ||
| 136 | 129 | QScriptValue injectionOptionValue = _engine.scriptValueFromQMetaObject<AudioInjectorOptions>(); |
| 137 | 130 | _engine.globalObject().setProperty("AudioInjectionOptions", injectionOptionValue); |
| 138 | 131 | |
| 139 | − QScriptValue audioScriptingInterfaceValue = _engine.newQObject(&_audioScriptingInterface); | |
| 140 | − _engine.globalObject().setProperty("Audio", audioScriptingInterfaceValue); | |
| 141 | − | |
| 132 | + registerGlobalObject("Agent", this); | |
| 133 | + registerGlobalObject("Audio", &_audioScriptingInterface); | |
| 134 | + registerGlobalObject("Controller", _controllerScriptingInterface); | |
| 142 | 135 | registerGlobalObject("Data", &_dataServerScriptingInterface); |
| 136 | + registerGlobalObject("Particles", &_particlesScriptingInterface); | |
| 137 | + registerGlobalObject("Quat", &_quatLibrary); | |
| 143 | 138 | |
| 144 | − if (_controllerScriptingInterface) { | |
| 145 | − QScriptValue controllerScripterValue = _engine.newQObject(_controllerScriptingInterface); | |
| 146 | − _engine.globalObject().setProperty("Controller", controllerScripterValue); | |
| 147 | − } | |
| 139 | + registerGlobalObject("Voxels", &_voxelsScriptingInterface); | |
| 148 | 140 | |
| 149 | 141 | QScriptValue treeScaleValue = _engine.newVariant(QVariant(TREE_SCALE)); |
| 150 | 142 | _engine.globalObject().setProperty("TREE_SCALE", treeScaleValue); |
| @@ -157,8 +149,10 @@ void ScriptEngine::init() { · 6 unmodified lines | ||
| 157 | 149 | } |
| 158 | 150 | |
| 159 | 151 | void ScriptEngine::registerGlobalObject(const QString& name, QObject* object) { |
| 160 | − QScriptValue value = _engine.newQObject(object); | |
| 161 | − _engine.globalObject().setProperty(name, value); | |
| 152 | + if (object) { | |
| 153 | + QScriptValue value = _engine.newQObject(object); | |
| 154 | + _engine.globalObject().setProperty(name, value); | |
| 155 | + } | |
| 162 | 156 | } |
| 163 | 157 | |
| 164 | 158 | void ScriptEngine::evaluate() { |