Skip to content

Commit

Permalink
Merge pull request #7 from SimonDarksideJ/dev_UWPFix
Browse files Browse the repository at this point in the history
Dev uwp fix
  • Loading branch information
leestott authored Oct 19, 2018
2 parents 00b03df + 134d302 commit 533ec7a
Show file tree
Hide file tree
Showing 30 changed files with 543 additions and 586 deletions.
42 changes: 7 additions & 35 deletions Assets/Fizzyo/Scripts/FizzyoFramework/FizzyoAchievements.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Fizzyo
Expand All @@ -12,7 +12,6 @@ namespace Fizzyo
public class AllHighscoreData
{
public HighscoreData[] highscores;

}

// Serializable which holds individual high score data
Expand All @@ -31,7 +30,6 @@ public class AllAchievementData
{
public AchievementData[] achievements;
public AchievementData[] unlockedAchievements;

}

// Serializable that is used to pull and hold the data of each Achievement in the Achievements.json file
Expand Down Expand Up @@ -63,7 +61,6 @@ public class CalibrationData
/// <summary>
/// Used to unlock Fizzyo achievements and post high scores in the Fizzyo rest API
/// </summary>

public class FizzyoAchievements
{
/// <summary>
Expand All @@ -80,10 +77,8 @@ public class FizzyoAchievements
/// </summary>
public HighscoreData[] highscores;



/// <summary>
/// Loads all game achievements and the users unlocked achievements and achievement progres.
/// Loads all game achievements and the users unlocked achievements and achievement progress.
/// </summary>
/// <returns>
/// A JSON formatted string containing the list of achievements
Expand Down Expand Up @@ -121,17 +116,15 @@ public FizzyoRequestReturnType LoadAchievements()


return FizzyoRequestReturnType.SUCCESS;

}

internal void Load()
{
LoadAchievements();
}


/// <summary>
/// Loads in the top 20 highscores for the current game.
/// Loads in the top 20 high-scores for the current game.
/// </summary>
/// <returns>
/// A JSON formatted string containing tag and score for the top 20 scores of the game
Expand All @@ -157,9 +150,6 @@ public FizzyoRequestReturnType GetHighscores()
return FizzyoRequestReturnType.SUCCESS;
}




/// <summary>
/// Uploads a players Score
/// </summary>
Expand Down Expand Up @@ -200,7 +190,6 @@ public FizzyoRequestReturnType PostScore(int score)
/// FizzyoRequestReturnType.SUCCESS is upload is successful.
/// FizzyoRequestReturnType.FAILED_TO_CONNECT if connection failed.
/// </returns>
///
public FizzyoRequestReturnType UnlockAchievement(string achievementId)
{
string unlockAchievement = "https://api.fizzyo-ucl.co.uk/api/v1/games/" + FizzyoFramework.Instance.gameID + "/achievements/" + achievementId + "/unlock" ;
Expand All @@ -221,8 +210,8 @@ public FizzyoRequestReturnType UnlockAchievement(string achievementId)
if (sendPostUnlock.error != null)
{
return FizzyoRequestReturnType.FAILED_TO_CONNECT;
//TODO add upload que here
}

return FizzyoRequestReturnType.SUCCESS;
}

Expand All @@ -239,15 +228,12 @@ private FizzyoRequestReturnType PostAchievements()

if (achievementsToUpload != "")
{

string[] achievementsToUploadArray = achievementsToUpload.Split(',');

for (int i = 0; i < achievementsToUploadArray.Length; i++)
{

if (achievementsToUploadArray[i] != "")
{

string postUnlock;

postUnlock = "https://api.fizzyo-ucl.co.uk/api/v1/game/" + FizzyoFramework.Instance.gameID + "/achievements/" + achievementsToUploadArray[i] + "/unlock";
Expand All @@ -270,11 +256,8 @@ private FizzyoRequestReturnType PostAchievements()
{
return FizzyoRequestReturnType.FAILED_TO_CONNECT;
}

}

}

}

