void Start() { if (!AppManager.I.NavigationManager.IsInFirstLoadedScene) { return; } AppManager.I.Player.SetCurrentJourneyPosition(Stage, LearningBlock, PlaySession); var config = new MinigameLaunchConfiguration(Difficulty, NumberOfRounds, TutorialEnabled); AppManager.I.GameLauncher.LaunchGame(MiniGameCode, config, true); }
/// <summary> /// Prepare the context and start a minigame. /// </summary> /// <param name="gameCode">The minigame code.</param> /// <param name="launchConfig">The launch configuration. If null, the Teacher will generate a new one.</param> public void LaunchGame(MiniGameCode gameCode, MinigameLaunchConfiguration launchConfig) { LastLaunchConfig = launchConfig; ConfigAI.StartTeacherReport(); var miniGameData = AppManager.I.DB.GetMiniGameDataByCode(gameCode); if (launchConfig.DirectGame) { AppManager.I.NavigationManager.InitNewPlaySession(true, miniGameData); } if (ApplicationConfig.I.DebugLogEnabled) { Debug.Log("StartGame " + gameCode.ToString()); Debug.Log(launchConfig); } // Assign the configuration for the given minigame var minigameSession = DateTime.Now.Ticks.ToString(); currentGameConfig = ConfigureMiniGameScene(gameCode, minigameSession, launchConfig); // Retrieve the packs for the current minigame configuration currentQuestionBuilder = currentGameConfig.SetupBuilder(); currentQuestionPacks = questionPacksGenerator.GenerateQuestionPacks(currentQuestionBuilder); currentGameConfig.Questions = new SequentialQuestionPackProvider(currentQuestionPacks); // Communicate to LogManager the start of a new single minigame play session. if (AppConfig.DebugLogDbInserts) { Debug.Log("InitGameplayLogSession " + gameCode.ToString()); } LogManager.I.LogInfo(InfoEvent.GameStart, "{\"minigame\":\"" + gameCode.ToString() + "\"}"); LogManager.I.StartMiniGame(); // Print the teacher's report now ConfigAI.PrintTeacherReport(); // Play the title dialog for the game //AudioManager.I.PlayDialogue(_gameCode.ToString()+"_Title"); // Launch the game AppManager.I.NavigationManager.GoToMiniGameScene(); }
/// <summary> /// Prepare the context and start a minigame. /// </summary> /// <param name="_gameCode">The minigame code.</param> /// <param name="_launchConfiguration">The launch configuration. If null, the Teacher will generate a new one.</param> /// <param name="forceNewPlaySession">Is this a new play session?</param> public void LaunchGame(MiniGameCode _gameCode, MinigameLaunchConfiguration _launchConfiguration = null, bool forceNewPlaySession = false) { ConfigAI.StartTeacherReport(); if (_launchConfiguration == null) { var difficulty = teacher.GetCurrentDifficulty(_gameCode); var numberOfRounds = teacher.GetCurrentNumberOfRounds(_gameCode); var tutorialEnabled = teacher.GetTutorialEnabled(_gameCode); _launchConfiguration = new MinigameLaunchConfiguration(difficulty, numberOfRounds, tutorialEnabled); } var miniGameData = AppManager.I.DB.GetMiniGameDataByCode(_gameCode); if (forceNewPlaySession) { AppManager.I.NavigationManager.InitNewPlaySession(miniGameData); } if (AppConfig.DebugLogEnabled) { Debug.Log("StartGame " + _gameCode.ToString()); } // Assign the configuration for the given minigame var minigameSession = System.DateTime.Now.Ticks.ToString(); currentGameConfig = ConfigureMiniGameScene(_gameCode, minigameSession); currentGameConfig.Difficulty = _launchConfiguration.Difficulty; currentGameConfig.TutorialEnabled = _launchConfiguration.TutorialEnabled; // Set also the number of rounds // @note: only for assessment, for now if (currentGameConfig is Assessment.IAssessmentConfiguration) { var assessmentConfig = currentGameConfig as Assessment.IAssessmentConfiguration; assessmentConfig.NumberOfRounds = _launchConfiguration.NumberOfRounds; } // Retrieve the packs for the current minigame configuration currentQuestionBuilder = currentGameConfig.SetupBuilder(); currentQuestionPacks = questionPacksGenerator.GenerateQuestionPacks(currentQuestionBuilder); currentGameConfig.Questions = new SequentialQuestionPackProvider(currentQuestionPacks); // Communicate to LogManager the start of a new single minigame play session. if (AppConfig.DebugLogDbInserts) { Debug.Log("InitGameplayLogSession " + _gameCode.ToString()); } LogManager.I.LogInfo(InfoEvent.GameStart, "{\"minigame\":\"" + _gameCode.ToString() + "\"}"); LogManager.I.StartMiniGame(); // Print the teacher's report now ConfigAI.PrintTeacherReport(); // Play the title dialog for the game //AudioManager.I.PlayDialogue(_gameCode.ToString()+"_Title"); // Launch the game AppManager.I.NavigationManager.GoToMiniGameScene(); }
/// <summary> /// Prepare the configuration for a given minigame. /// </summary> public IGameConfiguration ConfigureMiniGameScene(MiniGameCode code, string sessionName, MinigameLaunchConfiguration launchConfig) { var miniGameData = AppManager.I.DB.GetMiniGameDataByCode(code); if (miniGameData == null) { throw new Exception("No game could be loaded from the DB for MiniGameCode " + code); } var defaultContext = new MinigamesGameContext(code, sessionName); // We use reflection to get the correct configuration class given a minigame code // This is needed so the Core is not directly dependent on the minigame classes const string configurationKey = "Configuration"; const string assessmentNamespaceKey = "Assessment"; const string minigamesNamespaceKey = "Minigames"; const string baseNamespaceKey = "Antura"; const string instanceFieldName = "Instance"; string miniGameSceneKey = miniGameData.Scene.Split('_')[1]; string configurationClassName = miniGameSceneKey + "." + miniGameSceneKey + configurationKey; if (miniGameSceneKey != assessmentNamespaceKey) { configurationClassName = minigamesNamespaceKey + "." + configurationClassName; } configurationClassName = baseNamespaceKey + "." + configurationClassName; var configurationClassType = Type.GetType(configurationClassName); if (configurationClassType == null) { throw new Exception("Type " + configurationClassName + " not found. Are the minigame scene and Configuration class ready?"); } var property = configurationClassType.GetProperty(instanceFieldName, BindingFlags.Public | BindingFlags.Static); if (property == null) { throw new Exception("Public static property named " + instanceFieldName + " not found. This should be present in the minigame's Configuration class."); } var currentGameConfig = (IGameConfiguration)property.GetValue(null, null); if (currentGameConfig != null) { currentGameConfig.Context = defaultContext; currentGameConfig.SetMiniGameCode(code); } // Setyp config currentGameConfig.GameData = miniGameData; currentGameConfig.Difficulty = launchConfig.Difficulty; currentGameConfig.TutorialEnabled = launchConfig.TutorialEnabled; currentGameConfig.InsideJourney = launchConfig.InsideJourney; currentGameConfig.IgnoreJourney = launchConfig.IgnoreJourney; // Set also the number of rounds // @note: only for assessment, for now if (currentGameConfig is Assessment.IAssessmentConfiguration) { var assessmentConfig = currentGameConfig as Assessment.IAssessmentConfiguration; assessmentConfig.NumberOfRounds = launchConfig.NumberOfRounds; } return(currentGameConfig); }