public object Clone() { PropertyDefValuePair ret = new PropertyDefValuePair() { Def = Def.Clone() as PropertyDef, Value = Value.Clone() as string }; return(ret); }
public object Clone() { var propertyDefValuePair = new PropertyDefValuePair() { Def = Def.Clone() as PropertyDef, Value = Value.Clone() as string }; return(propertyDefValuePair); }
private void PopulateEmptyCardProperty(Dictionary <string, PropertyDefValuePair> cardProperties, PropertyDef property, string key) { cardProperties[key] = new PropertyDefValuePair() { Def = property, Value = string.Empty }; foreach (PropertyDef childProperty in property.Properties) { PopulateEmptyCardProperty(cardProperties, childProperty, key + PropertyDef.ObjectDelimiter + childProperty.Name); } }
public void LoadCardFromJToken(JToken cardJToken, string defaultSetCode) { if (cardJToken == null) { UnityEngine.Debug.LogWarning("LoadCardFromJToken::NullCardJToken"); return; } string cardId = cardJToken.Value <string>(CardIdIdentifier) ?? string.Empty; if (string.IsNullOrEmpty(cardId)) { UnityEngine.Debug.LogWarning("LoadCardFromJToken::InvalidCardId:" + cardJToken.ToString()); return; } string cardName = cardJToken.Value <string>(CardNameIdentifier) ?? string.Empty; Dictionary <string, PropertyDefValuePair> cardProperties = new Dictionary <string, PropertyDefValuePair>(); foreach (PropertyDef property in CardProperties) { PropertyDefValuePair newPropertyEntry = new PropertyDefValuePair() { Def = property }; try { string listValue = string.Empty; JObject jObject = null; switch (property.Type) { case PropertyType.ObjectEnumList: listValue = string.Empty; foreach (JToken jToken in cardJToken[property.Name]) { if (!string.IsNullOrEmpty(listValue)) { listValue += EnumDef.Delimiter; } jObject = jToken as JObject; listValue += jObject?.Value <string>("id") ?? string.Empty; } newPropertyEntry.Value = listValue; break; case PropertyType.ObjectList: listValue = string.Empty; foreach (JToken jToken in cardJToken[property.Name]) { if (!string.IsNullOrEmpty(listValue)) { listValue += EnumDef.Delimiter; } jObject = jToken as JObject; listValue += jObject?.ToString() ?? string.Empty; } newPropertyEntry.Value = listValue; break; case PropertyType.ObjectEnum: jObject = cardJToken[property.Name] as JObject; newPropertyEntry.Value = jObject.Value <string>("id") ?? string.Empty; break; case PropertyType.Object: jObject = cardJToken[property.Name] as JObject; newPropertyEntry.Value = jObject?.ToString() ?? string.Empty; break; case PropertyType.StringEnumList: case PropertyType.StringList: listValue = string.Empty; foreach (JToken jToken in cardJToken[property.Name]) { if (!string.IsNullOrEmpty(listValue)) { listValue += EnumDef.Delimiter; } listValue += jToken.Value <string>() ?? string.Empty; } newPropertyEntry.Value = listValue; break; case PropertyType.EscapedString: newPropertyEntry.Value = (cardJToken.Value <string>(property.Name) ?? string.Empty).Replace("\\", ""); break; case PropertyType.StringEnum: case PropertyType.Number: case PropertyType.Integer: case PropertyType.Boolean: case PropertyType.String: default: newPropertyEntry.Value = cardJToken.Value <string>(property.Name) ?? string.Empty; break; } } catch { newPropertyEntry.Value = string.Empty; } cardProperties[property.Name] = newPropertyEntry; } HashSet <string> setCodes = new HashSet <string>(); if (SetsInCardObject) { JToken setContainer = cardJToken[CardSetIdentifier]; List <JToken> setJTokens = (setContainer as JArray)?.ToList() ?? new List <JToken>(); if (setJTokens.Count == 0) { setJTokens.Add(setContainer); } foreach (JToken jToken in setJTokens) { JObject setObject = jToken as JObject; string setCode = setObject?.Value <string>(SetCodeIdentifier); if (setCode == null) { UnityEngine.Debug.LogWarning("LoadCardFromJToken::InvalidSetObject:" + setContainer.ToString()); } else { setCodes.Add(setCode); } } } else { setCodes.Add(cardJToken.Value <string>(CardSetIdentifier) ?? defaultSetCode); } foreach (string cardSet in setCodes) { bool isReprint = CardNames.Contains(cardName); if (!isReprint) { CardNames.Add(cardName); } Card newCard = new Card(this, setCodes.Count > 1 ? (cardId + "_" + cardSet) : cardId, cardName, cardSet, cardProperties, isReprint); LoadedCards[newCard.Id] = newCard; if (!Sets.ContainsKey(cardSet)) { LoadedSets[cardSet] = new Set(cardSet); } } }
public void PopulateCardProperty(Dictionary <string, PropertyDefValuePair> cardProperties, JToken cardJToken, PropertyDef property, string key) { if (cardProperties == null || cardJToken == null || property == null) { UnityEngine.Debug.LogError($"PopulateCardProperty::MissingInput:{cardProperties}:{cardJToken}:{property}"); return; } try { PropertyDefValuePair newProperty = new PropertyDefValuePair() { Def = property }; string listValue = string.Empty; JObject jObject = null; switch (property.Type) { case PropertyType.ObjectEnumList: listValue = string.Empty; foreach (JToken jToken in cardJToken[property.Name]) { if (!string.IsNullOrEmpty(listValue)) { listValue += EnumDef.Delimiter; } jObject = jToken as JObject; listValue += jObject?.Value <string>(CardPropertyIdentifier) ?? string.Empty; } newProperty.Value = listValue; cardProperties[key] = newProperty; break; case PropertyType.ObjectList: foreach (PropertyDef childProperty in property.Properties) { newProperty = new PropertyDefValuePair() { Def = childProperty }; listValue = string.Empty; Dictionary <string, PropertyDefValuePair> values = new Dictionary <string, PropertyDefValuePair>(); int i = 0; foreach (JToken jToken in cardJToken[property.Name]) { PopulateCardProperty(values, jToken, childProperty, key + childProperty.Name + i); i++; } foreach (var entry in values) { if (!string.IsNullOrEmpty(listValue)) { listValue += EnumDef.Delimiter; } listValue += entry.Value.Value.Replace(EnumDef.Delimiter, ", "); } newProperty.Value = listValue; cardProperties[key + PropertyDef.ObjectDelimiter + childProperty.Name] = newProperty; } break; case PropertyType.ObjectEnum: jObject = cardJToken[property.Name] as JObject; newProperty.Value = jObject.Value <string>(CardPropertyIdentifier) ?? string.Empty; cardProperties[key] = newProperty; break; case PropertyType.Object: jObject = cardJToken[property.Name] as JObject; if (jObject != null && jObject.HasValues) { PopulateCardProperties(cardProperties, cardJToken[property.Name], property.Properties, key + PropertyDef.ObjectDelimiter); } else { PopulateEmptyCardProperty(cardProperties, property, key); } break; case PropertyType.StringEnumList: case PropertyType.StringList: listValue = string.Empty; if (string.IsNullOrEmpty(property.Delimiter)) { foreach (JToken jToken in cardJToken[property.Name]) { if (!string.IsNullOrEmpty(listValue)) { listValue += EnumDef.Delimiter; } listValue += jToken.Value <string>() ?? string.Empty; } } else { foreach (string token in (cardJToken.Value <string>(property.Name) ?? string.Empty).Split(new[] { property.Delimiter }, StringSplitOptions.RemoveEmptyEntries)) { if (!string.IsNullOrEmpty(listValue)) { listValue += EnumDef.Delimiter; } listValue += token; } } newProperty.Value = listValue; cardProperties[key] = newProperty; break; case PropertyType.EscapedString: newProperty.Value = (cardJToken.Value <string>(property.Name) ?? string.Empty) .Replace(PropertyDef.EscapeCharacter, string.Empty); cardProperties[key] = newProperty; break; case PropertyType.StringEnum: case PropertyType.Boolean: case PropertyType.Integer: case PropertyType.String: default: newProperty.Value = cardJToken.Value <string>(property.Name) ?? string.Empty; cardProperties[key] = newProperty; break; } } catch { PopulateEmptyCardProperty(cardProperties, property, key); } }