/// <summary> /// Prepare the configuration for a given minigame. /// </summary> public IGameConfiguration ConfigureMiniGameScene(MiniGameCode code, string sessionName) { var miniGameData = AppManager.I.DB.GetMiniGameDataByCode(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); } return(currentGameConfig); }
/// <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); }