public void TestConstructorNullVessel() { Assert.Catch <ArgumentNullException> (() => { var foo = new AsteroidInfo((ConfigNode)null, "something"); }); Assert.Catch <ArgumentNullException> (() => { var foo = new AsteroidInfo((ProtoVessel)null, "something"); }); Assert.Catch <ArgumentNullException> (() => { var foo = new AsteroidInfo((Vessel)null, "something"); }); }
public void TestLoadSave() { var testbed = TestUtils.makeAsteroidInfo(); // NUnit doesn't seem to have a "requires" Assert.AreNotEqual(default(uint), testbed.id); Assert.AreNotEqual(null, testbed.parentSet); ConfigNode saved = testbed.ToConfigNode(); AsteroidInfo copy = AsteroidInfo.FromConfigNode(saved); Assert.AreEqual(testbed.id, copy.id); Assert.AreEqual(testbed.parentSet, copy.parentSet); }
/// <summary> /// Counts the number of asteroids from a specific set. /// </summary> /// <param name="group">The AsteroidSet of interest.</param> /// <returns>The number of asteroids known to have been spawned from <c>group</c>.</returns> internal static int countAsteroidsInSet(AsteroidSet group) { int count = 0; string id = group.getName(); foreach (Vessel v in FlightGlobals.Vessels) { if (v.vesselType == VesselType.SpaceObject) { AsteroidInfo info = CustomAsteroidRegistry.Instance.LookupAsteroid(v); if (info != null && info.parentSet == id) { count++; } } } return(count); }
/// <summary> /// Called when the module is either constructed or loaded as part of a save game. After /// this method returns, the module will be initialized with any settings in <c>node</c>. /// </summary> /// <param name="node">The ConfigNode representing this ScenarioModule.</param> public override void OnLoad(ConfigNode node) { base.OnLoad(node); var buffer = new Dictionary <uint, AsteroidInfo> (); ConfigNode [] entries = node.GetNodes("asteroid"); foreach (ConfigNode asteroidNode in entries) { string encodedId = asteroidNode.GetValue("id"); uint id; if (uint.TryParse(encodedId, out id)) { buffer.Add(id, AsteroidInfo.FromConfigNode(asteroidNode)); } else { Debug.LogError($"[CustomAsteroidRegistry]: invalid asteroid ID {encodedId}, not loading"); } } asteroids = buffer; }
/// <summary> /// Summarize key information for an asteroid. /// </summary> /// <param name="vessel">The asteroid whose information needs to be stored.</param> /// <param name="info">The information to store.</param> /// <exception cref="System.ArgumentException">Thrown if <paramref name="vessel"/> /// is already registered.</exception> internal void RegisterAsteroid(Vessel vessel, AsteroidInfo info) { asteroids.Add(vessel.persistentId, info); }
public void TestConstructorNullGroup() { var testbed = new AsteroidInfo(TestUtils.makeVesselConfig(42), null); Assert.IsNull(testbed.parentSet); }
public void TestConstructorBadId() { Assert.Catch <ArgumentException> (() => { var foo = new AsteroidInfo(TestUtils.makeCorruptedVesselConfig(), "potatoroids"); }); }
public void TestConstructorNoId() { Assert.Catch <ArgumentException> (() => { var foo = new AsteroidInfo(new ConfigNode(), "potatoroids"); }); }