Skip to content

Commit 89ebd10

Browse files
author
AJubrey
committed
[ADDED] a test to demonstrate purely the preference system at work
[CHANGED] replaced two for loops with two lambda functions [ADDED] a helper function that just applys a regular expression to a string
1 parent 5213417 commit 89ebd10

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -450,38 +450,18 @@ private int ChoosePreferredDCCApp(int optionA, int optionB)
450450
int scoreA = -1;
451451
int scoreB = -1;
452452

453-
for( int i = 0; i < s_PreferenceList.Count; i++ )
454-
{
455-
//The constant without any spaces
456-
string currentApp = System.Text.RegularExpressions.Regex.Replace(s_PreferenceList[i], @"[\s^0-9]", "");
457-
//The potential app, without any numbers or spaces
458-
string comparingApp = System.Text.RegularExpressions.Regex.Replace(appA, @"[\s^0-9]", "");
459-
460-
if (currentApp.Equals(comparingApp))
461-
{
462-
scoreA = i;
463-
break;
464-
}
465-
466-
}
453+
scoreA = s_PreferenceList.FindIndex(app => RemoveSpacesAndNumbers(app).Equals(RemoveSpacesAndNumbers(appA)));
467454

468-
for (int i = 0; i < s_PreferenceList.Count; i++)
469-
{
470-
//The constant without any spaces
471-
string currentApp = System.Text.RegularExpressions.Regex.Replace(s_PreferenceList[i], @"[\s^0-9]", "");
472-
//The potential app, without any numbers or spaces
473-
string comparingApp = System.Text.RegularExpressions.Regex.Replace(appB, @"[\s^0-9]", "");
474-
475-
if (currentApp.Equals(comparingApp))
476-
{
477-
scoreB = i;
478-
break;
479-
}
480-
}
455+
scoreB = s_PreferenceList.FindIndex(app => RemoveSpacesAndNumbers(app).Equals(RemoveSpacesAndNumbers(appB)));
481456

482457
return scoreA < scoreB ? optionA : optionB;
483458
}
484459

460+
public string RemoveSpacesAndNumbers(string s)
461+
{
462+
return System.Text.RegularExpressions.Regex.Replace(s, @"[\s^0-9]", "");
463+
}
464+
485465
/// <summary>
486466
/// Finds the version based off of the title of the application
487467
/// </summary>

Assets/FbxExporters/Editor/UnitTests/FbxExportSettingsTest.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public void TestFindPreferredProgram()
213213
Assert.AreEqual(preferred, -1);
214214

215215
//Testing the results of only having a mayaLT install
216-
ExportSettings.instance.SetDCCOptionNames(new List<string> { "Maya LT"+ "2018" }); //hardcoded because the constant is changed in another branch but not this one at this time
216+
ExportSettings.instance.SetDCCOptionNames(new List<string> { ExportSettings.kMayaLtOptionName + "2018" }); //hardcoded because the constant is changed in another branch but not this one at this time
217217
preferred = ExportSettings.instance.GetPreferredDCCApp();
218218

219219
Assert.AreEqual(preferred, 0);
@@ -229,6 +229,12 @@ public void TestFindPreferredProgram()
229229
preferred = ExportSettings.instance.GetPreferredDCCApp();
230230

231231
Assert.AreEqual(preferred, 0);
232+
233+
//Testing the preference priority
234+
ExportSettings.instance.SetDCCOptionNames(new List<string> { ExportSettings.kMaxOptionName + "2018", ExportSettings.kMayaOptionName + "2018", ExportSettings.kMayaLtOptionName + "2018" });
235+
preferred = ExportSettings.instance.GetPreferredDCCApp();
236+
237+
Assert.AreEqual(preferred, 1);
232238
}
233239

234240
[Test]

0 commit comments

Comments
 (0)