[Fix] Code visual
This commit is contained in:
@@ -3,20 +3,19 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YachtDice.Persistence
|
||||
{
|
||||
[Serializable]
|
||||
public sealed class SaveData
|
||||
{
|
||||
public int Version = 1;
|
||||
public int Currency;
|
||||
public List<ModifierSaveEntry> OwnedModifiers = new();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class SaveData
|
||||
{
|
||||
public int Version = 1;
|
||||
public int Currency;
|
||||
public List<ModifierSaveEntry> OwnedModifiers = new();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class ModifierSaveEntry
|
||||
{
|
||||
public string ModifierId;
|
||||
public bool IsActive;
|
||||
public int RemainingUses;
|
||||
}
|
||||
[Serializable]
|
||||
public sealed class ModifierSaveEntry
|
||||
{
|
||||
public string ModifierId;
|
||||
public bool IsActive;
|
||||
public int RemainingUses;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,44 +3,43 @@ using UnityEngine;
|
||||
|
||||
namespace YachtDice.Persistence
|
||||
{
|
||||
|
||||
public static class SaveSystem
|
||||
{
|
||||
private const string SaveKey = "YachtDice_SaveData";
|
||||
|
||||
public static void Save(SaveData data)
|
||||
public static class SaveSystem
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(data, Formatting.Indented);
|
||||
PlayerPrefs.SetString(SaveKey, json);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
private const string SaveKey = "YachtDice_SaveData";
|
||||
|
||||
public static SaveData Load()
|
||||
{
|
||||
if (!PlayerPrefs.HasKey(SaveKey))
|
||||
return new SaveData();
|
||||
|
||||
string json = PlayerPrefs.GetString(SaveKey);
|
||||
|
||||
try
|
||||
public static void Save(SaveData data)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<SaveData>(json) ?? new SaveData();
|
||||
string json = JsonConvert.SerializeObject(data, Formatting.Indented);
|
||||
PlayerPrefs.SetString(SaveKey, json);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
catch (JsonException e)
|
||||
|
||||
public static SaveData Load()
|
||||
{
|
||||
Debug.LogWarning($"Failed to deserialize save data, returning default: {e.Message}");
|
||||
return new SaveData();
|
||||
if (!PlayerPrefs.HasKey(SaveKey))
|
||||
return new SaveData();
|
||||
|
||||
string json = PlayerPrefs.GetString(SaveKey);
|
||||
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<SaveData>(json) ?? new SaveData();
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
Debug.LogWarning($"Failed to deserialize save data, returning default: {e.Message}");
|
||||
return new SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Delete()
|
||||
{
|
||||
PlayerPrefs.DeleteKey(SaveKey);
|
||||
}
|
||||
|
||||
public static bool HasSave()
|
||||
{
|
||||
return PlayerPrefs.HasKey(SaveKey);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Delete()
|
||||
{
|
||||
PlayerPrefs.DeleteKey(SaveKey);
|
||||
}
|
||||
|
||||
public static bool HasSave()
|
||||
{
|
||||
return PlayerPrefs.HasKey(SaveKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user