Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 5 files). Show all
Unified · Split
| @@ -277,10 +277,6 @@ void ScriptEngine::init() { · 276 unmodified lines | ||
| 277 | 277 | registerAvatarTypes(this); |
| 278 | 278 | registerAudioMetaTypes(this); |
| 279 | 279 | |
| 280 | − if (_controllerScriptingInterface) { | |
| 281 | − _controllerScriptingInterface->registerControllerTypes(this); | |
| 282 | − } | |
| 283 | − | |
| 284 | 280 | qScriptRegisterMetaType(this, EntityPropertyFlagsToScriptValue, EntityPropertyFlagsFromScriptValue); |
| 285 | 281 | qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValueHonorReadOnly); |
| 286 | 282 | qScriptRegisterMetaType(this, EntityItemIDtoScriptValue, EntityItemIDfromScriptValue); |
| @@ -323,6 +319,43 @@ void ScriptEngine::init() { · 36 unmodified lines | ||
| 323 | 319 | |
| 324 | 320 | // constants |
| 325 | 321 | globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE))); |
| 322 | + | |
| 323 | + if (_controllerScriptingInterface) { | |
| 324 | + _controllerScriptingInterface->registerControllerTypes(this); | |
| 325 | + } | |
| 326 | + | |
| 327 | + | |
| 328 | +} | |
| 329 | + | |
| 330 | +void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) { | |
| 331 | + if (QThread::currentThread() != thread()) { | |
| 332 | +#ifdef THREAD_DEBUGGING | |
| 333 | + qDebug() << "*** WARNING *** ScriptEngine::registerValue() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name; | |
| 334 | +#endif | |
| 335 | + QMetaObject::invokeMethod(this, "registerValue", | |
| 336 | + Q_ARG(const QString&, valueName), | |
| 337 | + Q_ARG(QScriptValue, value)); | |
| 338 | + return; | |
| 339 | + } | |
| 340 | + | |
| 341 | + QStringList pathToValue = valueName.split("."); | |
| 342 | + int partsToGo = pathToValue.length(); | |
| 343 | + QScriptValue partObject = globalObject(); | |
| 344 | + | |
| 345 | + for (const auto& pathPart : pathToValue) { | |
| 346 | + partsToGo--; | |
| 347 | + if (!partObject.property(pathPart).isValid()) { | |
| 348 | + if (partsToGo > 0) { | |
| 349 | + //QObject *object = new QObject; | |
| 350 | + QScriptValue partValue = newArray(); //newQObject(object, QScriptEngine::ScriptOwnership); | |
| 351 | + qDebug() << "partValue[" << pathPart<<"].isArray() :" << partValue.isArray(); | |
| 352 | + partObject.setProperty(pathPart, partValue); | |
| 353 | + } else { | |
| 354 | + partObject.setProperty(pathPart, value); | |
| 355 | + } | |
| 356 | + } | |
| 357 | + partObject = partObject.property(pathPart); | |
| 358 | + } | |
| 326 | 359 | } |
| 327 | 360 | |
| 328 | 361 | void ScriptEngine::registerGlobalObject(const QString& name, QObject* object) { |
| @@ -339,9 +372,13 @@ void ScriptEngine::registerGlobalObject(const QString& name, QObject* object) { · 10 unmodified lines | ||
| 339 | 372 | qDebug() << "ScriptEngine::registerGlobalObject() called on thread [" << QThread::currentThread() << "] name:" << name; |
| 340 | 373 | #endif |
| 341 | 374 | |
| 342 | − if (object) { | |
| 343 | − QScriptValue value = newQObject(object); | |
| 344 | − globalObject().setProperty(name, value); | |
| 375 | + if (!globalObject().property(name).isValid()) { | |
| 376 | + if (object) { | |
| 377 | + QScriptValue value = newQObject(object); | |
| 378 | + globalObject().setProperty(name, value); | |
| 379 | + } else { | |
| 380 | + globalObject().setProperty(name, QScriptValue()); | |
| 381 | + } | |
| 345 | 382 | } |
| 346 | 383 | } |
| 347 | 384 | |