// return true if a proto module with the specified name and satisfing the predicate specified exist in a vessel // note: disabled modules are not returned public static bool HasModule(ProtoVessel v, string module_name, Predicate<ProtoPartModuleSnapshot> filter) { for (int i = 0; i < v.protoPartSnapshots.Count; ++i) { ProtoPartSnapshot p = v.protoPartSnapshots[i]; for (int j = 0; j < p.modules.Count; ++j) { ProtoPartModuleSnapshot m = p.modules[j]; if (m.moduleName == module_name && Proto.GetBool(m, "isEnabled") && filter(m)) { return true; } } } return false; }
// return all protomodules with a specified name in a vessel // note: disabled modules are not returned public static List<ProtoPartModuleSnapshot> FindModules(ProtoVessel v, string module_name) { List<ProtoPartModuleSnapshot> ret = new List<ProtoPartModuleSnapshot>(8); for (int i = 0; i < v.protoPartSnapshots.Count; ++i) { ProtoPartSnapshot p = v.protoPartSnapshots[i]; for (int j = 0; j < p.modules.Count; ++j) { ProtoPartModuleSnapshot m = p.modules[j]; if (m.moduleName == module_name && Proto.GetBool(m, "isEnabled")) { ret.Add(m); } } } return ret; }