History

Merge pull request #9190 from jherico/test_mode

Add test mode to interface

samcake committed 9 years ago

Commit 9155f112 parents 4ce1bb3 2a43f5f6 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"
@@ -553,6 +554,20 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 416 unmodified lines
553554 setProperty(hifi::properties::STEAM, SteamClient::isRunning());
554555 setProperty(hifi::properties::CRASHED, _previousSessionCrashed);
555556
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+
556571 _runningMarker.startRunningMarker();
557572
558573 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
13411356 return entityServerNode && !isPhysicsEnabled();
13421357 });
13431358
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;
13441378
1379+ bool hasTutorialContent = contentVersion >= 1;
13451380
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+ }
13791399
1380− const QString TUTORIAL_PATH = "/tutorial_begin";
1400+ const QString TUTORIAL_PATH = "/tutorial_begin";
13811401
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);
13931406 } 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+ }
13951416 }
1396− }
1397− } else {
1417+ } else {
13981418
1399− bool isFirstRun = firstRun.get();
1419+ bool isFirstRun = firstRun.get();
14001420
1401− if (isFirstRun) {
1402− showHelp();
1403− }
1421+ if (isFirstRun) {
1422+ showHelp();
1423+ }
14041424
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+ }
14111435 } else {
1412− qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry.";
14131436 DependencyManager::get<AddressManager>()->goToEntry();
14141437 }
14151438 } 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);
14171441 }
1418− } else {
1419− qCDebug(interfaceapp) << "Not first run... going to" << qPrintable(addressLookupString.isEmpty() ? QString("previous location") : addressLookupString);
1420− DependencyManager::get<AddressManager>()->loadSettings(addressLookupString);
14211442 }
1422− }
14231443
1424− _connectionMonitor.init();
1444+ _connectionMonitor.init();
14251445
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+ }
14281449 }
14291450
14301451 void Application::domainConnectionRefused(const QString& reasonMessage, int reasonCodeInt, const QString& extraInfo) {
@@ -5074,6 +5095,11 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 3643 unmodified lines
50745095 // AvatarManager has some custom types
50755096 AvatarManager::registerMetaTypes(scriptEngine);
50765097
5098+ if (property(hifi::properties::TEST).isValid()) {
5099+ scriptEngine->registerGlobalObject("Test", TestScriptingInterface::getInstance());
5100+ }
5101+
5102+ scriptEngine->registerGlobalObject("Overlays", &_overlays);
50775103 scriptEngine->registerGlobalObject("Rates", new RatesScriptingInterface(this));
50785104
50795105 // hook our avatar and avatar hash map object into this script engine