private static void ParseDamageTypeDefinition(string gameConstantsFilePath) { Debug.Assert(gameConstantsFilePath != null, nameof(gameConstantsFilePath) + " != null"); Debug.Assert(File.Exists(gameConstantsFilePath), nameof(gameConstantsFilePath) + " must exist"); XDocument gameConstantsFile = XDocument.Load(gameConstantsFilePath); Debug.Assert(gameConstantsFile.Root != null, "gameConstantsFile.Root != null"); foreach (XElement xElement in gameConstantsFile.Root.Elements()) { if (!xElement.Name.ToString().Equals(Tags.DAMAGE_TYPES, StringComparison.InvariantCultureIgnoreCase)) { continue; } List <Damage> damages = DamageUtility.ParseFromString(xElement.Value); foreach (Damage damage in damages) { if (GlobalStore.DAMAGE_REGISTRY.Contains(damage)) { Debug.Assert(damage != null, nameof(commons.damage) + " != null"); Log.Warning( $"Found duplicated damage type definition \"{damage.Name}\" was previously defined."); continue; } GlobalStore.DAMAGE_REGISTRY.Add(damage); } break; } }
public void ParseFromString_Test() { List <Damage> l = DamageUtility.ParseFromString(DAMAGE_STRING); Assert.IsNotNull(l); Assert.IsTrue(l.Any()); Assert.AreEqual(99, l.Count); }
public void ParseFromString_TestNullEmptyOrWhitespace() { List <Damage> l0 = DamageUtility.ParseFromString(null); Assert.IsNotNull(l0); Assert.IsFalse(l0.Any()); List <Damage> l1 = DamageUtility.ParseFromString(string.Empty); Assert.IsNotNull(l1); Assert.IsFalse(l1.Any()); List <Damage> l2 = DamageUtility.ParseFromString("\n \t\r\n"); Assert.IsNotNull(l2); Assert.IsFalse(l2.Any()); }