Merge branch 'andrew' into darrel

This commit is contained in:
Darrel Marek 2018-05-03 16:23:16 -05:00
commit b5c291ac44
2 changed files with 38 additions and 26 deletions

Binary file not shown.

View file

@ -60,14 +60,17 @@ namespace PedometerU.Tests
private int savedSteps; private int savedSteps;
private int savedPoints; private int savedPoints;
public string currentStepsKey;
public string totalPointsKey;
void OnStep (int steps, double distance) { void OnStep (int steps, double distance) {
//userDistance = (distance * 3.28084); //userDistance = (distance * 3.28084);
userSteps = steps + savedSteps; userSteps = steps + savedSteps;
PlayerPrefs.SetInt("currentSteps",userSteps); PlayerPrefs.SetInt(currentStepsKey,userSteps);
stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString(); stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString();
userPoints = steps*5 + savedPoints; userPoints = steps*5 + savedPoints;
PlayerPrefs.SetInt("totalPoints",userPoints); PlayerPrefs.SetInt(totalPointsKey,userPoints);
pointsText.text = "Points: " + userPoints.ToString (); pointsText.text = "Points: " + userPoints.ToString ();
} }
@ -82,30 +85,38 @@ namespace PedometerU.Tests
void Start () void Start ()
{ {
//PlayerPrefs.DeleteAll(); //danger!!
if(prefKey == "daily") if(prefKey == "daily")
{ {
// This should later only get called per goal // This should later only get called per goal
StartCoroutine(updateRival()); StartCoroutine(updateRival());
currentStepsKey = "currentSteps";
totalPointsKey = "totalPoints";
}
else
{
currentStepsKey = "currentSteps_p";
totalPointsKey = "totalPoints_p";
} }
savedSteps = PlayerPrefs.GetInt("currentSteps"); savedSteps = PlayerPrefs.GetInt(currentStepsKey);
savedPoints = PlayerPrefs.GetInt("totalPoints"); savedPoints = PlayerPrefs.GetInt(totalPointsKey);
// Create a new pedometer // Create a new pedometer
pedometer = new Pedometer(OnStep); pedometer = new Pedometer(OnStep);
// Reset UI // Reset UI
stepText.text = savedSteps.ToString () + "/" + stepsGoal.ToString(); stepText.text = savedSteps.ToString () + "/" + stepsGoal.ToString();
if(prefKey == "daily") if(PlayerPrefs.HasKey(totalPointsKey))
if(PlayerPrefs.HasKey("totalPoints")) {
{ pointsText.text = "Points: " + PlayerPrefs.GetInt(totalPointsKey).ToString ();
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString (); }
} else
else {
{ PlayerPrefs.SetInt(totalPointsKey, 0);
PlayerPrefs.SetInt("totalPoints", 0); pointsText.text = "Points: " + PlayerPrefs.GetInt(totalPointsKey).ToString ();
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString (); }
}
if(prefKey == "daily")
{ {
if(PlayerPrefs.HasKey("goalDate")) if(PlayerPrefs.HasKey("goalDate"))
{ {
@ -123,9 +134,9 @@ namespace PedometerU.Tests
userPoints = savedPoints; userPoints = savedPoints;
//OnStep(savedSteps, 0); //necessary? //OnStep(savedSteps, 0); //necessary?
Debug.Log(savedSteps); //Debug.Log(savedSteps);
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);
@ -216,8 +227,7 @@ namespace PedometerU.Tests
{ {
updateTimeRemaining (); updateTimeRemaining ();
updateProgressBar (); updateProgressBar ();
//updateMyGoalProgressBar ();
updateMyGoalProgressBar ();
if(prefKey == "daily") if(prefKey == "daily")
{ {
@ -226,9 +236,10 @@ namespace PedometerU.Tests
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
} }
//userSteps = (int)(Time.time); //userSteps = (int)(Time.time*10.0f);
//barDisplay = Time.time*0.05f; //barDisplay = Time.time*0.05f;
barDisplay = (float)userSteps/(float)stepsGoal; barDisplay = (float)userSteps/(float)stepsGoal;
stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString();
//check if the current date matches the goal date //check if the current date matches the goal date
if(prefKey == "daily" && currentDayStr == goalDayStr) if(prefKey == "daily" && currentDayStr == goalDayStr)
@ -243,24 +254,25 @@ namespace PedometerU.Tests
//reset steps... //reset steps...
userSteps = 0; userSteps = 0;
PlayerPrefs.SetInt("currentSteps", userSteps); PlayerPrefs.SetInt(currentStepsKey, userSteps);
} }
//goal complete //goal complete
if(barDisplay >= 1.0f) else if(barDisplay >= 1.0f)
{ {
Debug.Log("Goal complete! +100pts!"); Debug.Log(prefKey + "... Goal complete! +100pts!");
userSteps = 0; userSteps = 0;
PlayerPrefs.SetInt("currentSteps", userSteps); PlayerPrefs.SetInt(currentStepsKey, userSteps);
savedSteps = 0; savedSteps = 0;
//OnStep(0,0); //OnStep(0,0);
stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString();
//destroy the goal and set a new one? //destroy the goal and set a new one?
savedPoints += stepsGoal*10; savedPoints += stepsGoal*10;
PlayerPrefs.SetInt("totalPoints", savedPoints); PlayerPrefs.SetInt(totalPointsKey, savedPoints);
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString (); pointsText.text = "Points: " + PlayerPrefs.GetInt(totalPointsKey).ToString ();
//Random item //Random item
if(!PlayerPrefs.HasKey("inventory"))
PlayerPrefs.SetString("inventory", "");
StringBuilder invList = new StringBuilder (); StringBuilder invList = new StringBuilder ();
invList.Append(PlayerPrefs.GetString ("inventory")); invList.Append(PlayerPrefs.GetString ("inventory"));
invList.Append(items[(int)Math.Round(UnityEngine.Random.value*6.0f)]).Append(" "); invList.Append(items[(int)Math.Round(UnityEngine.Random.value*6.0f)]).Append(" ");