diff --git a/MoCha/Assets/Scenes/Goals.unity b/MoCha/Assets/Scenes/Goals.unity index 2516d16..4f0e9c5 100644 Binary files a/MoCha/Assets/Scenes/Goals.unity and b/MoCha/Assets/Scenes/Goals.unity differ diff --git a/MoCha/Assets/Scripts/GetGoals.cs b/MoCha/Assets/Scripts/GetGoals.cs index cb5c15e..0958508 100644 --- a/MoCha/Assets/Scripts/GetGoals.cs +++ b/MoCha/Assets/Scripts/GetGoals.cs @@ -60,14 +60,17 @@ namespace PedometerU.Tests private int savedSteps; private int savedPoints; + public string currentStepsKey; + public string totalPointsKey; + void OnStep (int steps, double distance) { //userDistance = (distance * 3.28084); userSteps = steps + savedSteps; - PlayerPrefs.SetInt("currentSteps",userSteps); + PlayerPrefs.SetInt(currentStepsKey,userSteps); stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString(); userPoints = steps*5 + savedPoints; - PlayerPrefs.SetInt("totalPoints",userPoints); + PlayerPrefs.SetInt(totalPointsKey,userPoints); pointsText.text = "Points: " + userPoints.ToString (); } @@ -82,30 +85,38 @@ namespace PedometerU.Tests void Start () { + PlayerPrefs.DeleteAll(); //danger!! if(prefKey == "daily") { // This should later only get called per goal StartCoroutine(updateRival()); + currentStepsKey = "currentSteps"; + totalPointsKey = "totalPoints"; + } + else + { + currentStepsKey = "currentSteps_p"; + totalPointsKey = "totalPoints_p"; } - savedSteps = PlayerPrefs.GetInt("currentSteps"); - savedPoints = PlayerPrefs.GetInt("totalPoints"); + savedSteps = PlayerPrefs.GetInt(currentStepsKey); + savedPoints = PlayerPrefs.GetInt(totalPointsKey); // Create a new pedometer pedometer = new Pedometer(OnStep); // Reset UI stepText.text = savedSteps.ToString () + "/" + stepsGoal.ToString(); - if(prefKey == "daily") - if(PlayerPrefs.HasKey("totalPoints")) - { - pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString (); - } - else - { - PlayerPrefs.SetInt("totalPoints", 0); - pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString (); - } + if(PlayerPrefs.HasKey(totalPointsKey)) + { + pointsText.text = "Points: " + PlayerPrefs.GetInt(totalPointsKey).ToString (); + } + else + { + PlayerPrefs.SetInt(totalPointsKey, 0); + pointsText.text = "Points: " + PlayerPrefs.GetInt(totalPointsKey).ToString (); + } + if(prefKey == "daily") { if(PlayerPrefs.HasKey("goalDate")) { @@ -217,7 +228,7 @@ namespace PedometerU.Tests updateTimeRemaining (); updateProgressBar (); - updateMyGoalProgressBar (); + //updateMyGoalProgressBar (); if(prefKey == "daily") { @@ -226,9 +237,10 @@ namespace PedometerU.Tests currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); } - //userSteps = (int)(Time.time); + //userSteps = (int)(Time.time*10.0f); //barDisplay = Time.time*0.05f; barDisplay = (float)userSteps/(float)stepsGoal; + stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString(); //check if the current date matches the goal date if(prefKey == "daily" && currentDayStr == goalDayStr) @@ -243,23 +255,25 @@ namespace PedometerU.Tests //reset steps... userSteps = 0; - PlayerPrefs.SetInt("currentSteps", userSteps); + PlayerPrefs.SetInt(currentStepsKey, userSteps); } //goal complete if(barDisplay >= 1.0f) { - Debug.Log("Goal complete! +100pts!"); + Debug.Log(prefKey + "... Goal complete! +100pts!"); userSteps = 0; - PlayerPrefs.SetInt("currentSteps", userSteps); + PlayerPrefs.SetInt(currentStepsKey, userSteps); savedSteps = 0; //OnStep(0,0); stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString(); //destroy the goal and set a new one? savedPoints += stepsGoal*10; - PlayerPrefs.SetInt("totalPoints", savedPoints); - pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString (); + PlayerPrefs.SetInt(totalPointsKey, savedPoints); + pointsText.text = "Points: " + PlayerPrefs.GetInt(totalPointsKey).ToString (); + if(!PlayerPrefs.HasKey("inventory")) + PlayerPrefs.SetString("inventory", ""); //Random item StringBuilder invList = new StringBuilder (); invList.Append(PlayerPrefs.GetString ("inventory"));