Exemplo n.º 1
0
        /// <summary>
        /// If no inventory save file exists we create a new one, and fill it with the base value of having everything false
        /// </summary>
        private void SaveInventoryData(bool createNewFile, bool isClosing = false)
        {
            if (createNewFile)
            {
                for (int i = 0; i < allPrimeSets.Count; i++)
                {
                    InventoryItemEntry[] itemEntry = new InventoryItemEntry[allPrimeSets[i].Count - 1];

                    for (int j = 1; j < allPrimeSets[i].Count; j++)
                    {
                        itemEntry[j - 1] = new InventoryItemEntry(allPrimeSets[i][j].item_name, false);
                    }
                    InventorySetEntry setEntry = new InventorySetEntry(allPrimeSets[i][0].item_name, false, itemEntry);
                    setsInventory.Add(setEntry);
                }
            }

            DefaultContractResolver contractResolver = new DefaultContractResolver
            {
                NamingStrategy = new CamelCaseNamingStrategy
                {
                    OverrideSpecifiedNames = false
                }
            };

            string jsonNoFormatting = JsonConvert.SerializeObject(setsInventory, new JsonSerializerSettings
            {
                ContractResolver = contractResolver,
                Formatting       = Formatting.Indented
            });

            //Write the inventory to a JSON file
            using (StreamWriter sw = new StreamWriter(JSONpath + inventorySaveFile))
            {
                sw.Write(jsonNoFormatting);
            }
            if (!File.Exists(JSONpath + inventorySaveFile))
            {
                Console.WriteLine("Error creating file. File not found");
            }

            if (!isClosing)
            {
                FillInventoryPanel();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load in the inventory save file
        /// </summary>
        private void LoadInventoryData()
        {
            string rawJson = "";

            using (StreamReader reader = new StreamReader(JSONpath + inventorySaveFile))
            {
                rawJson = reader.ReadToEnd();
            }
            JArray        jsonResult      = JArray.Parse(rawJson);
            List <JToken> filteredResults = jsonResult.ToList();

            foreach (JToken token in filteredResults)
            {
                InventorySetEntry item = token.ToObject <InventorySetEntry>();
                setsInventory.Add(item);
            }

            FillInventoryPanel();
        }