From 9f53652dfb7c2f37833d465d2cf2f05e5a2f6806 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 21 Sep 2016 09:29:40 -0700 Subject: [PATCH] Add routing of new users to tutorial --- interface/src/Application.cpp | 97 ++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 24 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fcd6c59b63..a81084d853 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1255,6 +1255,79 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : return entityServerNode && !isPhysicsEnabled(); }); + + + // Initialize location + + auto initializeLocation = [this]() { + // Get sandbox content set version, if available + auto acDirPath = PathUtils::getRootDataDirectory() + qApp->organizationName() + "/assignment-client/"; + auto contentVersionPath = acDirPath + "content-version.txt"; + auto contentVersion = 0; + QFile contentVersionFile(contentVersionPath); + if (contentVersionFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QString line = contentVersionFile.readAll(); + // toInt() returns 0 if the conversion fails, so we don't need to specifically check for failure + contentVersion = line.toInt(); + } + qDebug() << "Server content version: " << contentVersion; + + bool hasTutorialContent = contentVersion >= 1; + + Setting::Handle firstRun { Settings::firstRun, true }; + bool isOnVive = _displayPlugin && _displayPlugin->getName() == "OpenVR (Vive)"; + bool isFirstRun = firstRun.get(); + Setting::Handle tutorialComplete { "tutorialComplete", false }; + + bool shouldGoToTutorial = isOnVive && hasTutorialContent && !tutorialComplete.get(); + qDebug() << "Is on vive " << isOnVive << ", " << _displayPlugin->getName(); + qDebug() << "has tutorial content" << hasTutorialContent; + qDebug() << "tutorial complete" << tutorialComplete.get(); + qDebug() << "should go to tutorial " << shouldGoToTutorial; + + + + if (shouldGoToTutorial) { + DependencyManager::get()->ifLocalSandboxRunningElse([=]() { + qDebug() << "Home sandbox appears to be running, going to Home."; + //DependencyManager::get()->goToLocalSandbox("/tutorial"); + DependencyManager::get()->loadSettings("hifi://sport/tutorial"); + }, [=]() { + qDebug() << "Home sandbox does not appear to be running, going to Entry."; + showHelp(); + DependencyManager::get()->goToEntry(); + }); + } else { + + // when --url in command line, teleport to location + const QString HIFI_URL_COMMAND_LINE_KEY = "--url"; + int urlIndex = arguments().indexOf(HIFI_URL_COMMAND_LINE_KEY); + QString addressLookupString; + if (urlIndex != -1) { + addressLookupString = arguments().value(urlIndex + 1); + } + + if (firstRun.get()) { + showHelp(); + } + + if (addressLookupString.isEmpty() && firstRun.get()) { + DependencyManager::get()->ifLocalSandboxRunningElse([=]() { + qDebug() << "Home sandbox appears to be running, going to Home."; + DependencyManager::get()->goToLocalSandbox(); + }, [=]() { + qDebug() << "Home sandbox does not appear to be running, going to Entry."; + DependencyManager::get()->goToEntry(); + }); + } else { + qDebug() << "Not first run... going to" << qPrintable(addressLookupString.isEmpty() ? QString("previous location") : addressLookupString); + DependencyManager::get()->loadSettings(addressLookupString); + } + } + }; + + initializeLocation(); + // After all of the constructor is completed, then set firstRun to false. Setting::Handle firstRun{ Settings::firstRun, true }; firstRun.set(false); @@ -3279,15 +3352,6 @@ void Application::init() { _timerStart.start(); _lastTimeUpdated.start(); - - // when --url in command line, teleport to location - const QString HIFI_URL_COMMAND_LINE_KEY = "--url"; - int urlIndex = arguments().indexOf(HIFI_URL_COMMAND_LINE_KEY); - QString addressLookupString; - if (urlIndex != -1) { - addressLookupString = arguments().value(urlIndex + 1); - } - // when +connect_lobby in command line, join steam lobby const QString STEAM_LOBBY_COMMAND_LINE_KEY = "+connect_lobby"; int lobbyIndex = arguments().indexOf(STEAM_LOBBY_COMMAND_LINE_KEY); @@ -3296,21 +3360,6 @@ void Application::init() { SteamClient::joinLobby(lobbyId); } - Setting::Handle firstRun { Settings::firstRun, true }; - if (addressLookupString.isEmpty() && firstRun.get()) { - qCDebug(interfaceapp) << "First run and no URL passed... attempting to go to Home or Entry..."; - DependencyManager::get()->ifLocalSandboxRunningElse([](){ - qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home."; - DependencyManager::get()->goToLocalSandbox(); - }, - [](){ - qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry."; - DependencyManager::get()->goToEntry(); - }); - } else { - qCDebug(interfaceapp) << "Not first run... going to" << qPrintable(addressLookupString.isEmpty() ? QString("previous location") : addressLookupString); - DependencyManager::get()->loadSettings(addressLookupString); - } qCDebug(interfaceapp) << "Loaded settings";