Skip to content

Commit deddb13

Browse files
authored
fixed achievements that were shown more than once (#229)
1 parent ac736cb commit deddb13

File tree

4 files changed

+19
-31
lines changed

4 files changed

+19
-31
lines changed

Assets/Scripts/GameManager/GameManager.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class GameManager : MonoBehaviour
4141

4242
//Achievements
4343
[SerializeField] private GameObject achievementNotificationManagerPrefab;
44+
private HashSet<AchievementData> unlockedAchievements = new HashSet<AchievementData>();
4445

4546
//Game status
4647
private bool isPaused = false;
@@ -501,6 +502,11 @@ public async void UpdateAchievement(AchievementTitle title, int newProgress, Lis
501502
{
502503
return;
503504
}
505+
if (!unlockedAchievements.Any(achievementInListUnlockedAchievements => achievementInListUnlockedAchievements.GetTitle() == achievement.GetTitle()))
506+
{
507+
EarnAchievement(achievement);
508+
unlockedAchievements.Add(achievement);
509+
}
504510

505511
}
506512
#endif
@@ -526,7 +532,11 @@ public async void IncreaseAchievementProgress(AchievementTitle title, int increm
526532
return;
527533
}
528534

529-
EarnAchievement(achievement);
535+
if (!unlockedAchievements.Any(achievementInListUnlockedAchievements => achievementInListUnlockedAchievements.GetTitle() == achievement.GetTitle()))
536+
{
537+
EarnAchievement(achievement);
538+
unlockedAchievements.Add(achievement);
539+
}
530540
}
531541
}
532542
}

Assets/Scripts/HUD/Leaderboard/OpenLeaderboard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/// </summary>
99
public class OpenLeaderboard : MonoBehaviour
1010
{
11-
public static bool menuOpen = true;
11+
public static bool menuOpen = false;
1212
public GameObject rewardsPanel;
1313

1414
private AudioSource audioSource;

Assets/Scripts/HUD/ProgressBar.cs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using UnityEngine;
22
using UnityEngine.UI;
33
using TMPro;
4+
using System;
45

56
public class ProgressBar : MonoBehaviour
67
{
@@ -68,22 +69,13 @@ public void setUnlockedArea(int worldIndex)
6869

6970
unlockedAreaText.text = worldIndex.ToString();
7071

71-
if (worldIndex == 1)
72+
if (worldIndex == 1 || worldIndex == 2)
7273
{
73-
GameManager.Instance.UpdateAchievement(AchievementTitle.LEVEL_UP, 1, null);
74+
GameManager.Instance.UpdateAchievement(AchievementTitle.LEVEL_UP, worldIndex, null);
7475
}
75-
if (worldIndex == 2)
76+
if (worldIndex != 1)
7677
{
77-
GameManager.Instance.IncreaseAchievementProgress(AchievementTitle.OPENER_WORLD_2, 1, null);
78-
GameManager.Instance.UpdateAchievement(AchievementTitle.LEVEL_UP, 2, null);
79-
}
80-
if (worldIndex == 3)
81-
{
82-
GameManager.Instance.IncreaseAchievementProgress(AchievementTitle.OPENER_WORLD_3, 1, null);
83-
}
84-
if (worldIndex == 4)
85-
{
86-
GameManager.Instance.IncreaseAchievementProgress(AchievementTitle.OPENER_WORLD_4, 1, null);
78+
GameManager.Instance.UpdateAchievement((AchievementTitle)Enum.Parse(typeof(AchievementTitle), $"OPENER_WORLD_{worldIndex}"), 1, null);
8779
}
8880
}
8981

@@ -95,22 +87,7 @@ public void setUnlockedArea(int worldIndex)
9587
public void setUnlockedArea(int worldIndex, int dungeonIndex)
9688
{
9789
unlockedAreaText.text = worldIndex + "-" + dungeonIndex;
98-
if (worldIndex == 1)
99-
{
100-
GameManager.Instance.UpdateAchievement(AchievementTitle.MINER_WORLD_1, dungeonIndex, null);
101-
}
102-
if (worldIndex == 2)
103-
{
104-
GameManager.Instance.UpdateAchievement(AchievementTitle.MINER_WORLD_2, dungeonIndex, null);
105-
}
106-
if (worldIndex == 3)
107-
{
108-
GameManager.Instance.UpdateAchievement(AchievementTitle.MINER_WORLD_3, dungeonIndex, null);
109-
}
110-
if (worldIndex == 4)
111-
{
112-
GameManager.Instance.UpdateAchievement(AchievementTitle.MINER_WORLD_4, dungeonIndex, null);
113-
}
90+
GameManager.Instance.UpdateAchievement((AchievementTitle)Enum.Parse(typeof(AchievementTitle), $"MINER_WORLD_{worldIndex}"), 1, null);
11491
}
11592

11693
#region tutorial

Assets/Scripts/Minigame Loading/Minigame.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ private void UpdateStatus()
199199
/// </summary>
200200
private void UpdateAchievements()
201201
{
202+
successfullyCompletedMinigames = DataManager.Instance.GetAchievements().Find(achievement => achievement.GetTitle() == "MINIGAME_PROFESSIONAL").GetInteractedObjects();
202203
var key = (world,dungeon,number);
203204
if(!successfullyCompletedMinigames.Contains(key))
204205
{

0 commit comments

Comments
 (0)