76 lines
No EOL
1.9 KiB
C#
76 lines
No EOL
1.9 KiB
C#
// Assets/ShiroginSDK/Runtime/Data/ProgressionData.cs
|
||
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
namespace ShiroginSDK.Runtime.Modules.Data.Scripts
|
||
{
|
||
[Serializable]
|
||
public class LevelProgress
|
||
{
|
||
public string LevelId;
|
||
public bool Completed;
|
||
public int Stars; // 0-3 gibi
|
||
public int BestScore;
|
||
|
||
public LevelProgress(string id)
|
||
{
|
||
LevelId = id;
|
||
}
|
||
}
|
||
|
||
[Serializable]
|
||
public class ProgressionData : BaseData
|
||
{
|
||
public List<LevelProgress> Levels = new();
|
||
public List<string> Achievements = new(); // unlocked achievement id’leri
|
||
protected override string PrefsKey => "PROGRESSION_DATA";
|
||
|
||
private LevelProgress Find(string levelId)
|
||
{
|
||
return Levels.Find(l => l.LevelId == levelId) ?? AddLevel(levelId);
|
||
}
|
||
|
||
private LevelProgress AddLevel(string levelId)
|
||
{
|
||
var lp = new LevelProgress(levelId);
|
||
Levels.Add(lp);
|
||
return lp;
|
||
}
|
||
|
||
public void SetCompleted(string levelId, bool completed = true)
|
||
{
|
||
var lp = Find(levelId);
|
||
lp.Completed = completed;
|
||
Save();
|
||
}
|
||
|
||
public void SetStars(string levelId, int stars)
|
||
{
|
||
var lp = Find(levelId);
|
||
lp.Stars = Mathf.Clamp(stars, 0, 3);
|
||
Save();
|
||
}
|
||
|
||
public void SubmitScore(string levelId, int score)
|
||
{
|
||
var lp = Find(levelId);
|
||
lp.BestScore = Mathf.Max(lp.BestScore, score);
|
||
Save();
|
||
}
|
||
|
||
public bool HasAchievement(string id)
|
||
{
|
||
return Achievements.Contains(id);
|
||
}
|
||
|
||
public bool UnlockAchievement(string id)
|
||
{
|
||
if (HasAchievement(id)) return false;
|
||
Achievements.Add(id);
|
||
Save();
|
||
return true;
|
||
}
|
||
}
|
||
} |