public int GetPropertyValueInt(string propertyName) { if (string.IsNullOrEmpty(propertyName) || !Properties.TryGetValue(propertyName, out PropertyDefValuePair property)) { return(0); } int intValue; if (!EnumDef.TryParseInt(property.Value, out intValue)) { return(0); } return(intValue); }
public int GetPropertyValueEnum(string propertyName) { if (string.IsNullOrEmpty(propertyName) || !Properties.TryGetValue(propertyName, out PropertyDefValuePair property)) { return(0); } EnumDef enumDef = SourceGame.Enums.FirstOrDefault(def => def.Property.Equals(propertyName)); if (enumDef == null) { return(0); } return(enumDef.GetEnumFromPropertyValue(property.Value)); }
public string GetPropertyValueString(string propertyName) { if (string.IsNullOrEmpty(propertyName) || !Properties.TryGetValue(propertyName, out PropertyDefValuePair property)) { return(string.Empty); } EnumDef enumDef = SourceGame.Enums.FirstOrDefault(def => def.Property.Equals(propertyName)); if (enumDef == null || string.IsNullOrEmpty(property.Value)) { return(!string.IsNullOrEmpty(property.Value) ? property.Value : property.Def.DisplayEmpty ?? string.Empty); } return(enumDef.GetStringFromPropertyValue(property.Value)); }
public IEnumerable <Card> FilterCards(CardSearchFilters filters) { if (filters == null) { UnityEngine.Debug.LogWarning("FilterCards::NullFilters"); yield break; } foreach (Card card in Cards.Values) { if (!string.IsNullOrEmpty(filters.Name) && !filters.Name.ToLower().Split(' ').All(card.Name.ToLower().Contains)) { continue; } if (!string.IsNullOrEmpty(filters.Id) && !card.Id.ToLower().Contains(filters.Id.ToLower())) { continue; } if (!string.IsNullOrEmpty(filters.SetCode) && !card.SetCode.ToLower().Contains(filters.SetCode.ToLower())) { continue; } bool propsMatch = true; foreach (KeyValuePair <string, string> entry in filters.StringProperties) { if (!card.GetPropertyValueString(entry.Key).ToLower().Contains(entry.Value.ToLower())) { propsMatch = false; } } foreach (KeyValuePair <string, int> entry in filters.IntMinProperties) { if (card.GetPropertyValueInt(entry.Key) < entry.Value) { propsMatch = false; } } foreach (KeyValuePair <string, int> entry in filters.IntMaxProperties) { if (card.GetPropertyValueInt(entry.Key) > entry.Value) { propsMatch = false; } } foreach (KeyValuePair <string, int> entry in filters.EnumProperties) { EnumDef enumDef = Enums.FirstOrDefault(def => def.Property.Equals(entry.Key)); if (enumDef == null) { propsMatch = false; continue; } if ((card.GetPropertyValueEnum(entry.Key) & entry.Value) == 0) { propsMatch = propsMatch && (entry.Value == (1 << enumDef.Values.Count)) && CardProperties.FirstOrDefault(prop => prop.Name.Equals(entry.Key)).Empty.Equals(card.GetPropertyValueString(entry.Key)); } } if (propsMatch) { yield return(card); } } }
public string ToString(CardGame forGame) { string filters = string.Empty; if (!string.IsNullOrEmpty(Name)) { filters += "name:\"" + Name + "\"; "; } if (!string.IsNullOrEmpty(Id)) { filters += "id:" + Id + "; "; } if (!string.IsNullOrEmpty(SetCode)) { filters += "set:" + SetCode + "; "; } foreach (PropertyDef property in forGame.CardProperties) { switch (property.Type) { case PropertyType.ObjectEnum: case PropertyType.ObjectEnumList: case PropertyType.StringEnum: case PropertyType.StringEnumList: if (!EnumProperties.ContainsKey(property.Name)) { break; } EnumDef enumDef = forGame.Enums.FirstOrDefault(def => def.Property.Equals(property.Name)); if (enumDef != null) { string filterValue = enumDef.GetStringFromLookupFlags(EnumProperties[property.Name]); if (filterValue.Contains(' ')) { filterValue = "\'" + filterValue + "\'"; } filters += property.Name + ":" + filterValue + "; "; } break; case PropertyType.Integer: if (IntMinProperties.ContainsKey(property.Name)) { filters += property.Name + ">=" + IntMinProperties[property.Name] + "; "; } if (IntMaxProperties.ContainsKey(property.Name)) { filters += property.Name + "<=" + IntMaxProperties[property.Name] + "; "; } break; case PropertyType.Object: case PropertyType.ObjectList: case PropertyType.Number: case PropertyType.Boolean: case PropertyType.StringList: case PropertyType.EscapedString: case PropertyType.String: default: if (StringProperties.ContainsKey(property.Name)) { filters += property.Name + ":\"" + StringProperties[property.Name] + "\"; "; } break; } } return(filters); }