Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor local playerprefs profile service.
- Loading branch information
Showing
20 changed files
with
282 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using UnityEngine; | ||
|
||
namespace Impulse | ||
{ | ||
/// <summary> | ||
/// Manages the presentation for the game | ||
/// </summary> | ||
public class PresentationService : Singleton<PresentationService> | ||
{ | ||
public void Initialize() | ||
{ | ||
SetResolution(LocalPlayerProfileService.Instance.GetLocalData().Resolution); | ||
} | ||
|
||
/// <summary> | ||
/// Set display resolution. | ||
/// </summary> | ||
public void SetResolution(string resolutionString) | ||
{ | ||
var words = resolutionString.Split('x'); | ||
var width = int.Parse(words[0]); | ||
var height = int.Parse(words[1]); | ||
|
||
Screen.SetResolution(width, height, Screen.fullScreen); | ||
} | ||
} | ||
} |
File renamed without changes.
14 changes: 7 additions & 7 deletions
14
Assets/Scripts/MainSystem/Zenject/SaveControllerInstaller.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using Zenject; | ||
using Zenject; | ||
|
||
public class SaveControllerInstaller : MonoInstaller<SaveControllerInstaller> | ||
namespace Impulse | ||
{ | ||
public override void InstallBindings() | ||
public class SaveControllerInstaller : MonoInstaller<SaveControllerInstaller> | ||
{ | ||
transform.GetComponent<GameObjectContext>().Container.BindInstance(GetComponent<ILocalDataManager>()); | ||
public override void InstallBindings() | ||
{ | ||
transform.GetComponent<GameObjectContext>().Container.BindInstance(GetComponent<ILocalPlayerProfileService>()); | ||
} | ||
} | ||
} |
82 changes: 41 additions & 41 deletions
82
Assets/Scripts/MainSystem/Zenject/ZenjectMainSystemStartup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using Zenject; | ||
/// <summary> | ||
/// Use this class for initialization of core systems (core singleton manager instatiation) | ||
/// </summary> | ||
public class ZenjectMainSystemStartup : MonoInstaller | ||
{ | ||
[SerializeField] | ||
[Tooltip("List of singletons to instantiate")] | ||
private List<GameObject> _singletonsToSpawn = new List<GameObject>(); | ||
|
||
namespace Impulse | ||
{ | ||
/// <summary> | ||
/// Use this to install the zenject bindings | ||
/// Use this class for initialization of core systems (core singleton service instantiation) | ||
/// </summary> | ||
public override void InstallBindings() | ||
public class ZenjectMainSystemStartup : MonoInstaller | ||
{ | ||
// Deactivate install warning, we don't need to worry about installation order as every singleton initialization should be order independant | ||
Container.ShouldCheckForInstallWarning = false; | ||
[SerializeField] [Tooltip("List of singleton services to instantiate")] | ||
private List<GameObject> _singletonsToSpawn = new List<GameObject>(); | ||
|
||
foreach (GameObject singleton in _singletonsToSpawn) | ||
/// <summary> | ||
/// Use this to install the Zenject bindings | ||
/// </summary> | ||
public override void InstallBindings() | ||
{ | ||
// Zenject based singletons (objects in need of reference injection) | ||
if (singleton.GetComponent<GameObjectContext>() != null) | ||
{ | ||
Container.InstantiatePrefab(singleton); | ||
} | ||
// Regular based singletons | ||
else | ||
// Deactivate install warning - we don't need to worry about installation order as every singleton initialization should be order independent. | ||
Container.ShouldCheckForInstallWarning = false; | ||
|
||
foreach (var singleton in _singletonsToSpawn) | ||
{ | ||
GameObject instancedSingleton = Instantiate(singleton); | ||
instancedSingleton.transform.parent = this.transform; | ||
instancedSingleton.transform.localPosition = Vector3.zero; | ||
instancedSingleton.transform.localRotation = Quaternion.identity; | ||
instancedSingleton.transform.localScale = Vector3.one; | ||
// Zenject based singletons (objects in need of reference injection) | ||
if (singleton.GetComponent<GameObjectContext>() != null) | ||
{ | ||
Container.InstantiatePrefab(singleton); | ||
} | ||
// Regular based singletons | ||
else | ||
{ | ||
var instancedSingleton = Instantiate(singleton); | ||
instancedSingleton.transform.parent = transform; | ||
instancedSingleton.transform.localPosition = Vector3.zero; | ||
instancedSingleton.transform.localRotation = Quaternion.identity; | ||
instancedSingleton.transform.localScale = Vector3.one; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Use this for initialization | ||
/// </summary> | ||
public override void Start() | ||
{ | ||
// Initialize core managers | ||
SaveManager.Instance.Initialize(); | ||
/// <summary> | ||
/// Use this for initialization | ||
/// </summary> | ||
public override void Start() | ||
{ | ||
// Initialize core managers | ||
LocalPlayerProfileService.Instance.Initialize(); | ||
|
||
// Load player profile | ||
SaveManager.Instance.LoadData(); | ||
// Load player profile | ||
LocalPlayerProfileService.Instance.LoadData(); | ||
|
||
// Use presentation data | ||
PresentationManager.Instance.Initialize(); | ||
// Use presentation data | ||
PresentationService.Instance.Initialize(); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,38 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.Generic; | ||
using Impulse; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class OptionsMenuScreen : InterfaceScreen | ||
{ | ||
|
||
[SerializeField] | ||
protected Dropdown _dropdownSystem; | ||
protected Dropdown DropdownSystem; | ||
|
||
[SerializeField] | ||
protected List<string> _resolutionOptions = new List<string>() | ||
protected List<string> ResolutionOptions = new List<string> | ||
{ | ||
"1024x768", "1280x800","1360x768","1366x768","1440x900","1600x900","1680x1050","1920x1080","2560x1080","2560x1440","2560x1600" | ||
}; | ||
|
||
/// <summary> | ||
/// Use this for initialization | ||
/// </summary> | ||
protected override void Start() | ||
{ | ||
_dropdownSystem.ClearOptions(); | ||
_dropdownSystem.AddOptions(_resolutionOptions); | ||
DropdownSystem.ClearOptions(); | ||
DropdownSystem.AddOptions(ResolutionOptions); | ||
|
||
// Load saved resolution | ||
string savedResolution = SaveManager.Instance.GetLocalData().Resolution; | ||
int indexOfSavedResolution = _resolutionOptions.IndexOf(savedResolution); | ||
_dropdownSystem.value = indexOfSavedResolution; | ||
_dropdownSystem.RefreshShownValue(); | ||
var savedResolution = LocalPlayerProfileService.Instance.GetLocalData().Resolution; | ||
var indexOfSavedResolution = ResolutionOptions.IndexOf(savedResolution); | ||
DropdownSystem.value = indexOfSavedResolution; | ||
DropdownSystem.RefreshShownValue(); | ||
} | ||
|
||
public void SetResolution() | ||
{ | ||
// Notify resolution manager | ||
PresentationManager.Instance.SetResolution(_resolutionOptions[_dropdownSystem.value]); | ||
PresentationService.Instance.SetResolution(ResolutionOptions[DropdownSystem.value]); | ||
|
||
// Update player prefs | ||
string resolutionToSave = _resolutionOptions[_dropdownSystem.value]; | ||
SaveManager.Instance.GetLocalData().Resolution = resolutionToSave; | ||
SaveManager.Instance.SaveData(); | ||
// Update player profile settings. | ||
var resolutionToSave = ResolutionOptions[DropdownSystem.value]; | ||
LocalPlayerProfileService.Instance.GetLocalData().Resolution = resolutionToSave; | ||
LocalPlayerProfileService.Instance.SaveData(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
Assets/Scripts/PlayerProfile/ILocalPlayerProfileService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Impulse | ||
{ | ||
/// <summary> | ||
/// Interface for local profile management. | ||
/// </summary> | ||
public interface ILocalPlayerProfileService | ||
{ | ||
/// <summary> | ||
/// Requests the profile data to be reset. | ||
/// </summary> | ||
void ResetProfile(); | ||
|
||
/// <summary> | ||
/// Save the current values of the player profile data. | ||
/// </summary> | ||
void SaveProfile(PlayerProfile playerProfile); | ||
|
||
/// <summary> | ||
/// Load player profile. | ||
/// </summary> | ||
PlayerProfile LoadProfile(); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Zenject; | ||
|
||
namespace Impulse | ||
{ | ||
public class LocalPlayerProfileService : Singleton<LocalPlayerProfileService> | ||
{ | ||
|
||
private PersistentLocalProfileService _localSaveService; | ||
[Inject] private ILocalPlayerProfileService _localPlayerProfileService; | ||
|
||
public void Initialize() | ||
{ | ||
_localSaveService = new PersistentLocalProfileService(); | ||
_localSaveService.Initialize(_localPlayerProfileService); | ||
} | ||
|
||
public PlayerProfile GetPlayerProfile() | ||
{ | ||
return _localSaveService.LocalPlayerProfile; | ||
} | ||
|
||
public void SaveData() | ||
{ | ||
_localSaveService.SaveProfile(); | ||
} | ||
|
||
public void ResetData() | ||
{ | ||
_localSaveService.ResetProfile(); | ||
} | ||
|
||
public void LoadData() | ||
{ | ||
_localSaveService.LoadProfile(); | ||
} | ||
|
||
public PlayerProfile GetLocalData() | ||
{ | ||
if (_localSaveService.LocalPlayerProfile == null) | ||
return new PlayerProfile(); | ||
|
||
return _localSaveService.LocalPlayerProfile; | ||
} | ||
} | ||
} |
File renamed without changes.
48 changes: 0 additions & 48 deletions
48
Assets/Scripts/PlayerProfile/PersistentLocalDataService.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.