Skip to content

Commit

Permalink
Rename ModeProfile to Mode to de-conflict and standardize on naming. …
Browse files Browse the repository at this point in the history
…A profile contains modes, so a 'modeprofile' is confusing.
  • Loading branch information
joekolodz committed Apr 27, 2022
1 parent 047f981 commit f3b92a7
Show file tree
Hide file tree
Showing 28 changed files with 487 additions and 486 deletions.
50 changes: 25 additions & 25 deletions src/Models/HOTASCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class HOTASCollection : IHOTASCollection
public virtual event EventHandler<MacroCancelledEventArgs> MacroCancelled;
public virtual event EventHandler<ButtonPressedEventArgs> ButtonPressed;
public virtual event EventHandler<AxisChangedEventArgs> AxisChanged;
public virtual event EventHandler<ModeProfileChangedEventArgs> ModeProfileChanged;
public virtual event EventHandler<ModeChangedEventArgs> ModeChanged;
public virtual event EventHandler<LostConnectionToDeviceEventArgs> LostConnectionToDevice;

[JsonProperty]
Expand All @@ -44,7 +44,7 @@ public class HOTASCollection : IHOTASCollection
public ActionCatalog ActionCatalog { get; private set; }

[JsonProperty]
public Dictionary<int, ModeActivationItem> ModeProfileActivationButtons { get; private set; }
public Dictionary<int, ModeActivationItem> ModeActivationButtons { get; private set; }

public HOTASCollection()
{
Expand All @@ -65,7 +65,7 @@ public HOTASCollection(DirectInputFactory directInputFactory, JoystickFactory jo
private void Initialize()
{
Devices = new ObservableCollection<IHOTASDevice>();
ModeProfileActivationButtons = new Dictionary<int, ModeActivationItem>();
ModeActivationButtons = new Dictionary<int, ModeActivationItem>();
JsonFormatVersion = FileFormatVersion;
}

Expand Down Expand Up @@ -93,8 +93,8 @@ public void ReplaceDevice(IHOTASDevice newDevice)
private void RebuildMapForNewDevice(IHOTASDevice device, IHOTASDevice newDevice)
{
newDevice.ApplyButtonMap(device.ButtonMap.ToObservableCollection());
newDevice.SetModeProfile(device.ModeProfiles);
newDevice.SetModeActivation(ModeProfileActivationButtons);
newDevice.SetMode(device.Modes);
newDevice.SetModeActivation(ModeActivationButtons);
Devices.Add(newDevice);
}

Expand Down Expand Up @@ -126,7 +126,7 @@ private void StopDevice(IHOTASDevice device)
device.KeystrokeUpSent -= Device_KeystrokeUpSent;
device.MacroStarted -= Device_MacroStarted;
device.MacroCancelled -= Device_MacroCancelled;
device.ModeProfileSelected -= Device_ModeProfileSelected;
device.ModeSelected -= device_modeSelected;
device.ShiftReleased -= Device_ShiftReleased;
device.LostConnectionToDevice -= Device_LostConnectionToDevice;

Expand All @@ -145,7 +145,7 @@ public void ApplyButtonMapToAllProfiles()
{
foreach (var d in Devices)
{
d.OverlayAllProfilesToDevice();
d.OverlayAllModesToDevice();
}
}

Expand All @@ -165,11 +165,11 @@ public void ListenToDevice(IHOTASDevice device)
device.KeystrokeUpSent += Device_KeystrokeUpSent;
device.MacroStarted += Device_MacroStarted;
device.MacroCancelled += Device_MacroCancelled;
device.ModeProfileSelected += Device_ModeProfileSelected;
device.ModeSelected += device_modeSelected;
device.ShiftReleased += Device_ShiftReleased;
device.LostConnectionToDevice += Device_LostConnectionToDevice;

device.SetModeActivation(ModeProfileActivationButtons);
device.SetModeActivation(ModeActivationButtons);
device.ListenAsync();
}

Expand All @@ -188,27 +188,27 @@ private void RemoveDevice(IHOTASDevice device)
Devices.Remove(device);
}

