Scripting API cleanup and type conversion fixes

This commit is contained in:
ksuprynowicz 2023-05-01 16:48:51 +02:00
parent 82e6cb9391
commit a7229e9249
11 changed files with 21 additions and 48 deletions

View file

@ -460,7 +460,8 @@ void MyAvatar::enableHandTouchForID(const QUuid& entityID) {
void MyAvatar::registerMetaTypes(ScriptEnginePointer engine) {
scriptRegisterMetaType<AudioListenerMode, audioListenModeToScriptValue, audioListenModeFromScriptValue>(engine.get());
scriptRegisterMetaType<MyAvatar::DriveKeys, driveKeysToScriptValue, driveKeysFromScriptValue>(engine.get());
scriptRegisterMetaType<MyAvatar::DriveKeys, driveKeysToScriptValue, driveKeysFromScriptValue>(engine.get(), "DriveKeys");
qDebug() << "MyAvatar::registerMetaTypes";
}
void MyAvatar::registerProperties(ScriptEnginePointer engine) {

View file

@ -2291,13 +2291,6 @@ public slots:
*/
void clearAvatarEntity(const QUuid& entityID, bool requiresRemovalFromTree = true) override;
/*@jsdoc
* @function MyAvatar.sanitizeAvatarEntityProperties
* @param {EntityItemProperties} properties - Properties.
* @deprecated This function is deprecated and will be removed.
*/
void sanitizeAvatarEntityProperties(EntityItemProperties& properties) const;
/*@jsdoc
* Sets whether your avatar mesh is visible to you.
* @function MyAvatar.setEnableMeshVisible
@ -2689,6 +2682,7 @@ private:
virtual int parseDataFromBuffer(const QByteArray& buffer) override;
virtual glm::vec3 getSkeletonPosition() const override;
int _skeletonModelChangeCount { 0 };
void sanitizeAvatarEntityProperties(EntityItemProperties& properties) const;
void saveAvatarScale();
@ -3119,6 +3113,8 @@ private:
QTimer _addAvatarEntitiesToTreeTimer;
};
Q_DECLARE_METATYPE(MyAvatar::DriveKeys)
ScriptValue audioListenModeToScriptValue(ScriptEngine* engine, const AudioListenerMode& audioListenerMode);
bool audioListenModeFromScriptValue(const ScriptValue& object, AudioListenerMode& audioListenerMode);

View file

@ -508,9 +508,9 @@ void Audio::setReverb(bool enable) {
});
}
void Audio::setReverbOptions(const AudioEffectOptions* options) {
void Audio::setReverbOptions(const AudioEffectOptions options) {
withWriteLock([&] {
DependencyManager::get<AudioClient>()->setReverbOptions(options);
DependencyManager::get<AudioClient>()->setReverbOptions(&options);
});
}

View file

@ -215,7 +215,7 @@ public:
* @function Audio.setReverbOptions
* @param {AudioEffectOptions} options - The reverberation options.
*/
Q_INVOKABLE void setReverbOptions(const AudioEffectOptions* options);
Q_INVOKABLE void setReverbOptions(const AudioEffectOptions options);
/*@jsdoc
* Sets the gain (relative volume) that avatars' voices are played at. This gain is used at the server.

View file

@ -778,16 +778,6 @@ public:
*/
Q_INVOKABLE char getHandState() const { return _handState; }
const QVector<JointData>& getRawJointData() const { return _jointData; }
/*@jsdoc
* Sets joint translations and rotations from raw joint data.
* @function Avatar.setRawJointData
* @param {JointData[]} data - The raw joint data.
* @deprecated This function is deprecated and will be removed.
*/
Q_INVOKABLE void setRawJointData(QVector<JointData> data);
/*@jsdoc
* Sets a specific joint's rotation and position relative to its parent, in model coordinates.
* <p><strong>Warning:</strong> These coordinates are not necessarily in meters.</p>
@ -1706,6 +1696,9 @@ protected:
QByteArray packAvatarEntityTraitInstance(AvatarTraits::TraitInstanceID traitInstanceID);
QByteArray packGrabTraitInstance(AvatarTraits::TraitInstanceID traitInstanceID);
const QVector<JointData>& getRawJointData() const { return _jointData; }
void setRawJointData(QVector<JointData> data);
void unpackSkeletonModelURL(const QByteArray& data);
void unpackSkeletonData(const QByteArray& data);
@ -1894,6 +1887,9 @@ private:
Q_DISABLE_COPY(AvatarData)
friend void avatarStateFromFrame(const QByteArray& frameData, AvatarData* _avatar);
// Required for setRawJointData. Making setRawJointData public would expose it to scripting interface.
friend class SkeletonModel;
friend class MyAvatar;
static QUrl _defaultFullAvatarModelUrl;
};
Q_DECLARE_METATYPE(AvatarData*)

View file

@ -123,18 +123,10 @@ namespace controller {
return userInputMapper->getPose(Input((uint32_t)source));
}
QVector<Action> ScriptingInterface::getAllActions() {
return DependencyManager::get<UserInputMapper>()->getAllActions();
}
QString ScriptingInterface::getDeviceName(unsigned int device) {
return DependencyManager::get<UserInputMapper>()->getDeviceName((unsigned short)device);
}
QVector<Input::NamedPair> ScriptingInterface::getAvailableInputs(unsigned int device) {
return DependencyManager::get<UserInputMapper>()->getAvailableInputs((unsigned short)device);
}
int ScriptingInterface::findDevice(QString name) {
return DependencyManager::get<UserInputMapper>()->findDevice(name);
}

View file

@ -73,25 +73,6 @@ namespace controller {
ScriptingInterface();
virtual ~ScriptingInterface() {};
/*@jsdoc
* Gets a list of all available actions.
* @function Controller.getAllActions
* @returns {Action[]} All available actions.
* @deprecated This function is deprecated and will be removed. It no longer works.
*/
// FIXME: This function causes a JavaScript crash: https://highfidelity.manuscript.com/f/cases/edit/13921
Q_INVOKABLE QVector<Action> getAllActions();
/*@jsdoc
* Gets a list of all available inputs for a hardware device.
* @function Controller.getAvailableInputs
* @param {number} deviceID - Integer ID of the hardware device.
* @returns {NamedPair[]} All available inputs for the device.
* @deprecated This function is deprecated and will be removed. It no longer works.
*/
// FIXME: This function causes a JavaScript crash: https://highfidelity.manuscript.com/f/cases/edit/13922
Q_INVOKABLE QVector<Input::NamedPair> getAvailableInputs(unsigned int device);
/*@jsdoc
* Finds the name of a particular controller from its device ID.
* @function Controller.getDeviceName

View file

@ -549,4 +549,6 @@ private:
QUrl _previousAPILookup;
};
Q_DECLARE_METATYPE(AddressManager::LookupTrigger)
#endif // hifi_AddressManager_h

View file

@ -34,6 +34,7 @@
#include "ScriptValueIterator.h"
#include "ScriptEngineLogging.h"
#include "v8/FastScriptValueUtils.h"
#include "AddressManager.h"
bool isListOfStrings(const ScriptValue& arg) {
if (!arg.isArray()) {
@ -98,6 +99,8 @@ void registerMetaTypes(ScriptEngine* engine) {
scriptRegisterSequenceMetaType<QVector<glm::vec2>>(engine);
scriptRegisterSequenceMetaType<QVector<glm::quat>>(engine);
scriptRegisterSequenceMetaType<QVector<QString>>(engine);
scriptRegisterMetaType<AddressManager::LookupTrigger, scriptValueFromEnumClass<AddressManager::LookupTrigger>, scriptValueToEnumClass<AddressManager::LookupTrigger>>(engine, "LookupTrigger");
}
ScriptValue qVector2DToScriptValue(ScriptEngine* engine, const QVector2D& qVector2D) {

View file

@ -37,6 +37,7 @@ STATIC_SCRIPT_TYPES_INITIALIZER((+[](ScriptManager* manager){
scriptRegisterMetaType<TabletProxy*, wrapperToScriptValue<TabletProxy>, wrapperFromScriptValue<TabletProxy> >(scriptEngine);
scriptRegisterMetaType<TabletButtonProxy*, wrapperToScriptValue<TabletButtonProxy>, wrapperFromScriptValue<TabletButtonProxy> >(scriptEngine);
scriptRegisterMetaType<TabletScriptingInterface::TabletAudioEvents, scriptValueFromEnumClass<TabletScriptingInterface::TabletAudioEvents>, scriptValueToEnumClass<TabletScriptingInterface::TabletAudioEvents>>(scriptEngine);
}));
// FIXME move to global app properties

View file

@ -687,5 +687,6 @@ protected:
};
Q_DECLARE_METATYPE(TabletButtonProxy*);
Q_DECLARE_METATYPE(TabletScriptingInterface::TabletAudioEvents)
#endif // hifi_TabletScriptingInterface_h