Daily goals work now

This commit is contained in:
asleal2 2018-04-30 17:08:14 -05:00
parent 0d74c776ef
commit 736e9c3376

View file

@ -78,7 +78,7 @@ namespace PedometerU.Tests
void Start () void Start ()
{ {
// This should later only get caleld per goal // This should later only get called per goal
StartCoroutine(updateRival()); StartCoroutine(updateRival());
savedSteps = PlayerPrefs.GetInt("currentSteps"); savedSteps = PlayerPrefs.GetInt("currentSteps");
@ -96,10 +96,21 @@ namespace PedometerU.Tests
PlayerPrefs.SetInt("totalPoints", 0); PlayerPrefs.SetInt("totalPoints", 0);
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString (); pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString ();
} }
if(PlayerPrefs.HasKey("goalDate"))
{
goalDayStr = PlayerPrefs.GetString("goalDate");
}
else
{
PlayerPrefs.SetString("goalDate",
System.DateTime.Now.AddMinutes(1).ToString("MM/dd/yyyy"));
goalDayStr = PlayerPrefs.GetString("goalDate");
}
userSteps = savedSteps; userSteps = savedSteps;
userPoints = savedPoints; userPoints = savedPoints;
//OnStep(savedSteps, 0); //OnStep(savedSteps, 0); //necessary?
Debug.Log(savedSteps); Debug.Log(savedSteps);
@ -111,28 +122,6 @@ namespace PedometerU.Tests
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
Debug.Log(goalDayStr);
if(prefKey == "daily")
savePersistantGoalDate("daily");
}
//on a button press? begin a goal?
void startGoal()
{
}
void savePersistantGoalDate(string key)
{
PlayerPrefs.SetString(key, goalDayStr);
}
bool checkNewDay(string key)
{
string checkDay = PlayerPrefs.GetString(key);
if(checkDay == currentDayStr)
return false;
return true;
} }
// Was used for testing. // Was used for testing.
@ -215,18 +204,16 @@ namespace PedometerU.Tests
//barDisplay = Time.time*0.05f; //put actual progress here (current/total) //barDisplay = Time.time*0.05f; //put actual progress here (current/total)
barDisplay = (float)userSteps/(float)stepsGoal; barDisplay = (float)userSteps/(float)stepsGoal;
//failed to complete goal //check if the current date matches the goal date
if(currentDayStr != goalDayStr) if(currentDayStr == goalDayStr)
{ {
Debug.Log(currentDayStr); Debug.Log("current: " + currentDayStr);
Debug.Log(goalDayStr); Debug.Log("goal: " + goalDayStr);
Debug.Log("DAY HAS PASSED!! SETTING GOAL TO NEXT DAY!!");
Debug.Log("DAY HAS PASSED!!"); PlayerPrefs.SetString("goalDate",
System.DateTime.Now.AddMinutes(1).ToString("MM/dd/yyyy"));
//make it so user dismisses the goal instead! goalDayStr = PlayerPrefs.GetString("goalDate");
//Destroy(this); Debug.Log("new goal: " + goalDayStr);
//destroy the goal and set a new one?
} }
//goal complete //goal complete
if(barDisplay >= 1.0f) if(barDisplay >= 1.0f)
@ -253,12 +240,6 @@ namespace PedometerU.Tests
//only applies if "daily" goal //only applies if "daily" goal
if(prefKey == "daily") if(prefKey == "daily")
{ {
if(checkNewDay(prefKey))
{
Debug.Log("You failed your goal"); //not true if progress is actually complete!
goalDayStr = currentDayStr;
savePersistantGoalDate("daily");
}
} }
} }
} }