Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all
Unified · Split
| @@ -285,6 +285,23 @@ static void scriptableResourceFromScriptValue(const QScriptValue& value, Scripta · 284 unmodified lines | ||
| 285 | 285 | resource = static_cast<ScriptableResourceRawPtr>(value.toQObject()); |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | +static QScriptValue createScriptableResourcePrototype(QScriptEngine* engine) { | |
| 289 | + auto prototype = engine->newObject(); | |
| 290 | + | |
| 291 | + // Expose enum State to JS/QML via properties | |
| 292 | + QObject* state = new QObject(engine); | |
| 293 | + state->setObjectName("ResourceState"); | |
| 294 | + auto metaEnum = QMetaEnum::fromType<ScriptableResource::State>(); | |
| 295 | + for (int i = 0; i < metaEnum.keyCount(); ++i) { | |
| 296 | + state->setProperty(metaEnum.key(i), metaEnum.value(i)); | |
| 297 | + } | |
| 298 | + | |
| 299 | + auto prototypeState = engine->newQObject(state, QScriptEngine::QtOwnership, QScriptEngine::ExcludeSlots | QScriptEngine::ExcludeSuperClassMethods); | |
| 300 | + prototype.setProperty("State", prototypeState); | |
| 301 | + | |
| 302 | + return prototype; | |
| 303 | +} | |
| 304 | + | |
| 288 | 305 | void ScriptEngine::init() { |
| 289 | 306 | if (_isInitialized) { |
| 290 | 307 | return; // only initialize once |
| @@ -342,11 +359,14 @@ void ScriptEngine::init() { · 51 unmodified lines | ||
| 342 | 359 | registerGlobalObject("Vec3", &_vec3Library); |
| 343 | 360 | registerGlobalObject("Mat4", &_mat4Library); |
| 344 | 361 | registerGlobalObject("Uuid", &_uuidLibrary); |
| 345 | − registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data()); | |
| 346 | 362 | registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data()); |
| 347 | 363 | qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue); |
| 348 | 364 | qScriptRegisterMetaType(this, resultHandlerToScriptValue, resultHandlerFromScriptValue); |
| 349 | 365 | |
| 366 | + // Scriptable cache access | |
| 367 | + auto resourcePrototype = createScriptableResourcePrototype(this); | |
| 368 | + globalObject().setProperty("Resource", resourcePrototype); | |
| 369 | + setDefaultPrototype(qMetaTypeId<ScriptableResource*>(), resourcePrototype); | |
| 350 | 370 | qScriptRegisterMetaType(this, scriptableResourceToScriptValue, scriptableResourceFromScriptValue); |
| 351 | 371 | |
| 352 | 372 | // constants |