Skip to content

Commit

Permalink
DRY but I don't know if it is a good way
Browse files Browse the repository at this point in the history
  • Loading branch information
chihirobelmo committed Jul 1, 2022
1 parent bf1e2c3 commit 409772a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 32 deletions.
12 changes: 7 additions & 5 deletions Falcon BMS Alternative Launcher/Override/OverrideSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ protected void SaveDeviceSorting(DeviceControl deviceControl)
ds.Close();
}

/// <summary>
/// As the name implies...
/// </summary>
protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile)
protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile, int DXnumber)
{
string filename = appReg.GetInstallDir() + "/User/Config/" + appReg.getAutoKeyFileName();

Expand All @@ -218,14 +215,19 @@ protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl device
sw.Write(keyFile.keyAssign[i].GetKeyLine());
for (int i = 0; i < deviceControl.joyAssign.Length; i++)
{
sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length, CommonConstants.DX32));
sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length, DXnumber));
// PRIMARY DEVICE POV
if (((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == i)
sw.Write(deviceControl.joyAssign[i].GetKeyLinePOV());
}
sw.Close();
}

protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile)
{
SaveKeyMapping(inGameAxis, deviceControl, keyFile, CommonConstants.DX32);
}

/// <summary>
/// Overwrite callsign.pop file.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override void SaveConfigfile(Hashtable inGameAxis, DeviceControl devic
cfg.Close();
}

protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile)
protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile, int DXnumber)
{
string filename = appReg.GetInstallDir() + "/User/Config/" + appReg.getAutoKeyFileName();

Expand All @@ -72,7 +72,7 @@ protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl devic
sw.Write(keyFile.keyAssign[i].GetKeyLine());
for (int i = 0; i < deviceControl.joyAssign.Length; i++)
{
sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length, CommonConstants.DX32));
sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length, DXnumber));
// PRIMARY DEVICE POV
if (((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == i && ((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == ((InGameAxAssgn)inGameAxis["Throttle"]).GetDeviceNumber())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,9 @@ protected override void SaveConfigfile(Hashtable inGameAxis, DeviceControl devic
cfg.Close();
}

// please DRY later.
protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile)
{
string filename = appReg.GetInstallDir() + "/User/Config/" + appReg.getAutoKeyFileName();

if (File.Exists(filename))
File.SetAttributes(filename, File.GetAttributes(filename) & ~FileAttributes.ReadOnly);

StreamWriter sw = new StreamWriter
(filename, false, Encoding.GetEncoding("utf-8"));
for (int i = 0; i < keyFile.keyAssign.Length; i++)
sw.Write(keyFile.keyAssign[i].GetKeyLine());
for (int i = 0; i < deviceControl.joyAssign.Length; i++)
{
sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length, CommonConstants.DX128));
// PRIMARY DEVICE POV
if (((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == i && ((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == ((InGameAxAssgn)inGameAxis["Throttle"]).GetDeviceNumber())
{
sw.Write(deviceControl.joyAssign[i].GetKeyLinePOV());
continue;
}
if (((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == i)
sw.Write(deviceControl.joyAssign[i].GetKeyLinePOV(0));
if (((InGameAxAssgn)inGameAxis["Throttle"]).GetDeviceNumber() == i)
sw.Write(deviceControl.joyAssign[i].GetKeyLinePOV(1));
}
sw.Close();
SaveKeyMapping(inGameAxis, deviceControl, keyFile, CommonConstants.DX128);
}
}
}

0 comments on commit 409772a

Please sign in to comment.