public int SetupNewModeProfile()
public int SetupNewMode()
{
var newMode = 0;
foreach (var d in Devices)
{
newMode = d.SetupNewModeProfile();
newMode = d.SetupNewMode();
}

return newMode;
}

public void CopyModeProfileFromTemplate(int templateModeSource, int destinationMode)
public void CopyModeFromTemplate(int templateModeSource, int destinationMode)
{
foreach (var d in Devices)
{
d.CopyModeProfileFromTemplate(templateModeSource, destinationMode);
d.CopyModeFromTemplate(templateModeSource, destinationMode);
}
}


private void Device_ModeProfileSelected(object sender, ModeProfileSelectedEventArgs e)
private void device_modeSelected(object sender, ModeSelectedEventArgs e)
{
if (!(sender is IHOTASDevice)) return;

Expand Down Expand Up @@ -327,7 +327,7 @@ public void SetMode(int mode)
{
d.SetMode(mode);
}
ModeProfileChanged?.Invoke(this, new ModeProfileChangedEventArgs() { Mode = mode });
ModeChanged?.Invoke(this, new ModeChangedEventArgs() { Mode = mode });
}

/// <summary>
Expand All @@ -351,23 +351,23 @@ public void AutoSetMode()
}
}

public bool RemoveModeProfile(ModeActivationItem item)
public bool RemoveMode(ModeActivationItem item)
{
if (ModeProfileActivationButtons.ContainsValue(item))
if (ModeActivationButtons.ContainsValue(item))
{
RemoveActivationButtonModeFromAllProfiles(item);
ModeProfileActivationButtons.Remove(item.Mode);
ModeActivationButtons.Remove(item.Mode);

foreach (var d in Devices)
{
d.RemoveModeProfile(item.Mode);
d.RemoveMode(item.Mode);
}

Logging.Log.Debug($"DELETED Mode {item.Mode}!");

if (ModeProfileActivationButtons.Count <= 0) return true;
if (ModeActivationButtons.Count <= 0) return true;

var firstMode = ModeProfileActivationButtons.Keys.FirstOrDefault();
var firstMode = ModeActivationButtons.Keys.FirstOrDefault();
SetMode(firstMode);
Logging.Log.Debug($"Setting Mode to {firstMode}!");
return true;
Expand All @@ -377,12 +377,12 @@ public bool RemoveModeProfile(ModeActivationItem item)

private void RemoveActivationButtonModeFromAllProfiles(ModeActivationItem item)
{
foreach (var button in ModeProfileActivationButtons)
foreach (var button in ModeActivationButtons)
{
var device = Devices.FirstOrDefault(d => d.DeviceId == button.Value.DeviceId);
if (device == null) continue;

foreach (var profile in device.ModeProfiles)
foreach (var profile in device.Modes)
{
var map = profile.Value.FirstOrDefault(m => m.MapId == item.ButtonId);

Expand Down Expand Up @@ -410,7 +410,7 @@ private void RemoveActivationButtonModeFromAllProfiles(ModeActivationItem item)
public void ApplyActivationButtonToAllProfiles()
{
//new profiles wont have the link to previous profiles, so we iterate the entire dictionary to sync them all
foreach (var item in ModeProfileActivationButtons)
foreach (var item in ModeActivationButtons)
{
var buttonId = item.Value.ButtonId;
var isShift = item.Value.IsShift;
Expand All @@ -420,7 +420,7 @@ public void ApplyActivationButtonToAllProfiles()
var device = Devices.FirstOrDefault(d => d.DeviceId == deviceId);
if (device == null) continue;

foreach (var profile in device.ModeProfiles)
foreach (var profile in device.Modes)
{
var map = profile.Value.FirstOrDefault(m => m.MapId == buttonId);

Expand Down
Loading

0 comments on commit f3b92a7

Please sign in to comment.