Skip to content

Commit 533ec7a

Browse files
authored
Merge pull request #7 from SimonDarksideJ/dev_UWPFix
Dev uwp fix
2 parents 00b03df + 134d302 commit 533ec7a

30 files changed

+543
-586
lines changed

Assets/Fizzyo/Scripts/FizzyoFramework/FizzyoAchievements.cs

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
24
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
55
using UnityEngine;
66

77
namespace Fizzyo
@@ -12,7 +12,6 @@ namespace Fizzyo
1212
public class AllHighscoreData
1313
{
1414
public HighscoreData[] highscores;
15-
1615
}
1716

1817
// Serializable which holds individual high score data
@@ -31,7 +30,6 @@ public class AllAchievementData
3130
{
3231
public AchievementData[] achievements;
3332
public AchievementData[] unlockedAchievements;
34-
3533
}
3634

3735
// Serializable that is used to pull and hold the data of each Achievement in the Achievements.json file
@@ -63,7 +61,6 @@ public class CalibrationData
6361
/// <summary>
6462
/// Used to unlock Fizzyo achievements and post high scores in the Fizzyo rest API
6563
/// </summary>
66-
6764
public class FizzyoAchievements
6865
{
6966
/// <summary>
@@ -80,10 +77,8 @@ public class FizzyoAchievements
8077
/// </summary>
8178
public HighscoreData[] highscores;
8279

83-
84-
8580
/// <summary>
86-
/// Loads all game achievements and the users unlocked achievements and achievement progres.
81+
/// Loads all game achievements and the users unlocked achievements and achievement progress.
8782
/// </summary>
8883
/// <returns>
8984
/// A JSON formatted string containing the list of achievements
@@ -121,17 +116,15 @@ public FizzyoRequestReturnType LoadAchievements()
121116

122117

123118
return FizzyoRequestReturnType.SUCCESS;
124-
125119
}
126120

127121
internal void Load()
128122
{
129123
LoadAchievements();
130124
}
131125

132-
133126
/// <summary>
134-
/// Loads in the top 20 highscores for the current game.
127+
/// Loads in the top 20 high-scores for the current game.
135128
/// </summary>
136129
/// <returns>
137130
/// A JSON formatted string containing tag and score for the top 20 scores of the game
@@ -157,9 +150,6 @@ public FizzyoRequestReturnType GetHighscores()
157150
return FizzyoRequestReturnType.SUCCESS;
158151
}
159152

160-
161-
162-
163153
/// <summary>
164154
/// Uploads a players Score
165155
/// </summary>
@@ -200,7 +190,6 @@ public FizzyoRequestReturnType PostScore(int score)
200190
/// FizzyoRequestReturnType.SUCCESS is upload is successful.
201191
/// FizzyoRequestReturnType.FAILED_TO_CONNECT if connection failed.
202192
/// </returns>
203-
///
204193
public FizzyoRequestReturnType UnlockAchievement(string achievementId)
205194
{
206195
string unlockAchievement = "https://api.fizzyo-ucl.co.uk/api/v1/games/" + FizzyoFramework.Instance.gameID + "/achievements/" + achievementId + "/unlock" ;
@@ -221,8 +210,8 @@ public FizzyoRequestReturnType UnlockAchievement(string achievementId)
221210
if (sendPostUnlock.error != null)
222211
{
223212
return FizzyoRequestReturnType.FAILED_TO_CONNECT;
224-
//TODO add upload que here
225213
}
214+
226215
return FizzyoRequestReturnType.SUCCESS;
227216
}
228217

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

240229
if (achievementsToUpload != "")
241230
{
242-
243231
string[] achievementsToUploadArray = achievementsToUpload.Split(',');
244232

245233
for (int i = 0; i < achievementsToUploadArray.Length; i++)
246234
{
247-
248235
if (achievementsToUploadArray[i] != "")
249236
{
250-
251237
string postUnlock;
252238

253239
postUnlock = "https://api.fizzyo-ucl.co.uk/api/v1/game/" + FizzyoFramework.Instance.gameID + "/achievements/" + achievementsToUploadArray[i] + "/unlock";
@@ -270,11 +256,8 @@ private FizzyoRequestReturnType PostAchievements()
270256
{
271257
return FizzyoRequestReturnType.FAILED_TO_CONNECT;
272258
}
273-
274259
}
275-
276260
}
277-
278261
}
279262

280263
string achievementsToProgress = PlayerPrefs.GetString("achievementsToProgress");
@@ -287,40 +270,29 @@ private FizzyoRequestReturnType PostAchievements()
287270
// Add achievement progress to player preferences
288271
for (int i = 0; i < achievementsToProgressArray.Length; i++)
289272
{
290-
291273
if (achievementsToProgressArray[i] != "")
292274
{
293-
294275
for (int j = 0; j < allUserProgress.achievements.Length; j++)
295276
{
296-
297277
if (allUserProgress.achievements[j].id == achievementsToProgressArray[i])
298278
{
299279
for (int k = 0; k < allAchievements.achievements.Length; k++)
300280
{
301-
302281
if (allUserProgress.achievements[j].id == allAchievements.achievements[k].id)
303282
{
304283
allUserProgress.achievements[j].unlockProgress = allAchievements.achievements[k].unlockProgress;
305284
string newAllData = JsonUtility.ToJson(allUserProgress);
306285
PlayerPrefs.SetString(FizzyoFramework.Instance.User.UserID + "AchievementProgress", newAllData);
307286
break;
308287
}
309-
310288
}
311289

312290
break;
313291
}
314-
315292
}
316-
317293
}
318-
319294
}
320295
return FizzyoRequestReturnType.SUCCESS;
321296
}
322-
323297
}
324-
325-
}
326-
298+
}
Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using System;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
25
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
56
using UnityEngine;
67

