History

Add test mode to interface

Brad Davis committed 9 years ago

Commit 2a43f5f1 parent 06b73886 files · +183 −67Browse files

Showing the changes to interface/src/Application.cpp (1 of 6 files). Show all

Unified · Split

interface/src/Application.cpp+93−67
@@ -131,6 +131,7 @@ · 130 unmodified lines
131131 #include "LODManager.h"
132132 #include "ModelPackager.h"
133133 #include "networking/HFWebEngineProfile.h"
134+#include "scripting/TestScriptingInterface.h"
134135 #include "scripting/AccountScriptingInterface.h"
135136 #include "scripting/AssetMappingsScriptingInterface.h"
136137 #include "scripting/AudioDeviceScriptingInterface.h"
@@ -541,6 +542,20 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 404 unmodified lines
541542 setProperty(hifi::properties::STEAM, SteamClient::isRunning());
542543 setProperty(hifi::properties::CRASHED, _previousSessionCrashed);
543544
545+ {
546+ const QString TEST_SCRIPT = "--testScript";
547+ const QStringList args = arguments();
548+ for (int i = 0; i < args.size() - 1; ++i) {
549+ if (args.at(i) == TEST_SCRIPT) {
550+ QString testScriptPath = args.at(i + 1);
551+ if (QFileInfo(testScriptPath).exists()) {
552+ setProperty(hifi::properties::TEST, QUrl::fromLocalFile(testScriptPath));
553+ }
554+ }
555+ }
556+ }
557+
558+
544559 _runningMarker.startRunningMarker();
545560
546561 PluginContainer* pluginContainer = dynamic_cast<PluginContainer*>(this); // set the container for any plugins that care
@@ -1329,90 +1344,96 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 782 unmodified lines
13291344 return entityServerNode && !isPhysicsEnabled();
13301345 });
13311346
1347+ QVariant testProperty = property(hifi::properties::TEST);
1348+ qDebug() << testProperty;
1349+ if (testProperty.isValid()) {
1350+ auto scriptEngines = DependencyManager::get<ScriptEngines>();
1351+ const auto testScript = property(hifi::properties::TEST).toUrl();
1352+ scriptEngines->loadScript(testScript, false);
1353+ } else {
1354+ // Get sandbox content set version, if available
1355+ auto acDirPath = PathUtils::getRootDataDirectory() + BuildInfo::MODIFIED_ORGANIZATION + "/assignment-client/";
1356+ auto contentVersionPath = acDirPath + "content-version.txt";
1357+ qCDebug(interfaceapp) << "Checking " << contentVersionPath << " for content version";
1358+ auto contentVersion = 0;
1359+ QFile contentVersionFile(contentVersionPath);
1360+ if (contentVersionFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
1361+ QString line = contentVersionFile.readAll();
1362+ // toInt() returns 0 if the conversion fails, so we don't need to specifically check for failure
1363+ contentVersion = line.toInt();
1364+ }
1365+ qCDebug(interfaceapp) << "Server content version: " << contentVersion;
13321366
1367+ bool hasTutorialContent = contentVersion >= 1;
13331368
1334− // Get sandbox content set version, if available
1335− auto acDirPath = PathUtils::getRootDataDirectory() + BuildInfo::MODIFIED_ORGANIZATION + "/assignment-client/";
1336− auto contentVersionPath = acDirPath + "content-version.txt";
1337− qCDebug(interfaceapp) << "Checking " << contentVersionPath << " for content version";
1338− auto contentVersion = 0;
1339− QFile contentVersionFile(contentVersionPath);
1340− if (contentVersionFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
1341− QString line = contentVersionFile.readAll();
1342− // toInt() returns 0 if the conversion fails, so we don't need to specifically check for failure
1343− contentVersion = line.toInt();
1344− }
1345− qCDebug(interfaceapp) << "Server content version: " << contentVersion;
1346−
1347− bool hasTutorialContent = contentVersion >= 1;
1348−
1349− Setting::Handle<bool> firstRun { Settings::firstRun, true };
1350− bool hasHMDAndHandControllers = PluginUtils::isHMDAvailable("OpenVR (Vive)") && PluginUtils::isHandControllerAvailable();
1351− Setting::Handle<bool> tutorialComplete { "tutorialComplete", false };
1352−
1353− bool shouldGoToTutorial = hasHMDAndHandControllers && hasTutorialContent && !tutorialComplete.get();
1354−
1355− qCDebug(interfaceapp) << "Has HMD + Hand Controllers: " << hasHMDAndHandControllers << ", current plugin: " << _displayPlugin->getName();
1356− qCDebug(interfaceapp) << "Has tutorial content: " << hasTutorialContent;
1357− qCDebug(interfaceapp) << "Tutorial complete: " << tutorialComplete.get();
1358− qCDebug(interfaceapp) << "Should go to tutorial: " << shouldGoToTutorial;
1359−
1360− // when --url in command line, teleport to location
1361− const QString HIFI_URL_COMMAND_LINE_KEY = "--url";
1362− int urlIndex = arguments().indexOf(HIFI_URL_COMMAND_LINE_KEY);
1363− QString addressLookupString;
1364− if (urlIndex != -1) {
1365− addressLookupString = arguments().value(urlIndex + 1);
1366− }
1369+ Setting::Handle<bool> firstRun { Settings::firstRun, true };
1370+ bool hasHMDAndHandControllers = PluginUtils::isHMDAvailable("OpenVR (Vive)") && PluginUtils::isHandControllerAvailable();
1371+ Setting::Handle<bool> tutorialComplete { "tutorialComplete", false };
1372+
1373+ bool shouldGoToTutorial = hasHMDAndHandControllers && hasTutorialContent && !tutorialComplete.get();
1374+
1375+ qCDebug(interfaceapp) << "Has HMD + Hand Controllers: " << hasHMDAndHandControllers << ", current plugin: " << _displayPlugin->getName();
1376+ qCDebug(interfaceapp) << "Has tutorial content: " << hasTutorialContent;
1377+ qCDebug(interfaceapp) << "Tutorial complete: " << tutorialComplete.get();
1378+ qCDebug(interfaceapp) << "Should go to tutorial: " << shouldGoToTutorial;
1379+
1380+ // when --url in command line, teleport to location
1381+ const QString HIFI_URL_COMMAND_LINE_KEY = "--url";
1382+ int urlIndex = arguments().indexOf(HIFI_URL_COMMAND_LINE_KEY);
1383+ QString addressLookupString;
1384+ if (urlIndex != -1) {
1385+ addressLookupString = arguments().value(urlIndex + 1);
1386+ }
13671387
1368− const QString TUTORIAL_PATH = "/tutorial_begin";
1388+ const QString TUTORIAL_PATH = "/tutorial_begin";
13691389
1370− if (shouldGoToTutorial) {
1371− if(sandboxIsRunning) {
1372− qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home.";
1373− DependencyManager::get<AddressManager>()->goToLocalSandbox(TUTORIAL_PATH);
1374− } else {
1375− qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry.";
1376− if (firstRun.get()) {
1377− showHelp();
1378− }
1379− if (addressLookupString.isEmpty()) {
1380− DependencyManager::get<AddressManager>()->goToEntry();
1390+ if (shouldGoToTutorial) {
1391+ if (sandboxIsRunning) {
1392+ qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home.";
1393+ DependencyManager::get<AddressManager>()->goToLocalSandbox(TUTORIAL_PATH);
13811394 } else {
1382− DependencyManager::get<AddressManager>()->loadSettings(addressLookupString);
1395+ qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry.";
1396+ if (firstRun.get()) {
1397+ showHelp();
1398+ }
1399+ if (addressLookupString.isEmpty()) {
1400+ DependencyManager::get<AddressManager>()->goToEntry();
1401+ } else {
1402+ DependencyManager::get<AddressManager>()->loadSettings(addressLookupString);
1403+ }
13831404 }
1384− }
1385− } else {
1405+ } else {
13861406
1387− bool isFirstRun = firstRun.get();
1407+ bool isFirstRun = firstRun.get();
13881408
1389− if (isFirstRun) {
1390− showHelp();
1391− }
1409+ if (isFirstRun) {
1410+ showHelp();
1411+ }
13921412
1393− // If this is a first run we short-circuit the address passed in
1394− if (isFirstRun) {
1395− if (hasHMDAndHandControllers) {
1396− if(sandboxIsRunning) {
1397− qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home.";
1398− DependencyManager::get<AddressManager>()->goToLocalSandbox();
1413+ // If this is a first run we short-circuit the address passed in
1414+ if (isFirstRun) {
1415+ if (hasHMDAndHandControllers) {
1416+ if (sandboxIsRunning) {
1417+ qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home.";
1418+ DependencyManager::get<AddressManager>()->goToLocalSandbox();
1419+ } else {
1420+ qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry.";
1421+ DependencyManager::get<AddressManager>()->goToEntry();
1422+ }
13991423 } else {
1400− qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry.";
14011424 DependencyManager::get<AddressManager>()->goToEntry();
14021425 }
14031426 } else {
1404− DependencyManager::get<AddressManager>()->goToEntry();
1427+ qCDebug(interfaceapp) << "Not first run... going to" << qPrintable(addressLookupString.isEmpty() ? QString("previous location") : addressLookupString);
1428+ DependencyManager::get<AddressManager>()->loadSettings(addressLookupString);
14051429 }
1406− } else {
1407− qCDebug(interfaceapp) << "Not first run... going to" << qPrintable(addressLookupString.isEmpty() ? QString("previous location") : addressLookupString);
1408− DependencyManager::get<AddressManager>()->loadSettings(addressLookupString);
14091430 }
1410− }
14111431
1412− _connectionMonitor.init();
1432+ _connectionMonitor.init();
14131433
1414− // After all of the constructor is completed, then set firstRun to false.
1415− firstRun.set(false);
1434+ // After all of the constructor is completed, then set firstRun to false.
1435+ firstRun.set(false);
1436+ }
14161437 }
14171438
14181439 void Application::domainConnectionRefused(const QString& reasonMessage, int reasonCodeInt, const QString& extraInfo) {
@@ -5056,6 +5077,11 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 3637 unmodified lines
50565077 // AvatarManager has some custom types
50575078 AvatarManager::registerMetaTypes(scriptEngine);
50585079
5080+ if (property(hifi::properties::TEST).isValid()) {
5081+ scriptEngine->registerGlobalObject("Test", TestScriptingInterface::getInstance());
5082+ }
5083+
5084+ scriptEngine->registerGlobalObject("Overlays", &_overlays);
50595085 scriptEngine->registerGlobalObject("Rates", new RatesScriptingInterface(this));
50605086
50615087 // hook our avatar and avatar hash map object into this script engine