Add test mode to interface
Showing the changes to interface/src/Application.cpp (1 of 6 files). Show all
Unified · Split
| @@ -131,6 +131,7 @@ · 130 unmodified lines | ||
| 131 | 131 | #include "LODManager.h" |
| 132 | 132 | #include "ModelPackager.h" |
| 133 | 133 | #include "networking/HFWebEngineProfile.h" |
| 134 | +#include "scripting/TestScriptingInterface.h" | |
| 134 | 135 | #include "scripting/AccountScriptingInterface.h" |
| 135 | 136 | #include "scripting/AssetMappingsScriptingInterface.h" |
| 136 | 137 | #include "scripting/AudioDeviceScriptingInterface.h" |
| @@ -553,6 +554,20 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 416 unmodified lines | ||
| 553 | 554 | setProperty(hifi::properties::STEAM, SteamClient::isRunning()); |
| 554 | 555 | setProperty(hifi::properties::CRASHED, _previousSessionCrashed); |
| 555 | 556 | |
| 557 | + { | |
| 558 | + const QString TEST_SCRIPT = "--testScript"; | |
| 559 | + const QStringList args = arguments(); | |
| 560 | + for (int i = 0; i < args.size() - 1; ++i) { | |
| 561 | + if (args.at(i) == TEST_SCRIPT) { | |
| 562 | + QString testScriptPath = args.at(i + 1); | |
| 563 | + if (QFileInfo(testScriptPath).exists()) { | |
| 564 | + setProperty(hifi::properties::TEST, QUrl::fromLocalFile(testScriptPath)); | |
| 565 | + } | |
| 566 | + } | |
| 567 | + } | |
| 568 | + } | |
| 569 | + | |
| 570 | + | |
| 556 | 571 | _runningMarker.startRunningMarker(); |
| 557 | 572 | |
| 558 | 573 | PluginContainer* pluginContainer = dynamic_cast<PluginContainer*>(this); // set the container for any plugins that care |
| @@ -1341,90 +1356,96 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 782 unmodified lines | ||
| 1341 | 1356 | return entityServerNode && !isPhysicsEnabled(); |
| 1342 | 1357 | }); |
| 1343 | 1358 | |
| 1359 | + QVariant testProperty = property(hifi::properties::TEST); | |
| 1360 | + qDebug() << testProperty; | |
| 1361 | + if (testProperty.isValid()) { | |
| 1362 | + auto scriptEngines = DependencyManager::get<ScriptEngines>(); | |
| 1363 | + const auto testScript = property(hifi::properties::TEST).toUrl(); | |
| 1364 | + scriptEngines->loadScript(testScript, false); | |
| 1365 | + } else { | |
| 1366 | + // Get sandbox content set version, if available | |
| 1367 | + auto acDirPath = PathUtils::getRootDataDirectory() + BuildInfo::MODIFIED_ORGANIZATION + "/assignment-client/"; | |
| 1368 | + auto contentVersionPath = acDirPath + "content-version.txt"; | |
| 1369 | + qCDebug(interfaceapp) << "Checking " << contentVersionPath << " for content version"; | |
| 1370 | + auto contentVersion = 0; | |
| 1371 | + QFile contentVersionFile(contentVersionPath); | |
| 1372 | + if (contentVersionFile.open(QIODevice::ReadOnly | QIODevice::Text)) { | |
| 1373 | + QString line = contentVersionFile.readAll(); | |
| 1374 | + // toInt() returns 0 if the conversion fails, so we don't need to specifically check for failure | |
| 1375 | + contentVersion = line.toInt(); | |
| 1376 | + } | |
| 1377 | + qCDebug(interfaceapp) << "Server content version: " << contentVersion; | |
| 1344 | 1378 | |
| 1379 | + bool hasTutorialContent = contentVersion >= 1; | |
| 1345 | 1380 | |
| 1346 | − // Get sandbox content set version, if available | |
| 1347 | − auto acDirPath = PathUtils::getRootDataDirectory() + BuildInfo::MODIFIED_ORGANIZATION + "/assignment-client/"; | |
| 1348 | − auto contentVersionPath = acDirPath + "content-version.txt"; | |
| 1349 | − qCDebug(interfaceapp) << "Checking " << contentVersionPath << " for content version"; | |
| 1350 | − auto contentVersion = 0; | |
| 1351 | − QFile contentVersionFile(contentVersionPath); | |
| 1352 | − if (contentVersionFile.open(QIODevice::ReadOnly | QIODevice::Text)) { | |
| 1353 | − QString line = contentVersionFile.readAll(); | |
| 1354 | − // toInt() returns 0 if the conversion fails, so we don't need to specifically check for failure | |
| 1355 | − contentVersion = line.toInt(); | |
| 1356 | − } | |
| 1357 | − qCDebug(interfaceapp) << "Server content version: " << contentVersion; | |
| 1358 | − | |
| 1359 | − bool hasTutorialContent = contentVersion >= 1; | |
| 1360 | − | |
| 1361 | − Setting::Handle<bool> firstRun { Settings::firstRun, true }; | |
| 1362 | − bool hasHMDAndHandControllers = PluginUtils::isHMDAvailable("OpenVR (Vive)") && PluginUtils::isHandControllerAvailable(); | |
| 1363 | − Setting::Handle<bool> tutorialComplete { "tutorialComplete", false }; | |
| 1364 | − | |
| 1365 | − bool shouldGoToTutorial = hasHMDAndHandControllers && hasTutorialContent && !tutorialComplete.get(); | |
| 1366 | − | |
| 1367 | − qCDebug(interfaceapp) << "Has HMD + Hand Controllers: " << hasHMDAndHandControllers << ", current plugin: " << _displayPlugin->getName(); | |
| 1368 | − qCDebug(interfaceapp) << "Has tutorial content: " << hasTutorialContent; | |
| 1369 | − qCDebug(interfaceapp) << "Tutorial complete: " << tutorialComplete.get(); | |
| 1370 | − qCDebug(interfaceapp) << "Should go to tutorial: " << shouldGoToTutorial; | |
| 1371 | − | |
| 1372 | − // when --url in command line, teleport to location | |
| 1373 | − const QString HIFI_URL_COMMAND_LINE_KEY = "--url"; | |
| 1374 | − int urlIndex = arguments().indexOf(HIFI_URL_COMMAND_LINE_KEY); | |
| 1375 | − QString addressLookupString; | |
| 1376 | − if (urlIndex != -1) { | |
| 1377 | − addressLookupString = arguments().value(urlIndex + 1); | |
| 1378 | − } | |
| 1381 | + Setting::Handle<bool> firstRun { Settings::firstRun, true }; | |
| 1382 | + bool hasHMDAndHandControllers = PluginUtils::isHMDAvailable("OpenVR (Vive)") && PluginUtils::isHandControllerAvailable(); | |
| 1383 | + Setting::Handle<bool> tutorialComplete { "tutorialComplete", false }; | |
| 1384 | + | |
| 1385 | + bool shouldGoToTutorial = hasHMDAndHandControllers && hasTutorialContent && !tutorialComplete.get(); | |
| 1386 | + | |
| 1387 | + qCDebug(interfaceapp) << "Has HMD + Hand Controllers: " << hasHMDAndHandControllers << ", current plugin: " << _displayPlugin->getName(); | |
| 1388 | + qCDebug(interfaceapp) << "Has tutorial content: " << hasTutorialContent; | |
| 1389 | + qCDebug(interfaceapp) << "Tutorial complete: " << tutorialComplete.get(); | |
| 1390 | + qCDebug(interfaceapp) << "Should go to tutorial: " << shouldGoToTutorial; | |
| 1391 | + | |
| 1392 | + // when --url in command line, teleport to location | |
| 1393 | + const QString HIFI_URL_COMMAND_LINE_KEY = "--url"; | |
| 1394 | + int urlIndex = arguments().indexOf(HIFI_URL_COMMAND_LINE_KEY); | |
| 1395 | + QString addressLookupString; | |
| 1396 | + if (urlIndex != -1) { | |
| 1397 | + addressLookupString = arguments().value(urlIndex + 1); | |
| 1398 | + } | |
| 1379 | 1399 | |
| 1380 | − const QString TUTORIAL_PATH = "/tutorial_begin"; | |
| 1400 | + const QString TUTORIAL_PATH = "/tutorial_begin"; | |
| 1381 | 1401 | |
| 1382 | − if (shouldGoToTutorial) { | |
| 1383 | − if(sandboxIsRunning) { | |
| 1384 | − qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home."; | |
| 1385 | − DependencyManager::get<AddressManager>()->goToLocalSandbox(TUTORIAL_PATH); | |
| 1386 | − } else { | |
| 1387 | − qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry."; | |
| 1388 | − if (firstRun.get()) { | |
| 1389 | − showHelp(); | |
| 1390 | − } | |
| 1391 | − if (addressLookupString.isEmpty()) { | |
| 1392 | − DependencyManager::get<AddressManager>()->goToEntry(); | |
| 1402 | + if (shouldGoToTutorial) { | |
| 1403 | + if (sandboxIsRunning) { | |
| 1404 | + qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home."; | |
| 1405 | + DependencyManager::get<AddressManager>()->goToLocalSandbox(TUTORIAL_PATH); | |
| 1393 | 1406 | } else { |
| 1394 | − DependencyManager::get<AddressManager>()->loadSettings(addressLookupString); | |
| 1407 | + qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry."; | |
| 1408 | + if (firstRun.get()) { | |
| 1409 | + showHelp(); | |
| 1410 | + } | |
| 1411 | + if (addressLookupString.isEmpty()) { | |
| 1412 | + DependencyManager::get<AddressManager>()->goToEntry(); | |
| 1413 | + } else { | |
| 1414 | + DependencyManager::get<AddressManager>()->loadSettings(addressLookupString); | |
| 1415 | + } | |
| 1395 | 1416 | } |
| 1396 | − } | |
| 1397 | − } else { | |
| 1417 | + } else { | |
| 1398 | 1418 | |
| 1399 | − bool isFirstRun = firstRun.get(); | |
| 1419 | + bool isFirstRun = firstRun.get(); | |
| 1400 | 1420 | |
| 1401 | − if (isFirstRun) { | |
| 1402 | − showHelp(); | |
| 1403 | − } | |
| 1421 | + if (isFirstRun) { | |
| 1422 | + showHelp(); | |
| 1423 | + } | |
| 1404 | 1424 | |
| 1405 | − // If this is a first run we short-circuit the address passed in | |
| 1406 | − if (isFirstRun) { | |
| 1407 | − if (hasHMDAndHandControllers) { | |
| 1408 | − if(sandboxIsRunning) { | |
| 1409 | − qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home."; | |
| 1410 | − DependencyManager::get<AddressManager>()->goToLocalSandbox(); | |
| 1425 | + // If this is a first run we short-circuit the address passed in | |
| 1426 | + if (isFirstRun) { | |
| 1427 | + if (hasHMDAndHandControllers) { | |
| 1428 | + if (sandboxIsRunning) { | |
| 1429 | + qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home."; | |
| 1430 | + DependencyManager::get<AddressManager>()->goToLocalSandbox(); | |
| 1431 | + } else { | |
| 1432 | + qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry."; | |
| 1433 | + DependencyManager::get<AddressManager>()->goToEntry(); | |
| 1434 | + } | |
| 1411 | 1435 | } else { |
| 1412 | − qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry."; | |
| 1413 | 1436 | DependencyManager::get<AddressManager>()->goToEntry(); |
| 1414 | 1437 | } |
| 1415 | 1438 | } else { |
| 1416 | − DependencyManager::get<AddressManager>()->goToEntry(); | |
| 1439 | + qCDebug(interfaceapp) << "Not first run... going to" << qPrintable(addressLookupString.isEmpty() ? QString("previous location") : addressLookupString); | |
| 1440 | + DependencyManager::get<AddressManager>()->loadSettings(addressLookupString); | |
| 1417 | 1441 | } |
| 1418 | − } else { | |
| 1419 | − qCDebug(interfaceapp) << "Not first run... going to" << qPrintable(addressLookupString.isEmpty() ? QString("previous location") : addressLookupString); | |
| 1420 | − DependencyManager::get<AddressManager>()->loadSettings(addressLookupString); | |
| 1421 | 1442 | } |
| 1422 | − } | |
| 1423 | 1443 | |
| 1424 | − _connectionMonitor.init(); | |
| 1444 | + _connectionMonitor.init(); | |
| 1425 | 1445 | |
| 1426 | − // After all of the constructor is completed, then set firstRun to false. | |
| 1427 | − firstRun.set(false); | |
| 1446 | + // After all of the constructor is completed, then set firstRun to false. | |
| 1447 | + firstRun.set(false); | |
| 1448 | + } | |
| 1428 | 1449 | } |
| 1429 | 1450 | |
| 1430 | 1451 | void Application::domainConnectionRefused(const QString& reasonMessage, int reasonCodeInt, const QString& extraInfo) { |
| @@ -5074,6 +5095,11 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 3643 unmodified lines | ||
| 5074 | 5095 | // AvatarManager has some custom types |
| 5075 | 5096 | AvatarManager::registerMetaTypes(scriptEngine); |
| 5076 | 5097 | |
| 5098 | + if (property(hifi::properties::TEST).isValid()) { | |
| 5099 | + scriptEngine->registerGlobalObject("Test", TestScriptingInterface::getInstance()); | |
| 5100 | + } | |
| 5101 | + | |
| 5102 | + scriptEngine->registerGlobalObject("Overlays", &_overlays); | |
| 5077 | 5103 | scriptEngine->registerGlobalObject("Rates", new RatesScriptingInterface(this)); |
| 5078 | 5104 | |
| 5079 | 5105 | // hook our avatar and avatar hash map object into this script engine |