78
namespace Fizzyo
@@ -20,7 +21,6 @@ namespace Fizzyo
2021
/// </summary>
2122
public class FizzyoAnalytics
2223
{
23-
2424
// Various session parameters
2525
public int breathCount;
2626
public int goodBreathCount;
@@ -32,18 +32,22 @@ public class FizzyoAnalytics
3232
/// <summary>
3333
/// Add this to your game to update the score to send in the session.
3434
/// </summary>
35-
public int Score {
36-
get { return _score; }
37-
set {
38-
if(value >= _score ){
39-
_score = value;
40-
}
41-
}
35+
public int Score
36+
{
37+
get { return _score; }
38+
set
39+
{
40+
if (value >= _score)
41+
{
42+
_score = value;
43+
}
44+
}
4245
}
4346

4447
private int _setCount;
48+
4549
/// <summary>
46-
/// Add this to your game to update the breathing setcount to send in the session.
50+
/// Add this to your game to update the breathing set-count to send in the session.
4751
/// </summary>
4852
public int SetCount { get { return _setCount; } set { _setCount = value; } }
4953

@@ -56,29 +60,29 @@ public int Score {
5660
/// <param name="breathCount">
5761
/// Integer holding the amount of breaths that are to be completed in each set
5862
/// </param>
59-
6063
private void Start()
6164
{
62-
//Set start time
63-
///
64-
System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
65-
startTime = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds;
65+
//Set start time
66+
///
67+
System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
68+
startTime = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds;
6669
}
70+
6771
private void OnApplicationFocus(bool focus)
6872
{
6973
if (focus)
7074
{
71-
75+
7276
}
7377
else
7478
{
75-
79+
7680
}
7781
}
78-
79-
///<summary>
80-
///Add this to the logic which manages quitting the application to Create and Post sessions.
81-
///</summary>
82+
83+
///<summary>
84+
///Add this to the logic which manages quitting the application to Create and Post sessions.
85+
///</summary>
8286
public void PostOnQuit()
8387
{
8488
Debug.Log("[FizzyoAnalytics] About to quit: creating session to upload.");
@@ -90,8 +94,7 @@ public void PostOnQuit()
9094

9195
///<summary>
9296
///Sets all the fields of the session before upload.
93-
///</summary>
94-
97+
///</summary>
9598
void CreateSession()
9699
{
97100
//All of the stats comes from the Breath Recognizer
@@ -100,27 +103,25 @@ void CreateSession()
100103
badBreathCount = FizzyoFramework.Instance.Recogniser.BadBreaths;
101104
endTime = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
102105
Debug.Log("Good breath count = " + goodBreathCount);
103-
Debug.Log("Bearth count = " + breathCount);
106+
Debug.Log("Breath count = " + breathCount);
104107
Debug.Log("Bad breath count = " + badBreathCount);
105108
Debug.Log("Highest score = " + _score);
106109
Debug.Log("Time in Unix epoch: " + endTime);
107-
108110
}
109111

110-
///<summary>
111-
///Once the game shuts down, information from the session is sent to the server.
112-
///
113-
///It will send:
114-
/// 1. Amount of sets in this session
115-
/// 2. Amounts of breaths in this session
116-
/// 3. Amount of good breaths in this session
117-
/// 4. Amount of bad breaths in this session
118-
/// 5. User-s highest score for this session
119-
/// 6. Start time of the session
120-
/// 7. End time of the session.
121-
/// Note: Time represented as Unix Epoch time.
122-
/// </summary>
123-
112+
///<summary>
113+
///Once the game shuts down, information from the session is sent to the server.
114+
///
115+
///It will send:
116+
/// 1. Amount of sets in this session
117+
/// 2. Amounts of breaths in this session
118+
/// 3. Amount of good breaths in this session
119+
/// 4. Amount of bad breaths in this session
120+
/// 5. User-s highest score for this session
121+
/// 6. Start time of the session
122+
/// 7. End time of the session.
123+
/// Note: Time represented as Unix Epoch time.
124+
/// </summary>
124125
public FizzyoRequestReturnType PostAnalytics()
125126
{
126127
///https://api.fizzyo-ucl.co.uk/api/v1/games/<id>/sessions
@@ -140,27 +141,19 @@ public FizzyoRequestReturnType PostAnalytics()
140141
headers["Authorization"] = "Bearer " + FizzyoFramework.Instance.User.AccessToken;
141142

142143
byte[] rawData = form.data;
143-
144+
144145
WWW sendPostAnalytics = new WWW(postAnalytics, rawData, headers);
145-
146+
146147
while (!sendPostAnalytics.isDone) { };
147148

148149
if (sendPostAnalytics.error != null)
149150
{
150151
Debug.Log("[FizzyoAnalytics] Posting analytics failed. ");
151152
return FizzyoRequestReturnType.FAILED_TO_CONNECT;
152-
153+
153154
}
154155
Debug.Log("[FizzyoAnalytics] Posting analytics successful.");
155156
return FizzyoRequestReturnType.SUCCESS;
156157
}
157-
158-
159-
160-
161-
}
162-
163-
164-
165158
}
166-
159+
}

0 commit comments

Comments
 (0)