init: add project

This commit is contained in:
Bragin Stepan
2026-02-18 23:02:28 +05:00
commit 4f01e66894
620 changed files with 52253 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7fcee5516f2549bfbbf7d525c6e60d84
timeCreated: 1770822079

View File

@@ -0,0 +1,10 @@
using System.Collections.Generic;
using _Project.Develop.Runtime.Logic.Meta.Features.Wallet;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement
{
public class PlayerData : ISaveData
{
public Dictionary<CurrencyTypes, int> WalletData;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6fdb888a39a0dc548b3149ae88dcf261
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using _Project.Develop.Runtime.Configs.Meta;
using _Project.Develop.Runtime.Logic.Meta.Features.Wallet;
using Assets._Project.Develop.Runtime.Utilities.ConfigsManagement;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders
{
public class PlayerDataProvider : DataProvider<PlayerData>
{
private readonly ConfigsProviderService _configsProviderService;
public PlayerDataProvider(
ISaveLoadService saveLoadService,
ConfigsProviderService configsProviderService) : base(saveLoadService)
{
_configsProviderService = configsProviderService;
}
protected override PlayerData GetOriginData()
{
return new PlayerData()
{
WalletData = InitWalletData(),
};
}
private Dictionary<CurrencyTypes, int> InitWalletData()
{
Dictionary<CurrencyTypes, int> data = new();
StartWalletConfigSO config = _configsProviderService.GetConfig<StartWalletConfigSO>();
foreach (CurrencyTypes type in Enum.GetValues(typeof(CurrencyTypes)))
data[type] = config.GetValueFor(type);
return data;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8a9ea5d989647a4081ab2b6b076f1e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using System.Collections;
using Assets._Project.Develop.Runtime.Utilities.DataManagement;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders;
using UnityEngine;
namespace _Project.Develop.Runtime.Utilities.DataManagement
{
public static class DataUtils
{
public static IEnumerator LoadProviderAsync<T>(DataProvider<T> data) where T : ISaveData
{
bool isDataSaveExists = false;
yield return data.ExistsAsync(result => isDataSaveExists = result);
if (isDataSaveExists)
{
yield return data.LoadAsync();
Debug.Log($"Data {typeof(T).Name} loaded");
}
else
{
data.Reset();
yield return data.SaveAsync();
Debug.Log($"Data {typeof(T).Name} created");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1596051f07de4e36aab6dd2f1f0c8cd4
timeCreated: 1770825076

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b95729626d4a4da8b10a288862b4b647
timeCreated: 1770822430

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0dfabea6753040bb886e08bc12f31679
timeCreated: 1770822024

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bb5d55999e8cd9947b831a8be3baf413
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders
{
public abstract class DataProvider<TData> where TData : ISaveData
{
private readonly ISaveLoadService _saveLoadService;
private readonly List<IDataWriter<TData>> _writers = new();
private readonly List<IDataReader<TData>> _readers = new();
private TData _data;
protected DataProvider(ISaveLoadService saveLoadService)
{
_saveLoadService = saveLoadService;
}
public void RegisterWriter(IDataWriter<TData> writer)
{
if (_writers.Contains(writer))
throw new ArgumentException(nameof(writer));
_writers.Add(writer);
}
public void RegisterReader(IDataReader<TData> reader)
{
if (_readers.Contains(reader))
throw new ArgumentException(nameof(reader));
_readers.Add(reader);
}
public IEnumerator LoadAsync()
{
yield return _saveLoadService.Load<TData>(loadedData => _data = loadedData);
SendDataToReaders();
}
public IEnumerator SaveAsync()
{
UpdateDataFromWriters();
yield return _saveLoadService.Save(_data);
}
public IEnumerator ExistsAsync(Action<bool> onExistsResult)
{
yield return _saveLoadService.Exists<TData>(result => onExistsResult?.Invoke(result));
}
public void Reset()
{
_data = GetOriginData();
SendDataToReaders();
}
protected abstract TData GetOriginData();
private void SendDataToReaders()
{
foreach (IDataReader<TData> reader in _readers)
reader.ReadFrom(_data);
}
private void UpdateDataFromWriters()
{
foreach (IDataWriter<TData> writer in _writers)
writer.WriteTo(_data);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c6bf35dfa43cf024896bd6a93d0ef7d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders
{
public interface IDataReader<TData> where TData : ISaveData
{
void ReadFrom(TData data);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5635fd8b8a4db3247a083a80b115ff1c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders
{
public interface IDataWriter<TData> where TData : ISaveData
{
void WriteTo(TData data);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0c199eaeb90195b46b7ef35e77d2fc98
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ee31fbd4ba77de44ab91963e139c0c0e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataRepository
{
public interface IDataRepository
{
IEnumerator Read(string key, Action<string> onRead);
IEnumerator Write(string key, string serializedData);
IEnumerator Remove(string key);
IEnumerator Exists(string key, Action<bool> onExistsResult);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 44db3bd62a6844b438133918ce7520bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections;
using System.IO;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataRepository
{
public class LocalFileDataRepository : IDataRepository
{
private readonly string _folderPath;
private readonly string _saveFileExtension;
public LocalFileDataRepository(string folderPath, string saveFileExtension)
{
_folderPath = folderPath;
_saveFileExtension = saveFileExtension;
}
public IEnumerator Exists(string key, Action<bool> onExistsResult)
{
bool exists = File.Exists(FullPathFor(key));
onExistsResult?.Invoke(exists);
yield break;
}
public IEnumerator Read(string key, Action<string> onRead)
{
string text = File.ReadAllText(FullPathFor(key));
onRead?.Invoke(text);
yield break;
}
public IEnumerator Remove(string key)
{
File.Delete(FullPathFor(key));
yield break;
}
public IEnumerator Write(string key, string serializedData)
{
File.WriteAllText(FullPathFor(key), serializedData);
yield break;
}
private string FullPathFor(string key)
=> Path.Combine(_folderPath, key) + "." + _saveFileExtension;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1237330c119d323409a240bc05147dbb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections;
using UnityEngine;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataRepository
{
public class PlayerPrefsDataRepository : IDataRepository
{
public IEnumerator Exists(string key, Action<bool> onExistsResult)
{
bool exists = PlayerPrefs.HasKey(key);
onExistsResult?.Invoke(exists);
yield break;
}
public IEnumerator Read(string key, Action<string> onRead)
{
string text = PlayerPrefs.GetString(key);
onRead?.Invoke(text);
yield break;
}
public IEnumerator Remove(string key)
{
PlayerPrefs.DeleteKey(key);
yield break;
}
public IEnumerator Write(string key, string serializedData)
{
PlayerPrefs.SetString(key, serializedData);
yield break;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: adaa5e6dabd0ddc478a6c91a3f53645f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,6 @@
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement
{
public interface ISaveData
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94f8ecdf9df3d1549ae149d55a4d6654
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement
{
public interface ISaveLoadService
{
IEnumerator Load<TData>(Action<TData> onLoad) where TData : ISaveData;
IEnumerator Save<TData>(TData data) where TData : ISaveData;
IEnumerator Remove<TData>() where TData : ISaveData;
IEnumerator Exists<TData>(Action<bool> onExistsResult) where TData : ISaveData;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 307c92b53612c4c41845657f42d815d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6904ab4492a5aa242941e836a86fc46f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.KeysStorage
{
public interface IDataKeysStorage
{
string GetKeyFor<TData>() where TData : ISaveData;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 10eac07c628f6fc47b2a2965442dedd6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.KeysStorage
{
public class MapDataKeysStorage : IDataKeysStorage
{
private readonly Dictionary<Type, string> Keys = new (MapDataKeys.Dictionary);
public string GetKeyFor<TData>() where TData : ISaveData => Keys[typeof(TData)];
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ee6312a9f3693d4bbb60ffd58b21db7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2a7a36b7945f6484c9df1a4567fb9d67
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.Serializers
{
public interface IDataSerializer
{
string Serialize<TData>(TData data);
TData Deserialize<TData>(string serializedData);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 68c37667edb0fba42ba8ea048933f424
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
using Newtonsoft.Json;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.Serializers
{
public class JsonSerializer : IDataSerializer
{
public TData Deserialize<TData>(string serializedData)
{
return JsonConvert.DeserializeObject<TData>(serializedData, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
});
}
public string Serialize<TData>(TData data)
{
return JsonConvert.SerializeObject(data, new JsonSerializerSettings
{
Formatting = Formatting.Indented,
TypeNameHandling = TypeNameHandling.Auto,
});
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2f381e1811dfe344a6c25d6d1205239
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using Assets._Project.Develop.Runtime.Utilities.DataManagement.DataRepository;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.KeysStorage;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.Serializers;
using UnityEngine;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement
{
public class SaveLoadFactory
{
public SaveLoadService CreateDefaultSaveLoad()
{
IDataRepository dataRepository;
if(RuntimePlatform.WebGLPlayer == Application.platform)
{
dataRepository = new PlayerPrefsDataRepository();
}
else
{
string saveFolderPath =
$"{(Application.isEditor ? Application.dataPath : Application.persistentDataPath)}/Saves";
dataRepository = new LocalFileDataRepository(saveFolderPath, "json");
}
return new SaveLoadService(new JsonSerializer(), new MapDataKeysStorage(), dataRepository);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3890ea90607b48308fbb899dec13672b
timeCreated: 1770823825

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.DataRepository;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.KeysStorage;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.Serializers;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement
{
public class SaveLoadService : ISaveLoadService
{
private readonly IDataSerializer _serializer;
private readonly IDataKeysStorage _keysStorage;
private readonly IDataRepository _repository;
public SaveLoadService(
IDataSerializer serializer,
IDataKeysStorage keysStorage,
IDataRepository repository)
{
_serializer = serializer;
_keysStorage = keysStorage;
_repository = repository;
}
public IEnumerator Exists<TData>(Action<bool> onExistsResult) where TData : ISaveData
{
string key = _keysStorage.GetKeyFor<TData>();
yield return _repository.Exists(key, result => onExistsResult?.Invoke(result));
}
public IEnumerator Load<TData>(Action<TData> onLoad) where TData : ISaveData
{
string key = _keysStorage.GetKeyFor<TData>();
string serializedData = "";
yield return _repository.Read(key, result => serializedData = result);
TData data = _serializer.Deserialize<TData>(serializedData);
onLoad?.Invoke(data);
}
public IEnumerator Remove<TData>() where TData : ISaveData
{
string key = _keysStorage.GetKeyFor<TData>();
yield return _repository.Remove(key);
}
public IEnumerator Save<TData>(TData data) where TData : ISaveData
{
string serializedData = _serializer.Serialize(data);
string key = _keysStorage.GetKeyFor<TData>();
yield return _repository.Write(key, serializedData);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6e65636005d26054dba538573f23a2b4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: