Data sharing is part of Manager

This commit is contained in:
Kamil Trzciński 2022-12-02 11:03:28 +01:00
parent 33f9e8581f
commit 57b36c7e53
2 changed files with 32 additions and 18 deletions

View file

@ -27,12 +27,11 @@ namespace SteamController
Managers = {
new Managers.ProcessManager(),
new Managers.SteamManager(),
new Managers.ProfileSwitcher()
new Managers.ProfileSwitcher(),
new Managers.SharedDataManager()
}
};
SharedData<SteamControllerSetting> sharedData = SharedData<SteamControllerSetting>.CreateNew();
public Controller()
{
Instance.RunOnce(TitleWithVersion, "Global\\SteamController");
@ -130,24 +129,9 @@ namespace SteamController
context.Start();
}
private void SharedData_Update()
{
if (sharedData.GetValue(out var value) && value.DesiredProfile != "")
{
context.SelectProfile(value.DesiredProfile);
}
sharedData.SetValue(new SteamControllerSetting()
{
CurrentProfile = context.CurrentProfile?.Name ?? "",
SelectableProfiles = context.Profiles.Where((profile) => profile.Selected(context) || profile.Visible).JoinWithN((profile) => profile.Name),
});
}
private void ContextStateUpdate_Tick(object? sender, EventArgs e)
{
context.Tick();
SharedData_Update();
var isDesktop = context.CurrentProfile?.IsDesktop ?? false;

View file

@ -0,0 +1,30 @@
using CommonHelpers;
namespace SteamController.Managers
{
public sealed class SharedDataManager : Manager
{
SharedData<SteamControllerSetting> sharedData = SharedData<SteamControllerSetting>.CreateNew();
public override void Tick(Context context)
{
if (sharedData.GetValue(out var value) && value.DesiredProfile != "")
{
context.SelectProfile(value.DesiredProfile);
}
sharedData.SetValue(new SteamControllerSetting()
{
CurrentProfile = context.CurrentProfile?.Name ?? "",
SelectableProfiles = SelectableProfiles(context).JoinWith0(),
});
}
private IEnumerable<String> SelectableProfiles(Context context)
{
return context.Profiles.
Where((profile) => profile.Selected(context) || profile.Visible).
Select((profile) => profile.Name);
}
}
}