// // /*===============================================================================
// // Copyright (C) 2024 PhantomsXR Ltd. All Rights Reserved.
// //
// // This file is part of the Assembly-CSharp.
// //
// // The Nin1 cannot be copied, distributed, or made available to
// // third-parties for commercial purposes without written permission of PhantomsXR Ltd.
// //
// // Contact nswell@phantomsxr.com for licensing requests.
// // ===============================================================================*/
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.Services.CloudSave.Models;
using UnityEngine.Assertions;
namespace Phantom.XRMOD.GameServices.Runtime
{
///
/// Manages the Cloud Save system.
/// Provides methods to save and load player data to/from the cloud.
///
public class CloudSaveSystemManager : ICloudSaveGameData, IDeleteData
{
private static CloudSaveSystemManager _INSTANCE;
///
/// Singleton instance of CloudSaveSystemManager.
///
public static CloudSaveSystemManager GetInstance => _INSTANCE ??= new CloudSaveSystemManager();
private ICloudSaveGameData iCloudSaveGameDataProvider;
private IDeleteData iDeleteDataProvider;
private CloudSaveSystemManager()
{
#if USE_UNITY_CLOUD_SAVE
var tmp_Provider = new UnityCloudSavePlayerDataGameDataProvider();
iDeleteDataProvider = tmp_Provider;
iCloudSaveGameDataProvider = tmp_Provider;
#endif
Assert.IsNotNull(iCloudSaveGameDataProvider);
Assert.IsNotNull(iDeleteDataProvider);
}
///
/// Saves player data to the cloud.
///
/// A dictionary of key-value pairs to save.
/// A Task representing the save operation, returning true if successful.
///
///
/// var data = new Dictionary<string, object> { { "Level", 10 } };
/// await CloudSaveSystemManager.GetInstance.SavePlayerData(data);
///
///
public async Task SavePlayerData(Dictionary _saveData)
{
return await iCloudSaveGameDataProvider.SavePlayerData(_saveData);
}
///
/// Loads player data from the cloud using the specified keys.
///
/// A set of keys to load.
/// A Task representing the load operation, returning a dictionary of items.
public async Task> LoadPlayerData(HashSet _keys)
{
return await iCloudSaveGameDataProvider.LoadPlayerData(_keys);
}
///
/// Deletes player data associated with the specified key.
///
/// The key to delete.
public void DeletePlayerData(string _key)
{
iDeleteDataProvider?.DeletePlayerData(_key);
}
}
}