Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 364 files). Show all
Unified · Split
| @@ -108,6 +108,8 @@ int functionSignatureMetaID = qRegisterMetaType<QScriptEngine::FunctionSignature · 107 unmodified lines | ||
| 108 | 108 | |
| 109 | 109 | int scriptEnginePointerMetaID = qRegisterMetaType<ScriptEnginePointer>(); |
| 110 | 110 | |
| 111 | +Q_DECLARE_METATYPE(ExternalResource::Bucket); | |
| 112 | + | |
| 111 | 113 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine) { |
| 112 | 114 | // assemble the message by concatenating our arguments |
| 113 | 115 | QString message = ""; |
| @@ -705,6 +707,14 @@ void avatarDataFromScriptValue(const QScriptValue& object, ScriptAvatarData*& ou · 591 unmodified lines | ||
| 705 | 707 | out = nullptr; |
| 706 | 708 | } |
| 707 | 709 | |
| 710 | +QScriptValue externalResourceBucketToScriptValue(QScriptEngine* engine, ExternalResource::Bucket const& in) { | |
| 711 | + return QScriptValue((int)in); | |
| 712 | +} | |
| 713 | + | |
| 714 | +void externalResourceBucketFromScriptValue(const QScriptValue& object, ExternalResource::Bucket& out) { | |
| 715 | + out = static_cast<ExternalResource::Bucket>(object.toInt32()); | |
| 716 | +} | |
| 717 | + | |
| 708 | 718 | void ScriptEngine::resetModuleCache(bool deleteScriptCache) { |
| 709 | 719 | if (QThread::currentThread() != thread()) { |
| 710 | 720 | executeOnScriptThread([=]() { resetModuleCache(deleteScriptCache); }); |
| @@ -812,6 +822,9 @@ void ScriptEngine::init() { · 101 unmodified lines | ||
| 812 | 822 | resetModuleCache(); |
| 813 | 823 | } |
| 814 | 824 | |
| 825 | + qScriptRegisterMetaType(this, externalResourceBucketToScriptValue, externalResourceBucketFromScriptValue); | |
| 826 | + registerEnum("Script.ExternalPaths", QMetaEnum::fromType<ExternalResource::Bucket>()); | |
| 827 | + | |
| 815 | 828 | registerGlobalObject("Audio", DependencyManager::get<AudioScriptingInterface>().data()); |
| 816 | 829 | |
| 817 | 830 | registerGlobalObject("Midi", DependencyManager::get<Midi>().data()); |
| @@ -869,6 +882,19 @@ void ScriptEngine::init() { · 51 unmodified lines | ||
| 869 | 882 | })); |
| 870 | 883 | } |
| 871 | 884 | |
| 885 | +void ScriptEngine::registerEnum(const QString& enumName, QMetaEnum newEnum) { | |
| 886 | + if (!newEnum.isValid()) { | |
| 887 | + qCCritical(scriptengine) << "registerEnum called on invalid enum with name " << enumName; | |
| 888 | + return; | |
| 889 | + } | |
| 890 | + | |
| 891 | + for (int i = 0; i < newEnum.keyCount(); i++) { | |
| 892 | + const char* keyName = newEnum.key(i); | |
| 893 | + QString fullName = enumName + "." + keyName; | |
| 894 | + registerValue(fullName, newEnum.keyToValue(keyName)); | |
| 895 | + } | |
| 896 | +} | |
| 897 | + | |
| 872 | 898 | void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) { |
| 873 | 899 | if (QThread::currentThread() != thread()) { |
| 874 | 900 | #ifdef THREAD_DEBUGGING |
| @@ -2898,3 +2924,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 2023 unmodified lines | ||
| 2898 | 2924 | } |
| 2899 | 2925 | } |
| 2900 | 2926 | } |
| 2927 | + | |
| 2928 | +QString ScriptEngine::getExternalPath(ExternalResource::Bucket bucket, const QString& path) { | |
| 2929 | + return ExternalResource::getInstance()->getUrl(bucket, path); | |
| 2930 | +} | |