1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-24 14:50:10 +00:00
msfs-popout-panel-manager/Orchestration/ProfileOrchestrator.cs

95 lines
3.1 KiB
C#
Raw Normal View History

2023-07-12 22:41:31 +00:00
using MSFSPopoutPanelManager.DomainModel.Profile;
2022-08-02 15:51:28 +00:00
using System.Linq;
2022-07-23 19:23:32 +00:00
namespace MSFSPopoutPanelManager.Orchestration
{
2023-07-12 22:41:31 +00:00
public class ProfileOrchestrator
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
private ProfileData _profileData;
private FlightSimData _flightSimData;
2022-07-23 19:23:32 +00:00
2023-07-12 22:41:31 +00:00
public ProfileOrchestrator(ProfileData profileData, FlightSimData flightSimData)
{
_profileData = profileData;
_flightSimData = flightSimData;
}
2022-08-02 15:51:28 +00:00
2023-07-12 22:41:31 +00:00
public void AddProfile(string profileName, UserProfile copiedProfile)
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
// Reset current profile
_profileData.ResetActiveProfile();
if (copiedProfile == null)
_profileData.AddProfile(profileName);
2022-07-23 19:23:32 +00:00
else
2023-07-12 22:41:31 +00:00
_profileData.AddProfile(profileName, copiedProfile);
2022-08-02 15:51:28 +00:00
// Automatically bind aircraft
2023-07-12 22:41:31 +00:00
var boundProfile = _profileData.Profiles.FirstOrDefault(p => p.AircraftBindings.Any(p => p == _flightSimData.AircraftName));
if (boundProfile == null && _flightSimData.HasAircraftName)
2022-08-02 15:51:28 +00:00
{
2023-07-12 22:41:31 +00:00
_profileData.ActiveProfile.AircraftBindings.Add(_flightSimData.AircraftName);
_profileData.WriteProfiles();
_profileData.RefreshProfile();
2022-08-02 15:51:28 +00:00
}
2022-07-23 19:23:32 +00:00
}
public void DeleteActiveProfile()
{
2023-07-12 22:41:31 +00:00
_profileData.DeleteActiveProfile();
}
public void MoveToNextProfile()
{
// Reset current profile
_profileData.ResetActiveProfile();
var newProfileIndex = _profileData.Profiles.IndexOf(_profileData.ActiveProfile) + 1;
if (newProfileIndex >= _profileData.Profiles.Count)
newProfileIndex = 0;
_profileData.SetActiveProfile(newProfileIndex);
}
public void MoveToPreviousProfile()
{
// Reset current profile
_profileData.ResetActiveProfile();
var newProfileIndex = _profileData.Profiles.IndexOf(_profileData.ActiveProfile) - 1;
if (newProfileIndex < 0)
newProfileIndex = _profileData.Profiles.Count - 1;
_profileData.SetActiveProfile(newProfileIndex);
2022-07-23 19:23:32 +00:00
}
2023-07-12 22:41:31 +00:00
public void ChangeProfile(UserProfile profile)
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_profileData != null)
_profileData.SetActiveProfile(profile.Id);
2022-07-23 19:23:32 +00:00
}
2022-08-01 23:21:42 +00:00
public void AddProfileBinding(string bindingAircraft)
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_profileData.ActiveProfile != null && bindingAircraft != null)
_profileData.AddProfileBinding(bindingAircraft);
2022-07-23 19:23:32 +00:00
}
2022-08-01 23:21:42 +00:00
public void DeleteProfileBinding(string bindingAircraft)
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_profileData.ActiveProfile != null && bindingAircraft != null)
_profileData.DeleteProfileBinding(bindingAircraft);
}
public void AddPanel()
{
var panelConfig = new PanelConfig();
panelConfig.PanelType = PanelType.CustomPopout;
panelConfig.PanelSource.Color = PanelConfigColors.GetNextAvailableColor(_profileData.ActiveProfile.PanelConfigs.ToList());
_profileData.ActiveProfile.PanelConfigs.Add(panelConfig);
2022-07-23 19:23:32 +00:00
}
}
}