Skip to content

Commit

Permalink
Merge pull request #907 from PlayEveryWare/fix/manager-to-service-rename
Browse files Browse the repository at this point in the history
fix: Rename managers that have been refactored into services
  • Loading branch information
paulhazen authored Sep 16, 2024
2 parents c2bfef6 + 62eb07d commit 6bb7bdb
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/EOSTransferInProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace PlayEveryWare.EpicOnlineServices.Samples
using Utility;

/// <summary>
/// Class <c>EOSTransferInProgress</c> is used in <c>EOSTitleStorageManager</c> and <c>EOSPlayerDataStorageManager</c> to keep track of downloaded cached file data.
/// Class <c>EOSTransferInProgress</c> is used in <c>EOSTitleStorageManager</c> and <c>PlayerDataStorageService</c> to keep track of downloaded cached file data.
/// </summary>
public class EOSTransferInProgress
{
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/StandardSamples/Services/EOSService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ namespace PlayEveryWare.EpicOnlineServices
{
using Epic.OnlineServices;
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

/// <summary>
/// Contains implementation of common functionality between different
/// EOS Service managers (Currently AchievementsService and StatsService).
/// </summary>
public abstract class EOSService : IEOSSubManager, IDisposable
public abstract class EOSService : IDisposable
{
/// <summary>
/// Describes the function signature for the event that triggers when
Expand Down Expand Up @@ -174,8 +173,9 @@ private void OnAuthenticationChanged(bool authenticated)

/// <summary>
/// Implement this method to perform tasks when a user authenticates.
/// By default, there is no action taken.
/// </summary>
protected abstract void OnLoggedIn();
protected virtual void OnLoggedIn() { }

/// <summary>
/// If there are tasks that need to be done when logged out, consider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,41 @@ namespace PlayEveryWare.EpicOnlineServices.Samples
using Epic.OnlineServices;
using Epic.OnlineServices.PlayerDataStorage;

/// <summary>Class <c>EOSPlayerDataStorageManager</c> is a simplified wrapper for EOS [PlayerDataStorage Interface](https://dev.epicgames.com/docs/services/en-US/Interfaces/PlayerDataStorage/index.html).</summary>
public class EOSPlayerDataStorageManager : DataService<PlayerDataStorageFileTransferRequestWrapper>
/// <summary>Class <c>PlayerDataStorageService</c> is a simplified wrapper for EOS [PlayerDataStorage Interface](https://dev.epicgames.com/docs/services/en-US/Interfaces/PlayerDataStorage/index.html).</summary>
public class PlayerDataStorageService

: StorageService<PlayerDataStorageFileTransferRequestWrapper>
{
public event Action OnFileListUpdated;

#region Singleton Implementation

/// <summary>
/// Lazy instance for singleton allows for thread-safe interactions with
/// the TitleStorageService
/// </summary>
private static readonly Lazy<PlayerDataStorageService> s_LazyInstance = new(() => new PlayerDataStorageService());

/// <summary>
/// Accessor for the instance.
/// </summary>
public static PlayerDataStorageService Instance
{
get
{
return s_LazyInstance.Value;
}
}

/// <summary>
/// Private constructor guarantees adherence to thread-safe singleton
/// pattern.
/// </summary>
private PlayerDataStorageService() { }

#endregion


//-------------------------------------------------------------------------
/// <summary>(async) Query list of files.</summary>
public void QueryFileList()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace PlayEveryWare.EpicOnlineServices
/// <typeparam name="T">
/// The type of file transfer request that this data service makes use of.
/// </typeparam>
public abstract class DataService<T> : EOSService where T : IFileTransferRequest
public abstract class StorageService<T> : EOSService where T : IFileTransferRequest
{
/// <summary>
/// Reference to an instance of a transfer request created within the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,39 @@ namespace PlayEveryWare.EpicOnlineServices.Samples
using UnityEngine;
using Epic.OnlineServices;
using Epic.OnlineServices.TitleStorage;
/// <summary>Class <c>EOSTitleStorageManager</c> is a simplified wrapper for EOS [TitleStorage Interface](https://dev.epicgames.com/docs/services/en-US/Interfaces/TitleStorage/index.html).</summary>
public class EOSTitleStorageManager : DataService<TitleStorageFileTransferRequestWrapper>

/// <summary>Class <c>TitleStorageService</c> is a simplified wrapper for EOS [TitleStorage Interface](https://dev.epicgames.com/docs/services/en-US/Interfaces/TitleStorage/index.html).</summary>
public class TitleStorageService : StorageService<TitleStorageFileTransferRequestWrapper>
{
private List<string> CurrentFileNames = new List<string>();

#region Singleton Implementation

/// <summary>
/// Lazy instance for singleton allows for thread-safe interactions with
/// the TitleStorageService
/// </summary>
private static readonly Lazy<TitleStorageService> s_LazyInstance = new(() => new TitleStorageService());

/// <summary>
/// Accessor for the instance.
/// </summary>
public static TitleStorageService Instance
{
get
{
return s_LazyInstance.Value;
}
}

/// <summary>
/// Private constructor guarantees adherence to thread-safe singleton
/// pattern.
/// </summary>
private TitleStorageService() { }

#endregion

// Manager Callbacks
public EOSResultEventHandler QueryListCallback { get; private set; } = null;

Expand All @@ -43,14 +70,6 @@ public List<string> GetCachedCurrentFileNames()
return CurrentFileNames;
}

/// <summary>User Logged In actions</summary>
/// <list type="bullet">
/// <item><description><c>NA</c></description></item>
/// </list>
protected override void OnLoggedIn()
{
}

protected override Task InternalRefreshAsync()
{
// TODO: Needs implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class UIPlayerDataStorageMenu : SampleMenu

private string currentSelectedFile = string.Empty;

private EOSPlayerDataStorageManager PlayerDataStorageManager;
private PlayerDataInventory currentInventory = null;

private HashSet<string> fileNames = new();
Expand All @@ -70,31 +69,19 @@ public class UIPlayerDataStorageMenu : SampleMenu
protected override void Awake()
{
base.Awake();
PlayerDataStorageManager = EOSManager.Instance.GetOrCreateManager<EOSPlayerDataStorageManager>();
fileNameUIEntries.AddRange(FilesContentParent.GetComponentsInChildren<UIFileNameEntry>(true));
}

protected override void OnEnable()
{
base.OnEnable();
}

private void Start()
{
RemoteViewText.text = string.Empty;
LocalViewText.text = string.Empty;
CurrentFileNameText.text = "*No File Selected*";
}

protected override void OnDestroy()
{
base.OnDestroy();
EOSManager.Instance.RemoveManager<EOSPlayerDataStorageManager>();
}

private void UpdateFileListUI()
{
if (PlayerDataStorageManager.GetLocallyCachedData().Count != fileNameUIEntries.Count)
if (PlayerDataStorageService.Instance.GetLocallyCachedData().Count != fileNameUIEntries.Count)
{
// Destroy current UI member list
foreach (var entry in fileNameUIEntries)
Expand All @@ -104,7 +91,7 @@ private void UpdateFileListUI()
fileNameUIEntries.Clear();
fileNames.Clear();

foreach (string fileName in PlayerDataStorageManager.GetLocallyCachedData().Keys)
foreach (string fileName in PlayerDataStorageService.Instance.GetLocallyCachedData().Keys)
{
fileNames.Add(fileName);
GameObject fileUIObj = Instantiate(UIFileNameEntryPrefab, FilesContentParent.transform);
Expand All @@ -128,13 +115,13 @@ private void UpdateFileListUI()

public void RefreshButtonOnClick()
{
PlayerDataStorageManager.GetLocallyCachedData().Clear();
PlayerDataStorageService.Instance.GetLocallyCachedData().Clear();

PlayerDataStorageManager.QueryFileList();
PlayerDataStorageService.Instance.QueryFileList();

if (currentSelectedFile != string.Empty)
{
PlayerDataStorageManager.DownloadFile(currentSelectedFile, () => UpdateRemoteView(currentSelectedFile));
PlayerDataStorageService.Instance.DownloadFile(currentSelectedFile, () => UpdateRemoteView(currentSelectedFile));
}
}

Expand All @@ -153,7 +140,7 @@ public void NewFileButtonOnClick()
// Un-comment the following lines to test a large file
// newFileContents = new string('*', 20000);

PlayerDataStorageManager.AddFile(NewFileNameTextBox.InputField.text, newFileContents, UpdateFileListUI);
PlayerDataStorageService.Instance.AddFile(NewFileNameTextBox.InputField.text, newFileContents, UpdateFileListUI);

NewFileNameTextBox.InputField.text = string.Empty;
}
Expand All @@ -172,7 +159,7 @@ public void SaveButtonOnClick()
return;
}

PlayerDataStorageManager.AddFile(currentSelectedFile, LocalViewText.text, () => UpdateRemoteView(currentSelectedFile));
PlayerDataStorageService.Instance.AddFile(currentSelectedFile, LocalViewText.text, () => UpdateRemoteView(currentSelectedFile));
}

public void DownloadButtonOnClick()
Expand Down Expand Up @@ -220,7 +207,7 @@ public void DuplicateButtonOnClick()
copyName = copyName + copyIndex;
}

PlayerDataStorageManager.CopyFile(currentSelectedFile, copyName);
PlayerDataStorageService.Instance.CopyFile(currentSelectedFile, copyName);
}

public void DeleteButtonOnClick()
Expand All @@ -231,7 +218,7 @@ public void DeleteButtonOnClick()
return;
}

PlayerDataStorageManager.DeleteFile(currentSelectedFile);
PlayerDataStorageService.Instance.DeleteFile(currentSelectedFile);

currentSelectedFile = string.Empty;
CurrentFileNameText.text = "*No File Selected*";
Expand All @@ -257,12 +244,12 @@ private void FileListOnClick(string fileName)

private void UpdateRemoteView(string fileName)
{
string fileContent = PlayerDataStorageManager.GetCachedFileContent(fileName);
string fileContent = PlayerDataStorageService.Instance.GetCachedFileContent(fileName);

if (fileContent == null)
{
RemoteViewText.text = "*** Downloading content ***";
PlayerDataStorageManager.DownloadFile(fileName, () => UpdateRemoteView(fileName));
PlayerDataStorageService.Instance.DownloadFile(fileName, () => UpdateRemoteView(fileName));
}
else if (fileContent.Length == 0)
{
Expand Down Expand Up @@ -306,18 +293,13 @@ public override void Show()
{
base.Show();
UpdateFileListUI();
PlayerDataStorageManager.OnFileListUpdated += UpdateFileListUI;
PlayerDataStorageService.Instance.OnFileListUpdated += UpdateFileListUI;
}

public override void Hide()
{
base.Hide();

if (null != PlayerDataStorageManager)
{
PlayerDataStorageManager.OnFileListUpdated -= UpdateFileListUI;
}

currentSelectedFile = string.Empty;
currentInventory = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class UITitleStorageMenu : SampleMenu
public GameObject UIFileNameEntryPrefab;

public Text FileContent;
private EOSTitleStorageManager TitleStorageManager;
private List<string> CurrentTags = new List<string>();

protected override void Awake()
Expand All @@ -64,13 +63,6 @@ protected override void Awake()

private void Start()
{
TitleStorageManager = EOSManager.Instance.GetOrCreateManager<EOSTitleStorageManager>();
}

protected override void OnDestroy()
{
base.OnDestroy();
EOSManager.Instance.RemoveManager<EOSTitleStorageManager>();
}

public void AddTagOnClick()
Expand Down Expand Up @@ -156,7 +148,7 @@ public void QueryListOnClick()
return;
}

TitleStorageManager.QueryFileList(CurrentTags.ToArray(), SetFileListUI);
TitleStorageService.Instance.QueryFileList(CurrentTags.ToArray(), SetFileListUI);
}

private void SetFileListUI(Result result)
Expand All @@ -173,7 +165,7 @@ private void SetFileListUI(Result result)
GameObject.Destroy(child.gameObject);
}

foreach (string entry in TitleStorageManager.GetCachedCurrentFileNames())
foreach (string entry in TitleStorageService.Instance.GetCachedCurrentFileNames())
{
GameObject fileNameUIObj = Instantiate(UIFileNameEntryPrefab, FileNameContentParent.transform);
UIFileNameEntry fileNameEntry = fileNameUIObj.GetComponent<UIFileNameEntry>();
Expand All @@ -198,14 +190,14 @@ public void DownloadOnClick()
return;
}

if (!TitleStorageManager.GetCachedCurrentFileNames().Contains(FileNameTextBox.InputField.text))
if (!TitleStorageService.Instance.GetCachedCurrentFileNames().Contains(FileNameTextBox.InputField.text))
{
Debug.LogError("UITitleStorageMenu - FileName doesn't exist, cannot be downloaded!");
return;
}

// Check if it's already been downloaded
if (TitleStorageManager.GetLocallyCachedData().TryGetValue(FileNameTextBox.InputField.text, out string cachedData))
if (TitleStorageService.Instance.GetLocallyCachedData().TryGetValue(FileNameTextBox.InputField.text, out string cachedData))
{
Debug.Log("UITitleStorageMenu - FileName '{0}' already downloaded. Display content.");

Expand All @@ -214,7 +206,7 @@ public void DownloadOnClick()
return;
}

TitleStorageManager.DownloadFile(FileNameTextBox.InputField.text, UpdateFileContent);
TitleStorageService.Instance.DownloadFile(FileNameTextBox.InputField.text, UpdateFileContent);
}

public void UpdateFileContent(Result result)
Expand All @@ -225,7 +217,7 @@ public void UpdateFileContent(Result result)
return;
}

if (TitleStorageManager.GetLocallyCachedData().TryGetValue(FileNameTextBox.InputField.text, out string fileContent))
if (TitleStorageService.Instance.GetLocallyCachedData().TryGetValue(FileNameTextBox.InputField.text, out string fileContent))
{
// Update UI
FileContent.text = fileContent;
Expand Down
Loading

0 comments on commit 6bb7bdb

Please sign in to comment.