private ListValue GetModulesInGroup(StringValue groupName)
{
var matchGroup = KSPActionGroup.None;
string upperName = groupName.ToUpper();
// TODO: later refactor: put this in a Dictionary lookup instead, and then share it
// by both this code and the code in ActionGroup.cs:
if (upperName == "SAS") { matchGroup = KSPActionGroup.SAS; }
if (upperName == "GEAR") { matchGroup = KSPActionGroup.Gear; }
if (upperName == "LIGHTS") { matchGroup = KSPActionGroup.Light; }
if (upperName == "BRAKES") { matchGroup = KSPActionGroup.Brakes; }
if (upperName == "RCS") { matchGroup = KSPActionGroup.RCS; }
if (upperName == "ABORT") { matchGroup = KSPActionGroup.Abort; }
if (upperName == "AG1") { matchGroup = KSPActionGroup.Custom01; }
if (upperName == "AG2") { matchGroup = KSPActionGroup.Custom02; }
if (upperName == "AG3") { matchGroup = KSPActionGroup.Custom03; }
if (upperName == "AG4") { matchGroup = KSPActionGroup.Custom04; }
if (upperName == "AG5") { matchGroup = KSPActionGroup.Custom05; }
if (upperName == "AG6") { matchGroup = KSPActionGroup.Custom06; }
if (upperName == "AG7") { matchGroup = KSPActionGroup.Custom07; }
if (upperName == "AG8") { matchGroup = KSPActionGroup.Custom08; }
if (upperName == "AG9") { matchGroup = KSPActionGroup.Custom09; }
if (upperName == "AG10") { matchGroup = KSPActionGroup.Custom10; }
ListValue kScriptParts = new ListValue();
// This is almost identical to the logic in GetPartsInGroup and it might be a nice idea
// later to merge them somehow:
//
if (matchGroup == KSPActionGroup.None) return kScriptParts;
foreach (global::Part p in Vessel.parts)
foreach (PartModule pm in p.Modules)
{
if (pm.Actions.Any(a => a.actionGroup.Equals(matchGroup)))
{
kScriptParts.Add(PartModuleFieldsFactory.Construct(pm, Shared));
}
}
return kScriptParts;
}