refactor (#6)
Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
73
scripts/State/PlayerState.cs
Normal file
73
scripts/State/PlayerState.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.Collections.Generic;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.State;
|
||||
|
||||
/// <summary>
|
||||
/// Persistent player data that survives across sessions.
|
||||
/// This is a POCO (Plain Old C# Object) for predictable state management.
|
||||
/// </summary>
|
||||
public class PlayerState
|
||||
{
|
||||
/// <summary>
|
||||
/// Saved coins (not including current session).
|
||||
/// </summary>
|
||||
public int Coins { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Remaining lives.
|
||||
/// </summary>
|
||||
public int Lives { get; set; } = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Indices of completed levels.
|
||||
/// </summary>
|
||||
public List<int> CompletedLevels { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Indices of levels the player can access.
|
||||
/// </summary>
|
||||
public List<int> UnlockedLevels { get; set; } = new() { 0 };
|
||||
|
||||
/// <summary>
|
||||
/// Skills the player has permanently unlocked.
|
||||
/// </summary>
|
||||
public List<SkillData> UnlockedSkills { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Statistics dictionary for tracking game stats.
|
||||
/// </summary>
|
||||
public Dictionary<string, int> Statistics { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// IDs of unlocked achievements.
|
||||
/// </summary>
|
||||
public List<string> UnlockedAchievements { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a fresh default player state.
|
||||
/// </summary>
|
||||
public static PlayerState CreateDefault() => new()
|
||||
{
|
||||
Coins = 0,
|
||||
Lives = 3,
|
||||
CompletedLevels = new List<int>(),
|
||||
UnlockedLevels = new List<int> { 0 },
|
||||
UnlockedSkills = new List<SkillData>(),
|
||||
Statistics = new Dictionary<string, int>()
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Resets this state to default values.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
Coins = 0;
|
||||
Lives = 3;
|
||||
CompletedLevels.Clear();
|
||||
UnlockedLevels.Clear();
|
||||
UnlockedLevels.Add(0);
|
||||
UnlockedSkills.Clear();
|
||||
Statistics.Clear();
|
||||
}
|
||||
}
|
||||
1
scripts/State/PlayerState.cs.uid
Normal file
1
scripts/State/PlayerState.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://gtr1e60jq7iv
|
||||
55
scripts/State/SessionState.cs
Normal file
55
scripts/State/SessionState.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Collections.Generic;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.State;
|
||||
|
||||
/// <summary>
|
||||
/// Data for the current gameplay session.
|
||||
/// Reset when player dies or completes a level.
|
||||
/// </summary>
|
||||
public class SessionState
|
||||
{
|
||||
/// <summary>
|
||||
/// Current level index being played.
|
||||
/// </summary>
|
||||
public int CurrentLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Coins collected during this session (not yet saved).
|
||||
/// </summary>
|
||||
public int CoinsCollected { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Skills unlocked during this session (not yet saved).
|
||||
/// </summary>
|
||||
public List<SkillData> SkillsUnlocked { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a fresh session state.
|
||||
/// </summary>
|
||||
public static SessionState CreateDefault() => new()
|
||||
{
|
||||
CurrentLevel = 0,
|
||||
CoinsCollected = 0,
|
||||
SkillsUnlocked = new List<SkillData>()
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Resets session state to defaults.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
CoinsCollected = 0;
|
||||
SkillsUnlocked.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets completely including level.
|
||||
/// </summary>
|
||||
public void ResetAll()
|
||||
{
|
||||
CurrentLevel = 0;
|
||||
CoinsCollected = 0;
|
||||
SkillsUnlocked.Clear();
|
||||
}
|
||||
}
|
||||
1
scripts/State/SessionState.cs.uid
Normal file
1
scripts/State/SessionState.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://chqsdleqrnl7b
|
||||
Reference in New Issue
Block a user