QUuid EntityScriptingInterface::addAction(const QString& actionTypeString,
                                          const QUuid& entityID,
                                          const QVariantMap& arguments) {
    QUuid actionID = QUuid::createUuid();
    auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>();
    bool success = actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
            // create this action even if the entity doesn't have physics info.  it will often be the
            // case that a script adds an action immediately after an object is created, and the physicsInfo
            // is computed asynchronously.
            // if (!entity->getPhysicsInfo()) {
            //     return false;
            // }
            EntityActionType actionType = EntityActionInterface::actionTypeFromString(actionTypeString);
            if (actionType == ACTION_TYPE_NONE) {
                return false;
            }
            EntityActionPointer action = actionFactory->factory(actionType, actionID, entity, arguments);
            if (action) {
                entity->addAction(simulation, action);
                auto nodeList = DependencyManager::get<NodeList>();
                const QUuid myNodeID = nodeList->getSessionUUID();
                if (entity->getSimulatorID() != myNodeID) {
                    entity->flagForOwnership();
                }
                return true;
            }
            return false;
        });
    if (success) {
        return actionID;
    }
    return QUuid();
}
Esempio n. 2
0
QUuid EntityScriptingInterface::addAction(const QString& actionTypeString,
                                          const QUuid& entityID,
                                          const QVariantMap& arguments) {
    QUuid actionID = QUuid::createUuid();
    auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>();
    bool success = false;
    actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
            // create this action even if the entity doesn't have physics info.  it will often be the
            // case that a script adds an action immediately after an object is created, and the physicsInfo
            // is computed asynchronously.
            // if (!entity->getPhysicsInfo()) {
            //     return false;
            // }
            EntityActionType actionType = EntityActionInterface::actionTypeFromString(actionTypeString);
            if (actionType == ACTION_TYPE_NONE) {
                return false;
            }
            EntityActionPointer action = actionFactory->factory(actionType, actionID, entity, arguments);
            if (!action) {
                return false;
            }
            success = entity->addAction(simulation, action);
            entity->grabSimulationOwnership();
            return false; // Physics will cause a packet to be sent, so don't send from here.
        });
    if (success) {
        return actionID;
    }
    return QUuid();
}
QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, const QUuid& actionID) {
    QVariantMap result;
    actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
            result = entity->getActionArguments(actionID);
            return false; // don't send an edit packet
        });
    return result;
}
QVector<QUuid> EntityScriptingInterface::getActionIDs(const QUuid& entityID) {
    QVector<QUuid> result;
    actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
            QList<QUuid> actionIDs = entity->getActionIDs();
            result = QVector<QUuid>::fromList(actionIDs);
            return false; // don't send an edit packet
        });
    return result;
}
Esempio n. 5
0
bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& actionID, const QVariantMap& arguments) {
    return actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
            bool success = entity->updateAction(simulation, actionID, arguments);
            if (success) {
                entity->grabSimulationOwnership();
            }
            return success;
        });
}
Esempio n. 6
0
bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) {
    bool success = false;
    actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
            success = entity->removeAction(simulation, actionID);
            if (success) {
                // reduce from grab to poke
                entity->pokeSimulationOwnership();
            }
            return false; // Physics will cause a packet to be sent, so don't send from here.
        });
    return success;
}
bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& actionID, const QVariantMap& arguments) {
    return actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
            bool success = entity->updateAction(simulation, actionID, arguments);
            if (success) {
                auto nodeList = DependencyManager::get<NodeList>();
                const QUuid myNodeID = nodeList->getSessionUUID();
                if (entity->getSimulatorID() != myNodeID) {
                    entity->flagForOwnership();
                }
            }
            return success;
        });
}
bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) {
    return actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
            return entity->removeAction(simulation, actionID);
        });
}