示例#1
0
    private static string SerializeInventory(List <Item> itemList)
    {
        Dictionary <int, int> inventory = new Dictionary <int, int>();

        foreach (Item item in itemList)
        {
            if (inventory.ContainsKey(item.itemId))
            {
                inventory[item.itemId] += 1;
            }
            else
            {
                inventory.Add(item.itemId, 1);
            }
        }
        InventoryItemData[] items = new InventoryItemData[inventory.Count];
        int i = 0;

        foreach (var item in inventory)
        {
            InventoryItemData gameItem = new InventoryItemData(item.Key, item.Value);
            items[i] = gameItem;
            i++;
        }
        return(JsonArrayParser.ToJson(items, true));
    }
示例#2
0
 protected object ParseJsonArray()
 {
     try
     {
         JsonArrayParser arrParser = new JsonArrayParser(jsonContent.Substring(currentPosition));
         object          result    = arrParser.Parse();
         currentToken = jsonContent[currentPosition += arrParser.currentPosition];
         MatchToken(']');
         return(result);
     }
     catch
     {
         throw;
     }
 }
    internal RowValue <T> Deserialize <T>(string rawJson, JsonSerializerOptions jsonSerializerOptions)
    {
        var result = rawJson.Substring(1, rawJson.Length - 2);

        if (queryStreamHeader.ColumnTypes.Length == 1 && !typeof(T).IsAnonymousType())
        {
            return(new RowValue <T>(JsonSerializer.Deserialize <T>(result, jsonSerializerOptions)));
        }

        var jsonRecord = new JsonArrayParser().CreateJson(queryStreamHeader.ColumnNames, result);

        var record = JsonSerializer.Deserialize <T>(jsonRecord, jsonSerializerOptions);

        return(new RowValue <T>(record));
    }
示例#4
0
 public static void LoadData()
 {
     playerData = SaveSystem.LoadData();
     if (playerData == null)
     {
         playerData = new PlayerData();
         return;
     }
     InventoryItemData[] inventory = JsonArrayParser.FromJson <InventoryItemData>(playerData.GetInventoryString());
     itemList.Clear();
     foreach (InventoryItemData item in inventory)
     {
         for (int i = 0; i < item.count; i++)
         {
             itemList.Add(GameData.GetItemById(item.id));
         }
     }
     instance.StartCoroutine(PopulateUI());
 }
示例#5
0
    private void SetItemsConfig(int count)
    {
        Log.WriteLog("Set backgrounds config.", Log.LevelsOfLogs.INFO, "ShopBackgrounds");
        _itemsConfig = new ItemConfig[count];
        Log.WriteLog(string.Format("Count of current backgrounds: {0}.", _itemsConfig.Length), Log.LevelsOfLogs.INFO, "ShopBackgrounds");
        pathForJson = Application.dataPath + "/Resources/" + resourcesPath + jsonNameFile;
        if (!File.Exists(pathForJson))
        {
            Log.WriteLog("File not exists.", Log.LevelsOfLogs.ERROR, "BuyItemManager");
            return;
        }
        string json = File.ReadAllText(pathForJson);

        if (json.Length == 0)
        {
            Log.WriteLog("Can not set json.", Log.LevelsOfLogs.ERROR, "ShopBackgrounds");
        }
        _itemsConfig = JsonArrayParser.FromJson <ItemConfig>(json);
    }
示例#6
0
        public override void TestInitialize()
        {
            base.TestInitialize();

            ClassUnderTest = new JsonArrayParser();
        }