void Start () { ItemConversion.converter = new GameObjectItemDataConverter(); ItemDataList droppedItems = new ItemDataList(); for (int i = 0; i < 3; i++) { SocialPlay.Data.ItemData newItem = new SocialPlay.Data.ItemData(); newItem.Amount = 0; newItem.AssetBundleName = "h"; newItem.BaseItemEnergy = 0; newItem.BaseItemID = 0; newItem.Behaviours = "k"; newItem.Description = ""; newItem.Detail = ""; newItem.Energy = 0; newItem.Image = ""; newItem.ItemID = 0; newItem.Location = 0; newItem.Name = ""; newItem.Quality = 0; newItem.SellPrice = 0; newItem.StackLocationID = Guid.Empty; newItem.Tags = ""; newItem.Type = 0; droppedItems.Add(newItem); } List<ItemData> items = ItemConversion.converter.ConvertItems(droppedItems); itemGetter.OnReceivedGeneratedItems(items); }
void Start() { ItemConversion.converter = new GameObjectItemDataConverter(); ItemDataList droppedItems = new ItemDataList(); for (int i = 0; i < 3; i++) { SocialPlay.Data.ItemData newItem = new SocialPlay.Data.ItemData(); newItem.Amount = 0; newItem.AssetBundleName = "h"; newItem.BaseItemEnergy = 0; newItem.BaseItemID = 0; newItem.Behaviours = "k"; newItem.Description = ""; newItem.Detail = ""; newItem.Energy = 0; newItem.Image = ""; newItem.ItemID = 0; newItem.Location = 0; newItem.Name = ""; newItem.Quality = 0; newItem.SellPrice = 0; newItem.StackLocationID = Guid.Empty; newItem.Tags = ""; newItem.Type = 0; droppedItems.Add(newItem); } List <ItemData> items = ItemConversion.converter.ConvertItems(droppedItems); itemGetter.OnReceivedGeneratedItems(items); }
public override Dictionary <string, string> ConvertItemDetail(SocialPlay.Data.ItemData item) { Dictionary <string, string> statPair = new Dictionary <string, string>(); if (string.IsNullOrEmpty(item.Detail)) { return(statPair); } JArray statsArray = JArray.Parse(item.Detail); return(ItemStatsConverter.Converter.Generate(statsArray)); }
protected List <String> ConvertTags(SocialPlay.Data.ItemData item) { List <string> tags = new List <string>(); if (String.IsNullOrEmpty(item.Tags) || item.Tags == "\"[]\"") { return(tags); } JArray tagsArray = JArray.Parse(item.Tags); foreach (JToken tag in tagsArray) { tags.Add(tag.ToString()); } return(tags); }
public GeneratedItems ConvertToGeneratedItems(string dataString) { string parsedString = ParseString(dataString); JsonData dataArray = LitJson.JsonMapper.ToObject(parsedString); GeneratedItems generatedItems = new GeneratedItems(); if (!int.TryParse(dataArray["GenerationId"].ToString(), out generatedItems.GenerationID)) { Debug.LogError("GenerationID was not valid"); generatedItems.GenerationID = 0; } ItemDataList itemDataList = new SocialPlay.Data.ItemDataList(); JsonData itemsData = dataArray["Items"]; for (int i = 0; i < itemsData.Count; i++) { SocialPlay.Data.ItemData newItemData = new SocialPlay.Data.ItemData(); newItemData.Amount = int.Parse(itemsData[i]["Amount"].ToString()); newItemData.ItemID = int.Parse(itemsData[i]["ItemID"].ToString()); newItemData.Detail = itemsData[i]["Detail"].ToString(); newItemData.Name = itemsData[i]["Name"].ToString(); newItemData.BaseItemEnergy = int.Parse(itemsData[i]["BaseItemEnergy"].ToString()); newItemData.Energy = int.Parse(itemsData[i]["Energy"].ToString()); newItemData.Type = int.Parse(itemsData[i]["Type"].ToString()); newItemData.Image = itemsData[i]["Image"].ToString(); newItemData.Quality = int.Parse(itemsData[i]["Quality"].ToString()); newItemData.BaseItemID = int.Parse(itemsData[i]["BaseItemID"].ToString()); newItemData.Description = itemsData[i]["Description"].ToString(); newItemData.Behaviours = itemsData[i]["Behaviours"].ToString(); newItemData.AssetBundleName = itemsData[i]["AssetBundleName"].ToString(); //newItemData.Tags = itemsData[i]["tags"].ToString(); itemDataList.Add(newItemData); } List <ItemData> items = CloudGoods.itemDataConverter.ConvertItems(itemDataList, generatedItems.GenerationID); generatedItems.generatedItems = items; return(generatedItems); }
public override List <ItemData> ConvertItems(ItemDataList generatedItems, int GenerationID) { List <ItemData> convertedItems = new List <ItemData>(); for (int i = 0, imax = generatedItems.Count; i < imax; i++) { SocialPlay.Data.ItemData item = generatedItems[i]; //GameObject go = new GameObject(); ItemData itemData = new ItemData(); //go.AddComponent<ItemData>(); //go.name = item.Name; itemData.baseEnergy = item.BaseItemEnergy; //TODO fix behaviour conversion //itemData.behaviours = item.Behaviours; itemData.description = item.Description; itemData.itemName = item.Name; itemData.imageName = item.Image; itemData.classID = item.Type; itemData.quality = item.Quality; itemData.salePrice = item.SellPrice; itemData.ItemID = item.ItemID; itemData.CollectionID = int.Parse(item.BaseItemID.ToString()); itemData.stackSize = item.Amount; itemData.totalEnergy = item.Energy; itemData.stackID = item.StackLocationID; itemData.stats = ConvertItemDetail(item); itemData.assetURL = item.AssetBundleName; itemData.tags = ConvertTags(item); itemData.persistantLocation = item.Location; itemData.GenerationID = GenerationID; itemData.IsGenerated = true; convertedItems.Add(itemData); } Resources.UnloadUnusedAssets(); ItemComponentInitalizer.InitializeItemWithComponents(convertedItems, AddComponetTo.prefab); return(convertedItems); }
public abstract Dictionary <string, string> ConvertItemDetail(SocialPlay.Data.ItemData detail);
public List<ItemData> ConvertToItemDataList(string ObjectData) { ItemDataList itemDataList = new SocialPlay.Data.ItemDataList(); string parsedString = ParseString(ObjectData); if (parsedString == "[]") return new List<ItemData>(); JsonReader reader = new JsonReader(parsedString); Debug.Log(parsedString); reader.Read(); if (reader.Token.ToString() == "ArrayStart") { while (reader.Token.ToString() != "ArrayEnd") { reader.Read(); if (reader.Token.ToString() == "ObjectStart") { SocialPlay.Data.ItemData itemData = new SocialPlay.Data.ItemData(); while (reader.Token.ToString() != "ObjectEnd") { reader.Read(); if (reader.Token.ToString() == "PropertyName") { Debug.Log(reader.Value.ToString()); string propertyString = reader.Value.ToString(); reader.Read(); if (propertyString == "StackLocationID") { itemData.StackLocationID = new Guid(reader.Value.ToString()); Debug.Log(itemData.StackLocationID.ToString()); } if (propertyString == "Amount") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Amount = tmpInt; } if (propertyString == "Detail") { itemData.Detail = reader.Value.ToString(); } if (propertyString == "ItemID") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.ItemID = tmpInt; } if (propertyString == "Type") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Type = tmpInt; } if (propertyString == "Location") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Location = tmpInt; } if (propertyString == "BaseItemEnergy") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.BaseItemEnergy = tmpInt; } if (propertyString == "Energy") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Energy = tmpInt; } if (propertyString == "SellPrice") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.SellPrice = tmpInt; } if (propertyString == "Name") { itemData.Name = reader.Value.ToString(); } if (propertyString == "Image") { itemData.Image = reader.Value.ToString(); } if (propertyString == "Quality") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Quality = tmpInt; } if (propertyString == "Behaviours") { itemData.Behaviours = reader.Value.ToString(); } if (propertyString == "BaseItemID") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.BaseItemID = tmpInt; } if (propertyString == "Description") { itemData.Description = reader.Value.ToString(); } if (propertyString == "AssetBundleName") { itemData.AssetBundleName = reader.Value.ToString(); } if (propertyString == "Tags") { itemData.Tags = reader.Value.ToString(); } } } itemDataList.Add(itemData); } } } List<ItemData> items = ItemConversion.converter.ConvertItems(itemDataList); return items; }
public List <ItemData> ConvertToItemDataList(string ObjectData) { ItemDataList itemDataList = new SocialPlay.Data.ItemDataList(); string parsedString = ParseString(ObjectData); if (parsedString == "[]") { return(new List <ItemData>()); } JsonReader reader = new JsonReader(parsedString); Debug.Log(parsedString); reader.Read(); if (reader.Token.ToString() == "ArrayStart") { while (reader.Token.ToString() != "ArrayEnd") { reader.Read(); if (reader.Token.ToString() == "ObjectStart") { SocialPlay.Data.ItemData itemData = new SocialPlay.Data.ItemData(); while (reader.Token.ToString() != "ObjectEnd") { reader.Read(); if (reader.Token.ToString() == "PropertyName") { Debug.Log(reader.Value.ToString()); string propertyString = reader.Value.ToString(); reader.Read(); if (propertyString == "StackLocationID") { itemData.StackLocationID = new Guid(reader.Value.ToString()); Debug.Log(itemData.StackLocationID.ToString()); } if (propertyString == "Amount") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Amount = tmpInt; } if (propertyString == "Detail") { itemData.Detail = reader.Value.ToString(); } if (propertyString == "ItemID") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.ItemID = tmpInt; } if (propertyString == "Type") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Type = tmpInt; } if (propertyString == "Location") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Location = tmpInt; } if (propertyString == "BaseItemEnergy") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.BaseItemEnergy = tmpInt; } if (propertyString == "Energy") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Energy = tmpInt; } if (propertyString == "SellPrice") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.SellPrice = tmpInt; } if (propertyString == "Name") { itemData.Name = reader.Value.ToString(); } if (propertyString == "Image") { itemData.Image = reader.Value.ToString(); } if (propertyString == "Quality") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Quality = tmpInt; } if (propertyString == "Behaviours") { itemData.Behaviours = reader.Value.ToString(); } if (propertyString == "BaseItemID") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.BaseItemID = tmpInt; } if (propertyString == "Description") { itemData.Description = reader.Value.ToString(); } if (propertyString == "AssetBundleName") { itemData.AssetBundleName = reader.Value.ToString(); } if (propertyString == "Tags") { itemData.Tags = reader.Value.ToString(); } } } itemDataList.Add(itemData); } } } List <ItemData> items = ItemConversion.converter.ConvertItems(itemDataList); return(items); }
private static void CreateItemData(ItemDataList itemDataList, JsonReader reader) { if (reader.Token.ToString() == "ObjectStart") { SocialPlay.Data.ItemData itemData = new SocialPlay.Data.ItemData(); while (reader.Token.ToString() != "ObjectEnd") { reader.Read(); if (reader.Token.ToString() == "PropertyName") { string propertyString = reader.Value.ToString(); reader.Read(); if (propertyString == "StackLocationID") { itemData.StackLocationID = new Guid(reader.Value.ToString()); } if (propertyString == "Amount") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Amount = tmpInt; } if (propertyString == "Detail") { itemData.Detail = reader.Value.ToString(); } if (propertyString == "ItemID") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.ItemID = tmpInt; } if (propertyString == "Type") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Type = tmpInt; } if (propertyString == "Location") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Location = tmpInt; } if (propertyString == "BaseItemEnergy") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.BaseItemEnergy = tmpInt; } if (propertyString == "Energy") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Energy = tmpInt; } if (propertyString == "SellPrice") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.SellPrice = tmpInt; } if (propertyString == "Name") { itemData.Name = reader.Value.ToString(); } if (propertyString == "Image") { itemData.Image = reader.Value.ToString(); } if (propertyString == "Quality") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.Quality = tmpInt; } if (propertyString == "Behaviours") { if (reader.Value != null) { itemData.Behaviours = reader.Value.ToString(); } } if (propertyString == "BaseItemID") { int tmpInt = 0; int.TryParse(reader.Value.ToString(), out tmpInt); itemData.BaseItemID = tmpInt; } if (propertyString == "Description") { itemData.Description = reader.Value.ToString(); } if (propertyString == "AssetBundleName") { itemData.AssetBundleName = reader.Value.ToString(); } if (propertyString == "Tags") { if (reader.Value != null) { itemData.Tags = reader.Value.ToString(); } } } } itemDataList.Add(itemData); } }