Daily goals work now
This commit is contained in:
parent
0d74c776ef
commit
736e9c3376
1 changed files with 24 additions and 43 deletions
|
@ -78,7 +78,7 @@ namespace PedometerU.Tests
|
|||
|
||||
void Start ()
|
||||
{
|
||||
// This should later only get caleld per goal
|
||||
// This should later only get called per goal
|
||||
StartCoroutine(updateRival());
|
||||
|
||||
savedSteps = PlayerPrefs.GetInt("currentSteps");
|
||||
|
@ -96,43 +96,32 @@ namespace PedometerU.Tests
|
|||
PlayerPrefs.SetInt("totalPoints", 0);
|
||||
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;
|
||||
userPoints = savedPoints;
|
||||
|
||||
//OnStep(savedSteps, 0);
|
||||
//OnStep(savedSteps, 0); //necessary?
|
||||
Debug.Log(savedSteps);
|
||||
|
||||
|
||||
//goalText.text = prefKey;
|
||||
goalText.color = new Color(0f, 0f, 0f);
|
||||
Debug.Log(pbbg.rectTransform.anchoredPosition.x.ToString() + " " + pbbg.rectTransform.anchoredPosition.y.ToString());
|
||||
Debug.Log(pbbg.rectTransform.anchoredPosition.x.ToString() + " " + pbbg.rectTransform.anchoredPosition.y.ToString());
|
||||
|
||||
//barPos = new Vector2(pbbg.transform.position.x, 1895 - pbbg.transform.position.y);
|
||||
//barPos = new Vector2(pbbg.transform.position.x, 1895 - pbbg.transform.position.y);
|
||||
|
||||
currentDayStr = 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.
|
||||
|
@ -215,18 +204,16 @@ namespace PedometerU.Tests
|
|||
//barDisplay = Time.time*0.05f; //put actual progress here (current/total)
|
||||
barDisplay = (float)userSteps/(float)stepsGoal;
|
||||
|
||||
//failed to complete goal
|
||||
if(currentDayStr != goalDayStr)
|
||||
//check if the current date matches the goal date
|
||||
if(currentDayStr == goalDayStr)
|
||||
{
|
||||
Debug.Log(currentDayStr);
|
||||
Debug.Log(goalDayStr);
|
||||
|
||||
Debug.Log("DAY HAS PASSED!!");
|
||||
|
||||
//make it so user dismisses the goal instead!
|
||||
//Destroy(this);
|
||||
//destroy the goal and set a new one?
|
||||
|
||||
Debug.Log("current: " + currentDayStr);
|
||||
Debug.Log("goal: " + goalDayStr);
|
||||
Debug.Log("DAY HAS PASSED!! SETTING GOAL TO NEXT DAY!!");
|
||||
PlayerPrefs.SetString("goalDate",
|
||||
System.DateTime.Now.AddMinutes(1).ToString("MM/dd/yyyy"));
|
||||
goalDayStr = PlayerPrefs.GetString("goalDate");
|
||||
Debug.Log("new goal: " + goalDayStr);
|
||||
}
|
||||
//goal complete
|
||||
if(barDisplay >= 1.0f)
|
||||
|
@ -253,12 +240,6 @@ namespace PedometerU.Tests
|
|||
//only applies if "daily" goal
|
||||
if(prefKey == "daily")
|
||||
{
|
||||
if(checkNewDay(prefKey))
|
||||
{
|
||||
Debug.Log("You failed your goal"); //not true if progress is actually complete!
|
||||
goalDayStr = currentDayStr;
|
||||
savePersistantGoalDate("daily");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue