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 ()
|
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,43 +96,32 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
//goalText.text = prefKey;
|
//goalText.text = prefKey;
|
||||||
goalText.color = new Color(0f, 0f, 0f);
|
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");
|
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue