A bunch of stuff trying to use prefabs and protos instead of relying on
[AntennaRange.git] / Extensions.cs
blob:a/Extensions.cs -> blob:b/Extensions.cs
--- a/Extensions.cs
+++ b/Extensions.cs
@@ -15,9 +15,11 @@
 //
 // This software uses code from the MuMechLib library, © 2013 r4m0n, used under the GNU GPL version 3.
 
+using KSP;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using UnityEngine;
 
 namespace AntennaRange
 {
@@ -51,7 +53,7 @@
 		/// </summary>
 		/// <param name="relay">This <see cref="IAntennaRelay"/></param>
 		/// <param name="Vessel">A <see cref="Vessel"/></param>
-		public static double DistanceTo(this AntennaRelay relay, Vessel Vessel)
+		public static double DistanceTo(this IAntennaRelay relay, Vessel Vessel)
 		{
 			return relay.vessel.DistanceTo(Vessel);
 		}
@@ -61,7 +63,7 @@
 		/// </summary>
 		/// <param name="relay">This <see cref="IAntennaRelay"/></param>
 		/// <param name="body">A <see cref="CelestialBody"/></param>
-		public static double DistanceTo(this AntennaRelay relay, CelestialBody body)
+		public static double DistanceTo(this IAntennaRelay relay, CelestialBody body)
 		{
 			return relay.vessel.DistanceTo(body);
 		}
@@ -71,7 +73,7 @@
 		/// </summary>
 		/// <param name="relayOne">This <see cref="IAntennaRelay"/></param>
 		/// <param name="relayTwo">Another <see cref="IAntennaRelay"/></param>
-		public static double DistanceTo(this AntennaRelay relayOne, IAntennaRelay relayTwo)
+		public static double DistanceTo(this IAntennaRelay relayOne, IAntennaRelay relayTwo)
 		{
 			return relayOne.DistanceTo(relayTwo.vessel);
 		}
@@ -117,12 +119,15 @@
 				// Loop through the ProtoPartModuleSnapshots in this Vessel
 				foreach (ProtoPartSnapshot pps in vessel.protoVessel.protoPartSnapshots)
 				{
-					Transmitters.AddRange(
-						PartLoader.getPartInfoByName(pps.partName)
-						.partPrefab
-						.Modules
-						.OfType<IAntennaRelay>()
-					);
+					foreach (PartModule prefabModule in PartLoader.getPartInfoByName(pps.partName).partPrefab.Modules)
+					{
+						if (prefabModule is ModuleLimitedDataTransmitter)
+						{
+							pps.Load(vessel, false);
+
+							Transmitters.Add(pps.partRef.Modules.OfType<ModuleLimitedDataTransmitter>().First());
+						}
+					}
 				}
 			}