Merge branch 'master' of github.com:highfidelity/hifi into soft-entities

This commit is contained in:
Dante Ruiz 2018-01-03 08:47:40 -08:00
commit 674e8e1ac2
7 changed files with 276 additions and 20 deletions

View file

@ -197,14 +197,36 @@ Item {
anchors.topMargin: 26;
anchors.left: parent.left;
anchors.leftMargin: 20;
anchors.right: parent.right;
anchors.rightMargin: 30;
width: paintedWidth;
height: 30;
// Text size
size: 22;
// Style
color: hifi.colors.baseGrayHighlight;
}
RalewaySemiBold {
id: myPurchasesLink;
text: '<font color="#0093C5"><a href="#myPurchases">My Purchases</a></font>';
// Anchors
anchors.top: parent.top;
anchors.topMargin: 26;
anchors.right: parent.right;
anchors.rightMargin: 20;
width: paintedWidth;
height: 30;
y: 4;
// Text size
size: 18;
// Style
color: hifi.colors.baseGrayHighlight;
horizontalAlignment: Text.AlignRight;
onLinkActivated: {
sendSignalToWallet({method: 'goToPurchases_fromWalletHome'});
}
}
ListModel {
id: tempTransactionHistoryModel;
}

View file

@ -191,6 +191,7 @@
#include <GPUIdent.h>
#include <gl/GLHelpers.h>
#include <src/scripting/LimitlessVoiceRecognitionScriptingInterface.h>
#include <src/scripting/GooglePolyScriptingInterface.h>
#include <EntityScriptClient.h>
#include <ModelScriptingInterface.h>
@ -698,6 +699,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
DependencyManager::set<EntityScriptClient>();
DependencyManager::set<EntityScriptServerLogClient>();
DependencyManager::set<LimitlessVoiceRecognitionScriptingInterface>();
DependencyManager::set<GooglePolyScriptingInterface>();
DependencyManager::set<OctreeStatsProvider>(nullptr, qApp->getOcteeSceneStats());
DependencyManager::set<AvatarBookmarks>();
DependencyManager::set<LocationBookmarks>();
@ -5941,6 +5943,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe
scriptEngine->registerGlobalObject("Users", DependencyManager::get<UsersScriptingInterface>().data());
scriptEngine->registerGlobalObject("LimitlessSpeechRecognition", DependencyManager::get<LimitlessVoiceRecognitionScriptingInterface>().data());
scriptEngine->registerGlobalObject("GooglePoly", DependencyManager::get<GooglePolyScriptingInterface>().data());
if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) {
scriptEngine->registerGlobalObject("Steam", new SteamScriptingInterface(scriptEngine.data(), steamClient.get()));

View file

@ -0,0 +1,181 @@
//
// GooglePolyScriptingInterface.cpp
// interface/src/scripting
//
// Created by Elisa Lupin-Jimenez on 12/3/2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QEventLoop>
#include <QtGlobal>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QString>
#include <QTime>
#include <QUrl>
#include <random>
#include "GooglePolyScriptingInterface.h"
#include "ScriptEngineLogging.h"
const QString LIST_POLY_URL = "https://poly.googleapis.com/v1/assets?";
const QString GET_POLY_URL = "https://poly.googleapis.com/v1/assets/model?";
const QStringList VALID_FORMATS = QStringList() << "BLOCKS" << "FBX" << "GLTF" << "GLTF2" << "OBJ" << "TILT" << "";
const QStringList VALID_CATEGORIES = QStringList() << "animals" << "architecture" << "art" << "food" <<
"nature" << "objects" << "people" << "scenes" << "technology" << "transport" << "";
GooglePolyScriptingInterface::GooglePolyScriptingInterface() {
// nothing to be implemented
}
void GooglePolyScriptingInterface::setAPIKey(const QString& key) {
_authCode = key;
}
QString GooglePolyScriptingInterface::getAssetList(const QString& keyword, const QString& category, const QString& format) {
QUrl url = formatURLQuery(keyword, category, format);
if (!url.isEmpty()) {
QByteArray json = parseJSON(url, 0).toJsonDocument().toJson();
return (QString) json;
} else {
qCDebug(scriptengine) << "Invalid filters were specified.";
return "";
}
}
QString GooglePolyScriptingInterface::getFBX(const QString& keyword, const QString& category) {
QUrl url = formatURLQuery(keyword, category, "FBX");
return getModelURL(url);
}
QString GooglePolyScriptingInterface::getOBJ(const QString& keyword, const QString& category) {
QUrl url = formatURLQuery(keyword, category, "OBJ");
return getModelURL(url);
}
QString GooglePolyScriptingInterface::getBlocks(const QString& keyword, const QString& category) {
QUrl url = formatURLQuery(keyword, category, "BLOCKS");
return getModelURL(url);
}
QString GooglePolyScriptingInterface::getGLTF(const QString& keyword, const QString& category) {
QUrl url = formatURLQuery(keyword, category, "GLTF");
return getModelURL(url);
}
QString GooglePolyScriptingInterface::getGLTF2(const QString& keyword, const QString& category) {
QUrl url = formatURLQuery(keyword, category, "GLTF2");
return getModelURL(url);
}
// This method will not be useful until we support Tilt models
QString GooglePolyScriptingInterface::getTilt(const QString& keyword, const QString& category) {
QUrl url = formatURLQuery(keyword, category, "TILT");
return getModelURL(url);
}
// Can provide asset name or full URL to model
QString GooglePolyScriptingInterface::getModelInfo(const QString& input) {
QString name(input);
if (input.contains("poly.googleapis") || input.contains("poly.google.com")) {
QStringList list = input.split("/");
if (input.contains("poly.googleapis")) {
name = list[4];
} else {
name = list.last();
}
}
QString urlString(GET_POLY_URL);
urlString = urlString.replace("model", name) + "key=" + _authCode;
qCDebug(scriptengine) << "Google URL request: " << urlString;
QUrl url(urlString);
QString json = parseJSON(url, 2).toString();
return json;
}
int GooglePolyScriptingInterface::getRandIntInRange(int length) {
QTime time = QTime::currentTime();
qsrand((uint)time.msec());
return qrand() % length;
}
QUrl GooglePolyScriptingInterface::formatURLQuery(const QString& keyword, const QString& category, const QString& format) {
QString queries;
if (!VALID_FORMATS.contains(format, Qt::CaseInsensitive) || !VALID_CATEGORIES.contains(category, Qt::CaseInsensitive)) {
return QUrl("");
} else {
if (!keyword.isEmpty()) {
QString keywords(keyword);
keywords.replace(" ", "+");
queries.append("&keywords=" + keywords);
}
if (!category.isEmpty()) {
queries.append("&category=" + category);
}
if (!format.isEmpty()) {
queries.append("&format=" + format);
}
QString urlString(LIST_POLY_URL + "key=" + _authCode + queries);
return QUrl(urlString);
}
}
QString GooglePolyScriptingInterface::getModelURL(const QUrl& url) {
qCDebug(scriptengine) << "Google URL request: " << url;
if (!url.isEmpty()) {
return parseJSON(url, 1).toString();
} else {
qCDebug(scriptengine) << "Invalid filters were specified.";
return "";
}
}
// FIXME: synchronous
QByteArray GooglePolyScriptingInterface::getHTTPRequest(const QUrl& url) {
QNetworkAccessManager manager;
QNetworkReply *response = manager.get(QNetworkRequest(url));
QEventLoop event;
connect(response, SIGNAL(finished()), &event, SLOT(quit()));
event.exec();
return response->readAll();
}
// 0 = asset list, 1 = model from asset list, 2 = specific model
QVariant GooglePolyScriptingInterface::parseJSON(const QUrl& url, int fileType) {
QByteArray jsonString = getHTTPRequest(url);
QJsonDocument doc = QJsonDocument::fromJson(jsonString);
QJsonObject obj = doc.object();
if (obj.isEmpty()) {
qCDebug(scriptengine) << "Assets with specified filters not found";
return "";
}
if (obj.keys().first() == "error") {
QString error = obj.value("error").toObject().value("message").toString();
qCDebug(scriptengine) << error;
return "";
}
if (fileType == 0 || fileType == 1) {
QJsonArray arr = obj.value("assets").toArray();
// return model url
if (fileType == 1) {
int random = getRandIntInRange(arr.size());
QJsonObject json = arr.at(random).toObject();
// nested JSONs
return json.value("formats").toArray().at(0).toObject().value("root").toObject().value("url");
}
// return whole asset list
return QJsonDocument(arr);
// return specific object
} else {
return jsonString;
}
}

View file

@ -0,0 +1,47 @@
//
// GooglePolyScriptingInterface.h
// interface/src/scripting
//
// Created by Elisa Lupin-Jimenez on 12/3/2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_GooglePolyScriptingInterface_h
#define hifi_GooglePolyScriptingInterface_h
#include <QObject>
#include <DependencyManager.h>
class GooglePolyScriptingInterface : public QObject, public Dependency {
Q_OBJECT
public:
GooglePolyScriptingInterface();
public slots:
void setAPIKey(const QString& key);
QString getAssetList(const QString& keyword, const QString& category, const QString& format);
QString getFBX(const QString& keyword, const QString& category);
QString getOBJ(const QString& keyword, const QString& category);
QString getBlocks(const QString& keyword, const QString& categoryy);
QString getGLTF(const QString& keyword, const QString& category);
QString getGLTF2(const QString& keyword, const QString& category);
QString getTilt(const QString& keyword, const QString& category);
QString getModelInfo(const QString& input);
private:
QString _authCode;
QUrl formatURLQuery(const QString& keyword, const QString& category, const QString& format);
QString getModelURL(const QUrl& url);
QByteArray getHTTPRequest(const QUrl& url);
QVariant parseJSON(const QUrl& url, int fileType);
int getRandIntInRange(int length);
};
#endif // hifi_GooglePolyScriptingInterface_h

View file

@ -2082,17 +2082,6 @@ bool EntityItem::removeActionInternal(const QUuid& actionID, EntitySimulationPoi
}
EntityDynamicPointer action = _objectActions[actionID];
action->setOwnerEntity(nullptr);
action->setIsMine(false);
if (simulation) {
action->removeFromSimulation(simulation);
}
bool success = true;
serializeActions(success, _allActionsDataCache);
_dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
auto removedActionType = action->getType();
if ((removedActionType == DYNAMIC_TYPE_HOLD || removedActionType == DYNAMIC_TYPE_FAR_GRAB) && !stillHasGrabActions()) {
_dirtyFlags &= ~Simulation::NO_BOOTSTRAPPING;
@ -2109,7 +2098,17 @@ bool EntityItem::removeActionInternal(const QUuid& actionID, EntitySimulationPoi
// because they should have been set correctly when the action was added
// and/or when children were linked
}
action->setOwnerEntity(nullptr);
action->setIsMine(false);
_objectActions.remove(actionID);
if (simulation) {
action->removeFromSimulation(simulation);
}
bool success = true;
serializeActions(success, _allActionsDataCache);
_dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
setDynamicDataNeedsTransmit(true);
return success;
}

View file

@ -103,6 +103,7 @@
case 'transactionHistory_linkClicked':
tablet.gotoWebScreen(message.marketplaceLink, MARKETPLACES_INJECT_SCRIPT_URL);
break;
case 'goToPurchases_fromWalletHome':
case 'goToPurchases':
tablet.pushOntoStack(MARKETPLACE_PURCHASES_QML_PATH);
break;

View file

@ -29,7 +29,7 @@
var commerceMode = false;
var userIsLoggedIn = false;
var walletNeedsSetup = false;
var metaverseServerURL = "https://metaverse.highfidelity.com";
var marketplaceBaseURL = "https://highfidelity.com";
function injectCommonCode(isDirectoryPage) {
@ -58,7 +58,7 @@
);
// Footer.
var isInitialHiFiPage = location.href === metaverseServerURL + "/marketplace?";
var isInitialHiFiPage = location.href === marketplaceBaseURL + "/marketplace?";
$("body").append(
'<div id="marketplace-navigation">' +
(!isInitialHiFiPage ? '<input id="back-button" type="button" class="white" value="&lt; Back" />' : '') +
@ -70,7 +70,7 @@
// Footer actions.
$("#back-button").on("click", function () {
(document.referrer !== "") ? window.history.back() : window.location = (metaverseServerURL + "/marketplace?");
(document.referrer !== "") ? window.history.back() : window.location = (marketplaceBaseURL + "/marketplace?");
});
$("#all-markets").on("click", function () {
EventBridge.emitWebEvent(GOTO_DIRECTORY);
@ -89,7 +89,7 @@
window.location = "https://clara.io/library?gameCheck=true&public=true";
});
$('#exploreHifiMarketplace').on('click', function () {
window.location = "http://www.highfidelity.com/marketplace";
window.location = marketplaceBaseURL + "/marketplace";
});
}
@ -658,9 +658,9 @@
var HIFI_ITEM_PAGE = 3;
var pageType = DIRECTORY;
if (location.href.indexOf("highfidelity.com/") !== -1) { pageType = HIFI; }
if (location.href.indexOf(marketplaceBaseURL + "/") !== -1) { pageType = HIFI; }
if (location.href.indexOf("clara.io/") !== -1) { pageType = CLARA; }
if (location.href.indexOf("highfidelity.com/marketplace/items/") !== -1) { pageType = HIFI_ITEM_PAGE; }
if (location.href.indexOf(marketplaceBaseURL + "/marketplace/items/") !== -1) { pageType = HIFI_ITEM_PAGE; }
injectCommonCode(pageType === DIRECTORY);
switch (pageType) {
@ -694,7 +694,10 @@
commerceMode = !!parsedJsonMessage.data.commerceMode;
userIsLoggedIn = !!parsedJsonMessage.data.userIsLoggedIn;
walletNeedsSetup = !!parsedJsonMessage.data.walletNeedsSetup;
metaverseServerURL = parsedJsonMessage.data.metaverseServerURL;
marketplaceBaseURL = parsedJsonMessage.data.metaverseServerURL;
if (marketplaceBaseURL.indexOf('metaverse.') !== -1) {
marketplaceBaseURL = marketplaceBaseURL.replace('metaverse.', '');
}
injectCode();
}
}