static private void GetProblemsFromSeed() { string seedPath = SeedFilePath(); byte [] seedContents = System.IO.File.ReadAllBytes(seedPath); MemoryStream seedStream = new MemoryStream(seedContents); if (seedContents.Length == 0) { ThinksyPlugin.ShowEmergencyWindow("The seed file is empty! (" + seedPath + ")"); throw new Exception("The seed file is empty!"); } //Message.Problem.ProblemGetResponse problemGet = Message.Problem.ProblemGetResponse.ParseFrom (seedContents); //Message.Problem.ProblemGetResponse problemGet = ProtoBuf.Serializer.Deserialize<Message.Problem.ProblemGetResponse> (seedStream); ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer(); Message.Problem.ProblemGetResponse problemGet = customSerializer.Deserialize(seedStream, null, typeof(Message.Problem.ProblemGetResponse)) as Message.Problem.ProblemGetResponse; for (int i = 0; i < problemGet.problems.Count; i++) { Message.Problem.ProblemData problem = problemGet.problems[i]; ProblemKeeper.AddProblemsToProblemQueue(problem); } }
/// <summary> /// Returns false for an error, or true for no errors. /// </summary> static public bool NetworkErrorChecking(WWW recvResult) { //Did we receive any response? if (!string.IsNullOrEmpty(recvResult.error)) { UnityEngine.Debug.LogWarning(recvResult.error); if (secretStagingMode) { ThinksyPlugin.ShowEmergencyWindow(recvResult.error); } SenseixSession.SetSessionState(false); if (recvResult.error.Equals(401)) { //This is probably a problem with an auth token } else if (recvResult.error.Equals(422)) { //This is probably a server side error } else { //This is probably a 500. //This is a bad place in which to be. } return(false); } return(true); }
void OnEnable() { if (!ThinksyPlugin.UsesLeaderboard()) { gameObject.SetActive(false); } }
private void AnswerGiven(string answer) { int answerNumber = -1; try { answerNumber = System.Convert.ToInt16(answer); } catch { continueButtonText.text = "Please input an integer"; return; } if (answerNumber != firstNumber * secondNumber) { continueButtonText.text = "That's not right..."; return; } if (answerNumber == -1) { ThinksyPlugin.ShowEmergencyWindow("An error was encountered during the parent gate question."); } thisMenu.SetActive(false); nextMenu.SetActive(true); }
static public bool ParseGetEncouragementsResponse(byte[] responseBytes) { Encouragement.EncouragementGetResponse getEncouragementResponse = Deserialize(responseBytes, typeof(Encouragement.EncouragementGetResponse)) as Encouragement.EncouragementGetResponse; Logger.BasicLog("I got an encouragement get response with " + getEncouragementResponse.encouragement_data.Count + " encouragements."); foreach (Encouragement.EncouragementData encouragementData in getEncouragementResponse.encouragement_data) { ProblemPart[] encouragementParts = new ProblemPart[encouragementData.encouragement_atoms.Count]; for (int i = 0; i < encouragementParts.Length; i++) { encouragementParts[i] = ProblemPart.CreateProblemPart(encouragementData.encouragement_atoms[i]); } ThinksyEvents.InvokeEncouragementReceived(encouragementParts); } ThinksyPlugin.NewHeartbeatTiming(getEncouragementResponse.frames_per_heartbeat); if (getEncouragementResponse.force_pull) { ProblemKeeper.PullNewProblems(); } return(true); }
static public string SeedFilePath() { string[] files = Directory.GetFiles(Application.persistentDataPath, "*" + SEED_FILE_EXTENSION); foreach (string filename in files) { //test overrides everything if (filename.Contains("test")) { return(filename); } } //next priority is player specific string playerSeedPath = PlayerSeedPath(); if (File.Exists(playerSeedPath)) { return(playerSeedPath); } //then failsafe or anything else if (files.Length == 0) { ThinksyPlugin.ShowEmergencyWindow("No seed files found in " + Application.persistentDataPath); throw new Exception("No seed files found in " + Application.persistentDataPath); } return(files[0]); }
private void UpdateAnswers() { availableAnswers.Clear(); ProblemPart[] wrongAnswers = new ProblemPart[answerButtonTexts.Length - 1]; if (ThinksyPlugin.GetMostRecentProblem().CountDistractors() >= wrongAnswers.Length) { wrongAnswers = ThinksyPlugin.GetMostRecentProblem().GetDistractors(wrongAnswers.Length); } else { for (int i = 0; i < wrongAnswers.Length; i++) { wrongAnswers [i] = ThinksyPlugin.GetMostRecentProblem().GetDistractor(); } } foreach (ProblemPart wrongAnswer in wrongAnswers) { //add the number of buttons minus one wrong answers availableAnswers.Add(wrongAnswer); } availableAnswers.Add(ThinksyPlugin.GetMostRecentProblem().GetCurrentCorrectAnswerPart()); //add the one right answer Shuffle(availableAnswers); }
public void SecretStagingSwap(int tapOrder) { if (tapOrder != secretStagingCounter) { secretStagingCounter = 1; } else { secretStagingCounter++; } UnityEngine.Debug.Log(secretStagingCounter); if (secretStagingCounter != 5) { return; } secretStagingCounter = 1; UnityEngine.Debug.Log("Super secret staging strike!"); //Handheld.Vibrate (); StagingStrike.Boom(); SERVER_URL = STAGING_SERVER_URL; //API URLS GENERIC_HDR = ENCRYPTED + SERVER_URL + API_VERSION; PARENT_HDR = GENERIC_HDR + "/devices/"; PLAYER_HDR = GENERIC_HDR + "/players/"; PROBLEM_HDR = GENERIC_HDR + "/problems/"; LEADERBOARD_HDR = GENERIC_HDR + "/applications/leaderboard/"; DEBUG_HDR = GENERIC_HDR + "/debug/"; //Requests related to Parent management REGISTER_DEVICE_URL = PARENT_HDR + "create_device"; VERIFY_GAME_URL = PARENT_HDR + "game_verification"; SEND_PARENT_EMAIL_URL = PARENT_HDR + "send_parent_email"; //Requests related to Player management LIST_PLAYER_URL = PLAYER_HDR + "list_players"; REGISTER_PLAYER_WITH_GAME_URL = PLAYER_HDR + "register_player_with_game"; GET_ENCOURAGEMENT_URL = PLAYER_HDR + "get_encouragements"; LIST_ITEMS_URL = PLAYER_HDR + "list_items"; //Requests related to Problems GET_PROBLEM_URL = PROBLEM_HDR + "index"; SPECIFIED_GET_PROBLEM_URL = PROBLEM_HDR + "specified_index"; POST_PROBLEM_URL = PROBLEM_HDR + "update"; //Requests related to Leaderboards //GET_LEADERBOARD_PAGE_URL = LEADERBOARD_HDR + "page"; GET_PLAYER_RANK_URL = LEADERBOARD_HDR + "player"; UPDATE_PLAYER_SCORE_URL = LEADERBOARD_HDR + "update_player_score"; //Requests related to Debugging DEBUG_LOG_SUBMIT_URL = DEBUG_HDR + "debug_log_submit"; SenseixSession.SetAndSaveAuthToken(""); SenseixSession.SetCurrentPlayerList(null); //ThinksyPlugin.SetAccessToken("95df4f0f98585ef3679e774878080b7d57e8bb0b5cf9190f866628a4dc497e73"); //use same token from production secretStagingMode = true; ThinksyPlugin.StaticReinitialize(); }
// Use this for initialization void Start() { singletonInstance = this; if (ThinksyPlugin.IsInTestingMode()) { warningImage.sprite = offlineSprite; //warningText.text = "Offline mode"; } }
public void ButtonClick(int choiceIndex) { ThinksyPlugin.GetMostRecentProblem().AddGivenAnswerPart((ProblemPart)availableAnswers [choiceIndex]); if (ThinksyPlugin.AllAnswerPartsGiven()) { SubmitAnswers(); } else { UpdateDisplay(); } }
/// <summary> /// Returns the next Problem for the Player as an instance of the Problem class. If there aren't /// enough Problems left in the queue, an asynchronous task will retrieve more from the Senseix /// server. /// </summary> public static Problem NextProblem() { if (AllAnswerPartsGiven() && !GetMostRecentProblem().HasBeenSubmitted()) { ThinksyPlugin.GetMostRecentProblem().SubmitAnswer(); } Senseix.Message.Problem.ProblemData protobufsProblem = Senseix.SenseixSession.PullProblem(); Senseix.Logger.BasicLog("Next problem! Problem ID: " + protobufsProblem.uuid + " Category: " + protobufsProblem.category_name); //Debug.Log ("Next problem! Problem ID: " + protobufsProblem.uuid + " Category: " + protobufsProblem.category_name); mostRecentProblem = new Problem(protobufsProblem); ThinksyQuestionDisplay.DisplayCurrentQuestion(); return(mostRecentProblem); }
static public Senseix.Message.Problem.ProblemData GetProblem() { CheckProblemPull(); if (newProblems.Count == 0) { GetProblemsFromSeed(); } if (newProblems.Count == 0) { ThinksyPlugin.ShowEmergencyWindow("We ran out of problems. That really shouldn't happen!"); } return((Senseix.Message.Problem.ProblemData)newProblems.Dequeue()); }
static private ThinksyPlugin GetSingletonInstance() { if (singletonInstance == null) { singletonInstance = FindObjectOfType <ThinksyPlugin>(); } if (singletonInstance == null) { throw new Exception("Please drag the Thinksy prefab located in " + "thinsy_unity_plugin/prefabs into your object heierarchy"); } return(singletonInstance); }
private void SubmitAnswers() { if (ThinksyPlugin.GetMostRecentProblem().SubmitAnswer()) { AudioManager.audioManager.PlaySuccess(); CorrectLight.LightShow(); } else { AudioManager.audioManager.PlayFailure(); } NextProblem(); }
public static IEnumerator InitializeSenseix(string newAccessToken) { //Debug.Log ("initializing"); if (isInitializing) { Logger.BasicLog("already initializing"); yield break; } isInitializing = true; yield return(GetSingletonInstance().StartCoroutine(WaitForWebGLInitializing())); SetSessionState(true); accessToken = newAccessToken; if (CheckAccessToken() == -1) { throw new Exception("The Thinksy Token you have provided is not of a valid length, please" + " register at https://developer.thinksylearn.com/ to create a valid key. Then, fill " + "in the Game Access Token field of the ThinksyPlugin script on the Thinksy Prefab." + " You can also test offline by checking the testing mode boolean on the Thinksy Prefab."); } //Creates a temporary account based on device id //returns an auth token. This is Syncronous. //Debug.Log("registering device"); yield return(GetSingletonInstance().StartCoroutine(RegisterDevice())); //Debug.Log ("listing players"); yield return(GetSingletonInstance().StartCoroutine(ListPlayers())); //Debug.Log("register all players"); yield return(GetSingletonInstance().StartCoroutine(RegisterAllPlayers())); //Debug.Log("submit cache"); SenseixSession.CheckProblemPostCacheSubmission(); //SenseixPlugin.ShowEmergencyWindow ("testing"); //yield return GetSingletonInstance().StartCoroutine(Message.Request.UpdatePlayerScore (GetCurrentPlayerID(), 0)); //yield return GetSingletonInstance().StartCoroutine(Message.Request.GetPlayerRank (GetCurrentPlayerID ())); yield return(Message.Request.GetSingletonInstance().StartCoroutine( Message.Request.GetProblems(SenseixSession.GetCurrentPlayerID(), ProblemKeeper.PROBLEMS_PER_PULL))); ThinksyPlugin.GetMostRecentProblem(); isInitializing = false; }
public void SetStudent(int studentIndex) { if (availablePlayers.Count <= 0) { return; } currentPlayerIndex = studentIndex % availablePlayers.Count; if (currentPlayerIndex < 0) { currentPlayerIndex = availablePlayers.Count + currentPlayerIndex; } SenseixSession.SelectPlayer(GetCurrentPlayer()); SetName(); SetFace(); ThinksyPlugin.NextProblem(); }
public static IEnumerator InitializeSenseix(string newAccessToken) { //Debug.Log ("initializing"); yield return(GetSingletonInstance().StartCoroutine(LimitedInitializeSenseix(newAccessToken))); //Debug.Log("submit cache"); SenseixSession.CheckProblemPostCacheSubmission(); //SenseixPlugin.ShowEmergencyWindow ("testing"); //yield return GetSingletonInstance().StartCoroutine(Message.Request.UpdatePlayerScore (GetCurrentPlayerID(), 0)); //yield return GetSingletonInstance().StartCoroutine(Message.Request.GetPlayerRank (GetCurrentPlayerID ())); yield return(Message.Request.GetSingletonInstance().StartCoroutine( Message.Request.GetProblems(SenseixSession.GetCurrentPlayerID(), ProblemKeeper.PROBLEMS_PER_PULL))); ThinksyPlugin.GetMostRecentProblem(); EndInitialize(); }
public static void HandleResult(WWW recvResult, ResponseHandlerDelegate resultHandler) { byte[] responseBytes = new byte[0]; if (NetworkErrorChecking(recvResult)) { responseBytes = recvResult.bytes; //UnityEngine.Debug.Log ("Recv result is " + recvResult.bytes.Length + " bytes long"); //UnityEngine.Debug.Log ("parse response"); if (responseBytes.Length == 0) { Logger.BasicLog("I got an empty server response. This is normal for certain responses."); return; } bool isAnError = true; try { isAnError = Response.ParseServerErrorResponse(responseBytes); } catch { HandleNonerrorResponse(responseBytes, resultHandler); } if (!isAnError) { HandleNonerrorResponse(responseBytes, resultHandler); } } else { string logString = "A SenseiX message (Handler: " + resultHandler.Method.Name + ") had an error. " + "Most likely internet connectivity issues."; UnityEngine.Debug.LogWarning(logString); if (secretStagingMode) { ThinksyPlugin.ShowEmergencyWindow(logString); } SenseixSession.SetSessionState(false); } return; }
static public void CopyFailsafeOver() { string failsafeFileName = "failsafe"; string failsafeDestination = System.IO.Path.Combine(Application.persistentDataPath, failsafeFileName + SEED_FILE_EXTENSION); TextAsset failsafeAsset = Resources.Load <TextAsset>(failsafeFileName); byte[] failsafeContents = failsafeAsset.bytes; try { FileStream newFile = System.IO.File.Create(failsafeDestination); SenseixSession.DoFileFlagging(failsafeDestination); newFile.Close(); System.IO.File.WriteAllBytes(failsafeDestination, failsafeContents); } catch { ThinksyPlugin.ShowEmergencyWindow("An error occurred while creating a failsafe seed file in " + failsafeDestination); } }
static public bool ParseServerErrorResponse(byte[] responseBytes) { Debug.ServerErrorResponse serverErrorResponse = Deserialize(responseBytes, typeof(Debug.ServerErrorResponse)) as Debug.ServerErrorResponse; if (serverErrorResponse.message.Length == 0) { return(false); } string logString = "I got a server error response. Here is the message: " + serverErrorResponse.message; if (Request.IsInSecretStagingMode()) { ThinksyPlugin.ShowEmergencyWindow(logString); } UnityEngine.Debug.LogError(logString); return(true); }
static private void ReplaceSeed(Message.Problem.ProblemGetResponse reply) { Logger.BasicLog("Replacing seed file."); MemoryStream stream = new MemoryStream(); ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer(); customSerializer.Serialize(stream, reply); byte[] replacementBytes = stream.ToArray(); try { FileStream newFile = System.IO.File.Create(PlayerSeedPath()); SenseixSession.DoFileFlagging(PlayerSeedPath()); newFile.Close(); } catch { ThinksyPlugin.ShowEmergencyWindow("An error occurred while creating a seedfile in " + PlayerSeedPath()); } stream.Close(); System.IO.File.WriteAllBytes(SeedFilePath(), replacementBytes); SenseixSession.DoFileFlagging(SeedFilePath()); }
private void NextProblem() { ThinksyPlugin.NextProblem(); UpdateDisplay(); }
private void InstanceDisplayCurrentQuestion() { DisplayProblem(ThinksyPlugin.GetMostRecentProblem()); }
private static ThinksyPlugin GetSingletonInstance() { if (singletonInstance == null) { singletonInstance = FindObjectOfType<ThinksyPlugin>(); } if (singletonInstance == null) { throw new Exception("Please drag the Thinksy prefab located in " + "thinsy_unity_plugin/prefabs into your object heierarchy " + "and ensure that it is enabled."); } return singletonInstance; }