string achievementsToProgress = PlayerPrefs.GetString("achievementsToProgress");
Expand All @@ -287,40 +270,29 @@ private FizzyoRequestReturnType PostAchievements()
// Add achievement progress to player preferences
for (int i = 0; i < achievementsToProgressArray.Length; i++)
{

if (achievementsToProgressArray[i] != "")
{

for (int j = 0; j < allUserProgress.achievements.Length; j++)
{

if (allUserProgress.achievements[j].id == achievementsToProgressArray[i])
{
for (int k = 0; k < allAchievements.achievements.Length; k++)
{

if (allUserProgress.achievements[j].id == allAchievements.achievements[k].id)
{
allUserProgress.achievements[j].unlockProgress = allAchievements.achievements[k].unlockProgress;
string newAllData = JsonUtility.ToJson(allUserProgress);
PlayerPrefs.SetString(FizzyoFramework.Instance.User.UserID + "AchievementProgress", newAllData);
break;
}

}

break;
}

}

}

}
return FizzyoRequestReturnType.SUCCESS;
}

}

}

}
99 changes: 46 additions & 53 deletions Assets/Fizzyo/Scripts/FizzyoFramework/FizzyoAnalytics.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Fizzyo
Expand All @@ -20,7 +21,6 @@ namespace Fizzyo
/// </summary>
public class FizzyoAnalytics
{

// Various session parameters
public int breathCount;
public int goodBreathCount;
Expand All @@ -32,18 +32,22 @@ public class FizzyoAnalytics
/// <summary>
/// Add this to your game to update the score to send in the session.
/// </summary>
public int Score {
get { return _score; }
set {
if(value >= _score ){
_score = value;
}
}
public int Score
{
get { return _score; }
set
{
if (value >= _score)
{
_score = value;
}
}
}

private int _setCount;

/// <summary>
/// Add this to your game to update the breathing setcount to send in the session.
/// Add this to your game to update the breathing set-count to send in the session.
/// </summary>
public int SetCount { get { return _setCount; } set { _setCount = value; } }

Expand All @@ -56,29 +60,29 @@ public int Score {
/// <param name="breathCount">
/// Integer holding the amount of breaths that are to be completed in each set
/// </param>

private void Start()
{
//Set start time
///
System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
startTime = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds;
//Set start time
///
System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
startTime = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds;
}

private void OnApplicationFocus(bool focus)
{
if (focus)
{

}
else
{

}
}
///<summary>
///Add this to the logic which manages quitting the application to Create and Post sessions.
///</summary>

///<summary>
///Add this to the logic which manages quitting the application to Create and Post sessions.
///</summary>
public void PostOnQuit()
{
Debug.Log("[FizzyoAnalytics] About to quit: creating session to upload.");
Expand All @@ -90,8 +94,7 @@ public void PostOnQuit()

///<summary>
///Sets all the fields of the session before upload.
///</summary>

///</summary>
void CreateSession()
{
//All of the stats comes from the Breath Recognizer
Expand All @@ -100,27 +103,25 @@ void CreateSession()
badBreathCount = FizzyoFramework.Instance.Recogniser.BadBreaths;
endTime = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
Debug.Log("Good breath count = " + goodBreathCount);
Debug.Log("Bearth count = " + breathCount);
Debug.Log("Breath count = " + breathCount);
Debug.Log("Bad breath count = " + badBreathCount);
Debug.Log("Highest score = " + _score);
Debug.Log("Time in Unix epoch: " + endTime);

}

///<summary>
///Once the game shuts down, information from the session is sent to the server.
///
///It will send:
/// 1. Amount of sets in this session
/// 2. Amounts of breaths in this session
/// 3. Amount of good breaths in this session
/// 4. Amount of bad breaths in this session
/// 5. User-s highest score for this session
/// 6. Start time of the session
/// 7. End time of the session.
/// Note: Time represented as Unix Epoch time.
/// </summary>

///<summary>
///Once the game shuts down, information from the session is sent to the server.
///
///It will send:
/// 1. Amount of sets in this session
/// 2. Amounts of breaths in this session
/// 3. Amount of good breaths in this session
/// 4. Amount of bad breaths in this session
/// 5. User-s highest score for this session
/// 6. Start time of the session
/// 7. End time of the session.
/// Note: Time represented as Unix Epoch time.
/// </summary>
public FizzyoRequestReturnType PostAnalytics()
{
///https://api.fizzyo-ucl.co.uk/api/v1/games/<id>/sessions
Expand All @@ -140,27 +141,19 @@ public FizzyoRequestReturnType PostAnalytics()
headers["Authorization"] = "Bearer " + FizzyoFramework.Instance.User.AccessToken;

byte[] rawData = form.data;

WWW sendPostAnalytics = new WWW(postAnalytics, rawData, headers);

while (!sendPostAnalytics.isDone) { };

if (sendPostAnalytics.error != null)
{
Debug.Log("[FizzyoAnalytics] Posting analytics failed. ");
return FizzyoRequestReturnType.FAILED_TO_CONNECT;

}
Debug.Log("[FizzyoAnalytics] Posting analytics successful.");
return FizzyoRequestReturnType.SUCCESS;
}




}



}
}
Loading

0 comments on commit 533ec7a

Please sign in to comment.