Merge pull request #15201 from SamGondelman/emit

Case 21756: Entities.emitScriptEvent works now
This commit is contained in:
Sam Gondelman 2019-03-21 18:05:17 -07:00 committed by GitHub
commit 40f5a0263c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 12 deletions

View file

@ -1985,6 +1985,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
return nullptr;
});
EntityTree::setEmitScriptEventOperator([this](const QUuid& id, const QVariant& message) {
auto entities = getEntities();
if (auto entity = entities->renderableForEntityId(id)) {
entity->emitScriptEvent(message);
}
});
EntityTree::setTextSizeOperator([this](const QUuid& id, const QString& text) {
auto entities = getEntities();
if (auto entity = entities->renderableForEntityId(id)) {

View file

@ -40,6 +40,7 @@ public:
virtual bool wantsKeyboardFocus() const { return false; }
virtual void setProxyWindow(QWindow* proxyWindow) {}
virtual QObject* getEventHandler() { return nullptr; }
virtual void emitScriptEvent(const QVariant& message) {}
const EntityItemPointer& getEntity() const { return _entity; }
const ItemID& getRenderItemID() const { return _renderItemID; }

View file

@ -106,7 +106,7 @@ private:
static std::function<void(QSharedPointer<OffscreenQmlSurface>&, bool&, std::vector<QMetaObject::Connection>&)> _releaseWebSurfaceOperator;
public slots:
void emitScriptEvent(const QVariant& scriptMessage);
void emitScriptEvent(const QVariant& scriptMessage) override;
signals:
void scriptEventReceived(const QVariant& message);

View file

@ -511,8 +511,6 @@ public:
virtual void setProxyWindow(QWindow* proxyWindow) {}
virtual QObject* getEventHandler() { return nullptr; }
virtual void emitScriptEvent(const QVariant& message) {}
QUuid getLastEditedBy() const { return _lastEditedBy; }
void setLastEditedBy(QUuid value) { _lastEditedBy = value; }

View file

@ -2196,14 +2196,7 @@ bool EntityScriptingInterface::wantsHandControllerPointerEvents(const QUuid& id)
}
void EntityScriptingInterface::emitScriptEvent(const EntityItemID& entityID, const QVariant& message) {
if (_entityTree) {
_entityTree->withReadLock([&] {
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(EntityItemID(entityID));
if (entity) {
entity->emitScriptEvent(message);
}
});
}
EntityTree::emitScriptEvent(entityID, message);
}
// TODO move this someplace that makes more sense...

View file

@ -1529,7 +1529,6 @@ public slots:
* @function Entities.emitScriptEvent
* @param {Uuid} entityID - The ID of the {@link Entities.EntityType|Web} entity.
* @param {string} message - The message to send.
* @todo <em>This function is currently not implemented.</em>
*/
Q_INVOKABLE void emitScriptEvent(const EntityItemID& entityID, const QVariant& message);

View file

@ -2978,6 +2978,7 @@ QStringList EntityTree::getJointNames(const QUuid& entityID) const {
std::function<QObject*(const QUuid&)> EntityTree::_getEntityObjectOperator = nullptr;
std::function<QSizeF(const QUuid&, const QString&)> EntityTree::_textSizeOperator = nullptr;
std::function<bool()> EntityTree::_areEntityClicksCapturedOperator = nullptr;
std::function<void(const QUuid&, const QVariant&)> EntityTree::_emitScriptEventOperator = nullptr;
QObject* EntityTree::getEntityObject(const QUuid& id) {
if (_getEntityObjectOperator) {
@ -3000,6 +3001,12 @@ bool EntityTree::areEntityClicksCaptured() {
return false;
}
void EntityTree::emitScriptEvent(const QUuid& id, const QVariant& message) {
if (_emitScriptEventOperator) {
_emitScriptEventOperator(id, message);
}
}
void EntityTree::updateEntityQueryAACubeWorker(SpatiallyNestablePointer object, EntityEditPacketSender* packetSender,
MovingEntitiesOperator& moveOperator, bool force, bool tellServer) {
// if the queryBox has changed, tell the entity-server

View file

@ -272,6 +272,9 @@ public:
static void setEntityClicksCapturedOperator(std::function<bool()> areEntityClicksCapturedOperator) { _areEntityClicksCapturedOperator = areEntityClicksCapturedOperator; }
static bool areEntityClicksCaptured();
static void setEmitScriptEventOperator(std::function<void(const QUuid&, const QVariant&)> emitScriptEventOperator) { _emitScriptEventOperator = emitScriptEventOperator; }
static void emitScriptEvent(const QUuid& id, const QVariant& message);
std::map<QString, QString> getNamedPaths() const { return _namedPaths; }
void updateEntityQueryAACube(SpatiallyNestablePointer object, EntityEditPacketSender* packetSender,
@ -383,6 +386,7 @@ private:
static std::function<QObject*(const QUuid&)> _getEntityObjectOperator;
static std::function<QSizeF(const QUuid&, const QString&)> _textSizeOperator;
static std::function<bool()> _areEntityClicksCapturedOperator;
static std::function<void(const QUuid&, const QVariant&)> _emitScriptEventOperator;
std::vector<int32_t> _staleProxies;